public interface DataNode
Implementing classes will normally also supply one or more constructors
based on other classes (for instance String
,
File
or other types of DataNode
) -
such constructors should throw a NoSuchDataException
if the construction fails.
When a DataNodeFactory
instance is informed of the
existence of this new DataNode
implementation, it can
try to construct a new object of this type from child nodes generated
by this or other classes. In this way a DataNode
of
a given type does not need to know all about the kinds of child
nodes it can have.
For smooth working of the node building machinery, DataNode implementations should make every effort to observe the following rules about resource usage: As far as possible, internal state of a DataNode should be constructed just-in-time as it is required rather than up front in the constructor. This is because in many cases a large number of nodes will be constructed, most of which will only be called upon to supply their name, icon, description etc; if many allocate large amounts of memory, memory is liable to be exhausted. The only actions which should be permitted to cause a (potentially) large memory allocation are:
getChildIterator()
configureDetail(uk.ac.starlink.datanode.nodes.DetailViewer)
Although you can implement this interface directly and everything
should work fine, it is probably a good idea to inherit from
DefaultDataNode
. The separation of interface and implementation
is as much for clarity of documentation as anything.
Modifier and Type | Method and Description |
---|---|
boolean |
allowsChildren()
Indicates whether the node can in principle have child nodes.
|
void |
configureDetail(DetailViewer dv)
Configures a DetailViewer object to show additional class-specific
details associated with this node.
|
Iterator |
getChildIterator()
Gets an Iterator over the children of the object, each of which
should itself be a
DataNode . |
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)
Returns a data object of a given type which corresponds to this node.
|
String |
getDescription()
Gets a concise description of this object.
|
Icon |
getIcon()
Gets an
Icon which can be used when displaying this node. |
String |
getLabel()
Gets the label of this object.
|
String |
getName()
Gets the name of this object.
|
String |
getNodeTLA()
Returns a short string indicating what kind of node this is.
|
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()
Gets the contribution of this node to a pathname.
|
String |
getPathSeparator()
Gets the delimiter string which separates the name of this node from
the name of one of its children when constructing a pathname.
|
boolean |
hasDataObject(DataType type)
Indicates whether this node can, on request, supply a data object
of a particular type.
|
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 |
setLabel(String label)
Sets a label for this object.
|
void |
setParentObject(Object parentObj)
Sets the object which is in some sense the parent of the one
this node is based on.
|
boolean allowsChildren()
true
if the node is of a type which can have
child nodes, false
otherwisevoid setLabel(String label)
label
- the label to be given to this objectIterator getChildIterator()
DataNode
. Should only be
called if hasChildren
returns true
.
It is preferred that this method completes quickly, so if
constructing the whole list of children may be time-consuming,
implementing classes should avoid constructing the whole list
before returning the iterator.
Implementing classes should in general follow this strategy when
generating children: the class should get the list of children
in whatever way is appropriate for the type of node in question.
It should then make use of its childMaker (the
DataNodeFactory
returned by the
getChildMaker
method)
to turn these into DataNode
objects to return as
the children rather than using a particular constructor, such
as one of its own, to generate them. In this way, children
may turn out to be more specific objects of a type known about
by DataNodeFactory
but not by the implementing class.
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
.Object getParentObject()
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.null
void setParentObject(Object parentObj)
DataNode
,
it is something which may get fed to a DataNodeFactory
to create DataNode
.parentObj
- an object which is the parent of this oneString getLabel()
getName
unless the user of the implementing class
has previously called setLabel
to change it.String getName()
String getNodeTLA()
DataNode
String getNodeType()
DataNode
String getDescription()
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.Icon getIcon()
Icon
which can be used when displaying this node.
This should return an icon suitable for displaying in a JTree,
ideally about 16x16 pixels. It should give some indication of
the type of node.
Implementations are encouraged to construct this icon lazily (i.e. not do it until this method is called), since using Icons usually causes a large number of Swing classes to be loaded, and in some circumstances (such as treeview -text) these may never be used.
Icon
for displayString getPathElement()
name
member variable. Can be null to indicate the no pathname can
be formed from this node.String getPathSeparator()
null
is returned it indicates that no pathname
can be formed from this node and one of its children (for instance
if it has no children).boolean hasDataObject(DataType type)
DataType
s, it can in general forget about any special
presentation specific to that type, on the grounds that generic
node processing will take care of it.
Invoking this method ought not to create such a data object
if that is an expensive process, merely to indicate whether
a subsequent invocation of getDataObject(uk.ac.starlink.datanode.nodes.DataType)
using the same
type
is likely to be successful.
type
- data object type of interestgetDataObject(type)
is likely to be successfulObject getDataObject(DataType type) throws DataObjectException
hasDataObject(uk.ac.starlink.datanode.nodes.DataType)
using the same type
has returned true
(otherwise an IllegalArgumentException
may be thrown).
The returned object must be in instance of the class returned by
type.getDataClass()
.type
- data object type of interesttype
DataObjectException
void configureDetail(DetailViewer dv)
DetailViewer
object
to customise it to contain information about the node in question.
This will
consist of populating the main panel with basic and compact
information about this node, and possibly adding further tabbed
panes giving alternative views of the data attached to the node.
See the documentation for DetailViewer
for more information.
Nodes which don't have much to say about themselves may implement this method as a no-op, though it will generally be a good idea to invoke the superclass's implementation if there is a superclass.
dv
- the detail viewer which this node is given an opportunity
to configurevoid setChildMaker(DataNodeFactory factory)
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.
factory
- the factory to use for generating childrenDataNodeFactory getChildMaker()
void setCreator(CreationState state)
state
- an object encapsulating the means by which this node
was createdCreationState getCreator()
Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.