public class DefaultDataNode extends Object implements DataNode
DataNode
interface.
It may be used directly for simple nodes, or it may be subclassed
for convenience in writing more specific DataNode
implementors.Constructor and Description |
---|
DefaultDataNode()
Constructs a blank
DefaultDataNode . |
DefaultDataNode(String name)
Constructs a
DefaultDataNode with a given name. |
Modifier and Type | Method and Description |
---|---|
boolean |
allowsChildren()
The
DefaultDataNode implementation of this method returns
false . |
static void |
beep()
It beeps.
|
void |
configureDetail(DetailViewer dv)
No custom configuration is performed.
|
Iterator |
getChildIterator()
The
DefaultDataNode implementation of this method throws
UnsupportedOperationException
(allowsChildren() is false). |
DataNodeFactory |
getChildMaker()
Gets the factory which should in general be used to generate
descendant nodes.
|
CreationState |
getCreator()
Retrieves information about how this node was created.
|
Object |
getDataObject(DataType type)
The
DefaultDataNode implementation returns any data object
which has been registered using registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object) . |
String |
getDescription()
Gets a concise description of this object.
|
Icon |
getIcon()
Returns a default icon, unless setIconID has been called, in which
case it returns the one indicated by that call.
|
String |
getLabel()
Gets the label of this object.
|
String |
getName()
Gets the name of this object.
|
String |
getNodeTLA()
The
DefaultDataNode implementation returns the string "...". |
String |
getNodeType()
Returns a short sentence indicating what kind of node this is.
|
Object |
getParentObject()
Returns an object which is in some sense the parent of the one
this node is based on.
|
String |
getPathElement()
The
DefaultDataNode implementation
returns the label as a default path element. |
String |
getPathSeparator()
Returns a default separator string.
|
boolean |
hasDataObject(DataType type)
The
DefaultDataNode implementation returns true for
only those data objects which have been registered using
registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object) . |
DataNode |
makeChild(Object childObj)
Uses the node's childMaker to turn objects into data nodes.
|
DataNode |
makeErrorChild(Throwable th)
Constructs an error data node from a throwable.
|
void |
registerDataObject(DataType type,
Object data)
Provides a straightforward method of storing typed data objects
for this node, as accessed by the
hasDataObject(uk.ac.starlink.datanode.nodes.DataType) /getDataObject(uk.ac.starlink.datanode.nodes.DataType)
methods. |
void |
setChildMaker(DataNodeFactory factory)
Sets the factory which should in general be used to generate
child nodes.
|
void |
setCreator(CreationState state)
Stores information about how this node was created.
|
void |
setDescription(String desc)
Sets the value which will be returned by
getDescription() . |
protected void |
setIconID(short id)
This may be called by subclasses to set the icon returned by
this node to one of the ones defined in the IconFactory class.
|
void |
setLabel(String label)
Sets a label for this object.
|
protected void |
setName(String name)
Sets the name of this node.
|
void |
setParentObject(Object parent)
Sets the object which is in some sense the parent of the one
this node is based on.
|
String |
toString() |
public DefaultDataNode()
DefaultDataNode
.public DefaultDataNode(String name)
DefaultDataNode
with a given name.name
- the name to use for this object.public boolean allowsChildren()
DefaultDataNode
implementation of this method returns
false
.allowsChildren
in interface DataNode
true
if the node is of a type which can have
child nodes, false
otherwisepublic Iterator getChildIterator()
DefaultDataNode
implementation of this method throws
UnsupportedOperationException
(allowsChildren()
is false).getChildIterator
in interface DataNode
Iterator
over the children. Each object
iterated over should be a DataNode
.
Behaviour is undefined if this method is called on an
object for which allowsChildren
returns
false
.public Object getParentObject()
DataNode
DataNode
,
it is something which may get fed to a DataNodeFactory
to create DataNode
. If no such object exists, which
may well be the case, null
should be returned.getParentObject
in interface DataNode
null
public void setParentObject(Object parent)
DataNode
DataNode
,
it is something which may get fed to a DataNodeFactory
to create DataNode
.setParentObject
in interface DataNode
parent
- an object which is the parent of this onepublic void setLabel(String label)
DataNode
public String getLabel()
DataNode
getName
unless the user of the implementing class
has previously called setLabel
to change it.protected void setName(String name)
name
- the node's namepublic String getName()
DataNode
public void setDescription(String desc)
getDescription()
.desc
- the description stringpublic String getDescription()
DataNode
getName
method, since they may be presented together.
It should be on one line, and preferably no longer than around
70 characters. The null
value may be returned if
there is nothing to say.getDescription
in interface DataNode
public String getNodeTLA()
DefaultDataNode
implementation returns the string "...".getNodeTLA
in interface DataNode
public String getNodeType()
DataNode
getNodeType
in interface DataNode
DataNode
protected void setIconID(short id)
id
- one of the icon identifiers defined as static
final members of the IconFactory
classpublic Icon getIcon()
public String getPathSeparator()
getPathSeparator
in interface DataNode
public String getPathElement()
DefaultDataNode
implementation
returns the label as a default path element.getPathElement
in interface DataNode
public void registerDataObject(DataType type, Object data)
hasDataObject(uk.ac.starlink.datanode.nodes.DataType)
/getDataObject(uk.ac.starlink.datanode.nodes.DataType)
methods. You can invoke this method to register a data object
for a particular data type. Note that this is only suitable if
the data object is free or cheap to come by - in the case
that its construction is expensive then the data object ought to
be constructed on demand by getDataObject
rather than being
registered as a matter of course (since it may never be needed).type
- data type of object to registerdata
- data object of type type
for this node -
must be non-null and of class type.getDataClass()
public boolean hasDataObject(DataType type)
DefaultDataNode
implementation returns true for
only those data objects which have been registered using
registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object)
.hasDataObject
in interface DataNode
type
- data object type of interestgetDataObject(type)
is likely to be successfulpublic Object getDataObject(DataType type) throws DataObjectException
DefaultDataNode
implementation returns any data object
which has been registered using registerDataObject(uk.ac.starlink.datanode.nodes.DataType, java.lang.Object)
.getDataObject
in interface DataNode
type
- data object type of interesttype
DataObjectException
public void configureDetail(DetailViewer dv)
configureDetail
in interface DataNode
dv
- the detail viewer which this node is given an opportunity
to configurepublic void setChildMaker(DataNodeFactory factory)
DataNode
This method should only be used by applications which wish to restrict the type of node which can appear in a whole subtree of the node hierarchy. The childMaker is normally inherited from parent to child, so for instance customising the childMaker of the tree root by removing certain builders will prevent such nodes from appearing anywhere in the tree.
setChildMaker
in interface DataNode
factory
- the factory to use for generating childrenpublic DataNodeFactory getChildMaker()
DataNode
getChildMaker
in interface DataNode
public DataNode makeChild(Object childObj)
getChildMaker().makeChildNode(this,childObj)
.
In general, nodes should use this method to construct their
children.childObj
- the object which forms the basis for a child
data nodeDataNodeFactory.makeDataNode(uk.ac.starlink.datanode.nodes.DataNode, java.lang.Object)
public DataNode makeErrorChild(Throwable th)
getChildMaker().makeErrorDataNode(this,th)
th
- the throwable on which the data node will be basedDataNodeFactory.makeErrorDataNode(uk.ac.starlink.datanode.nodes.DataNode, java.lang.Throwable)
public void setCreator(CreationState state)
DataNode
setCreator
in interface DataNode
state
- an object encapsulating the means by which this node
was createdpublic CreationState getCreator()
DataNode
getCreator
in interface DataNode
public static void beep()
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.