Class TreeNode
- All Implemented Interfaces:
TreeTable.Node
- Direct Known Subclasses:
TreeNode.Element
TreeTableView
view. The TreeTableView
class is used directly
only for the root node, or for nodes containing a fixed value instead of a value fetched from
the metadata object. For all other nodes, the actual node class shall be either TreeNode.Element
or TreeNode.CollectionElement
.
The value of a node is extracted from the metadata object by getUserObject()
.
For each instance of TreeTableView
, that value is always a singleton, never a collection.
If a metadata property is a collection, then there is an instance of the TreeNode.CollectionElement
subclass for each element in the collection.
The newChild()
operation is supported if the node is not a leaf. The user shall
set the identifier and the value, in that order, before any other operation on the new child.
See newChild()
javadoc for an example.
TreeNode.Element.indexInData
and TreeNode.CollectionElement.indexInList
fields may not be stable.
The former may be invalid if the node is serialized and deserialized by two different versions of Apache SIS
having properties in different order. The second may be invalid if the collection is not guaranteed to preserve
order on serialization (e.g. CodeListSet
with user supplied elements, in which case the elements order
depends on the instantiation order).- Since:
- 0.3
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
A node for an element in a collection.(package private) static class
A node for a metadata property value.private final class
The proxy to be returned bynewChild()
. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Class<?>
The return type of the getter method that provides the value encapsulated by this node.(package private) Object
The value which existed when theTreeNodeChildren.iterator()
traversed this node.private Collection<TreeTable.Node>
The children of this node, ornull
if not yet computed.private static final Collection<TreeTable.Node>
The collection of children to return when the node does not allow children (i.e.(package private) final Object
The metadata object from which thegetUserObject()
method will fetch the value.private CharSequence
The value ofTableColumn.NAME
, computed bygetName()
then cached.private final TreeNode
The parent of this node to be returned bygetParent()
, ornull
if this node is the root of the tree.(package private) final TreeTableView
The table for which this node is an element. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
appendIdentifier
(StringBuilder buffer) Appends an identifier for this node in the given buffer, fortoString()
implementation.(package private) final void
appendStringTo
(StringBuilder buffer) Implementation oftoString()
appending the string representation in the given buffer.boolean
Returnstrue
if the given object is of the same class than this node and contains a reference to the same metadata object.final Collection<TreeTable.Node>
Returns the children of this node, or an empty set if none.private TreeNodeChildren
Returns the children if the value policy isValueExistencePolicy.COMPACT
, ornull
otherwise.(package private) String
Returns the UML identifier defined by the standard.(package private) Integer
getIndex()
Returns the index in the collection if the metadata property type is a collection, ornull
otherwise.(package private) CharSequence
getName()
Gets the human-readable name of this node.final TreeTable.Node
Returns the parent node, ornull
if this node is the root of the tree.(package private) CharSequence
Gets remarks about the value in this node, ornull
if none.The metadata value for this node, to be returned bygetValue(TableColumn.VALUE)
.final <V> V
getValue
(TableColumn<V> column) Returns the value of this node in the given column, ornull
if none.int
hashCode()
Returns a hash code value for this node.final boolean
isEditable
(TableColumn<?> column) Returnstrue
if the given column isTableColumn.VALUE
and the property is writable, orfalse
in all other cases.final boolean
isLeaf()
Returnsfalse
if the value is a metadata object (and consequently can have children), ortrue
if the value is not a metadata object.(package private) final boolean
isMetadata
(Class<?> type) Returnstrue
if nodes for values of the given type can be expanded with more children.(package private) boolean
Returnstrue
if the metadata value can be set.private CacheKey
key()
Returns the key to use for calls toMetadataStandard
methods.final TreeTable.Node
newChild()
Returns a proxy for a new property to be defined in the metadata object.(package private) void
setUserObject
(Object value) Sets the metadata value for this node.final <V> void
setValue
(TableColumn<V> column, V value) Sets the value if the given column isTableColumn.VALUE
.final String
toString()
Returns a string representation of this node for debugging purpose.private String
unmodifiableCellValue
(TableColumn<?> column) Returns the error message for an unmodifiable cell value in the given column.
-
Field Details
-
LEAF
The collection of children to return when the node does not allow children (i.e. is a leaf). This constant is also used as a sentinel value byisLeaf()
.We choose an empty set instead of an empty list because
TreeNodeChildren
does not implement theList
interface. So we are better to never give to the user a collection implementingList
in order to signal incorrect casts sooner. -
table
The table for which this node is an element. Contains information like the metadata standard and the value existence policy.All
TreeNode
instances in the same tree have a reference to the sameTreeTableView
instance. -
parent
The parent of this node to be returned bygetParent()
, ornull
if this node is the root of the tree.- See Also:
-
metadata
The metadata object from which thegetUserObject()
method will fetch the value. The value is fetched in different ways, which depend on theTreeNode
subclass:- For
TreeNode
(the root of the tree), the value is directlymetadata
. - For
TreeNode.Element
(a metadata property which is not a collection), the value isaccessor.get(indexInData, metadata)
. - For
TreeNode.CollectionElement
(an element in a collection), another index is used for fetching the element in that collection.
- See Also:
- For
-
baseType
The return type of the getter method that provides the value encapsulated by this node. This information is used for filtering aspects when a class opportunistically implements many interfaces. This value is part of theCacheKey
needed for invokingMetadataStandard
methods. -
name
The value ofTableColumn.NAME
, computed bygetName()
then cached.- See Also:
-
children
The children of this node, ornull
if not yet computed. If and only if the node cannot have children (i.e. is a leaf), then this field is set toLEAF
.- See Also:
-
cachedValue
The value which existed when theTreeNodeChildren.iterator()
traversed this node. This value is cached on the assumption that users will ask for value or for children soon after they iterated over this node. The cached value is cleared after its first use.This value shall be either
null
, or the exact same value than what a call togetUserObject()
would return, assuming that the underlying metadata object didn't changed.The purpose of this cache is to avoid invoking (by reflection) the same getter methods twice in common situations like the
TreeTableView.toString()
implementation or in Graphical User Interface. However, we may remove this field in any future SIS version if experience shows that it is more problematic than helpful.
-
-
Constructor Details
-
TreeNode
TreeNode(TreeTableView table, Object metadata, Class<?> baseType) Creates the root node of a new metadata tree table.- Parameters:
table
- the table which is creating this root node.metadata
- the root metadata object (cannot be null).baseType
- the return type of the getter method that provides the value encapsulated by this node.
-
TreeNode
Creates a new child for an element of the given metadata. This constructor is for theTreeNode.Element
subclass only.- Parameters:
parent
- the parent of this node.metadata
- the metadata object for which this node will be a value.baseType
- the return type of the getter method that provides the value encapsulated by this node.
-
-
Method Details
-
isMetadata
Returnstrue
if nodes for values of the given type can be expanded with more children. A return value offalse
means that values of the given type are leaves. -
key
Returns the key to use for calls toMetadataStandard
methods. This key is used only for some default method implementations in the root node; children will use the class of their node value instead. -
getIdentifier
String getIdentifier()Returns the UML identifier defined by the standard. The default implementation is suitable only for the root node, since it returns the class identifier. Subclasses must override in order to return the property identifier instead. -
getIndex
Integer getIndex()Returns the index in the collection if the metadata property type is a collection, ornull
otherwise. The (identifier, index) pair can be used as a primary key for identifying this node among its siblings. -
getName
CharSequence getName()Gets the human-readable name of this node. The name shall be stable, since it will be cached by the caller. The name typically contains identifier and index information, eventually localized.The default implementation is suitable only for the root node - subclasses must override.
-
getRemarks
CharSequence getRemarks()Gets remarks about the value in this node, ornull
if none. -
appendIdentifier
Appends an identifier for this node in the given buffer, fortoString()
implementation. The appended value is similar to the value returned bygetIdentifier()
(except for the root node), but may contains additional information like the index in a collection.The default implementation is suitable only for the root node - subclasses must override.
-
getUserObject
The metadata value for this node, to be returned bygetValue(TableColumn.VALUE)
. The default implementation is suitable only for the root node - subclasses must override.- Specified by:
getUserObject
in interfaceTreeTable.Node
- Returns:
- any object stored at this node by the user, or
null
if none.
-
setUserObject
Sets the metadata value for this node. Subclasses must override this method.- Throws:
UnsupportedOperationException
- if the metadata value is not writable.
-
isWritable
boolean isWritable()Returnstrue
if the metadata value can be set. Subclasses must override this method. -
equals
Returnstrue
if the given object is of the same class than this node and contains a reference to the same metadata object. SinceTreeNode
generates all content from the wrapped metadata, this condition should ensure that two equal nodes have the same values and children.- Specified by:
equals
in interfaceTreeTable.Node
- Overrides:
equals
in classObject
- Parameters:
other
- the other object to compare with this node.- Returns:
- whether the two objects are nodes with equal values and equal children, ignoring parents.
-
hashCode
public int hashCode()Returns a hash code value for this node.- Specified by:
hashCode
in interfaceTreeTable.Node
- Overrides:
hashCode
in classObject
- Returns:
- a hash code for this node, potentially based on values and children but ignoring parent.
-
getParent
Returns the parent node, ornull
if this node is the root of the tree.- Specified by:
getParent
in interfaceTreeTable.Node
- Returns:
- the parent, or
null
if none.
-
isLeaf
public final boolean isLeaf()Returnsfalse
if the value is a metadata object (and consequently can have children), ortrue
if the value is not a metadata object.- Specified by:
isLeaf
in interfaceTreeTable.Node
- Returns:
true
if this node cannot have any children.
-
getChildren
Returns the children of this node, or an empty set if none. Only metadata object can have children.- Specified by:
getChildren
in interfaceTreeTable.Node
- Returns:
- the children, or an empty collection if none.
-
newChild
Returns a proxy for a new property to be defined in the metadata object. The user shall set the identifier and the value, in that order, before any other operation on the new child. Example: Do not keep a reference to the returned node for a long time, since it is only a proxy toward the real node to be created once the identifier is known.- Specified by:
newChild
in interfaceTreeTable.Node
- Returns:
- the new child.
- Throws:
UnsupportedOperationException
- if this node is a leaf.
-
getCompactChildren
Returns the children if the value policy isValueExistencePolicy.COMPACT
, ornull
otherwise. -
getValue
Returns the value of this node in the given column, ornull
if none. This method verifies thecolumn
argument, then delegates togetName()
,getUserObject()
or other properties.- Specified by:
getValue
in interfaceTreeTable.Node
- Type Parameters:
V
- the base type of values in the given column.- Parameters:
column
- identifier of the column from which to get the value.- Returns:
- the value in the given column, or
null
if none. - See Also:
-
setValue
Sets the value if the given column isTableColumn.VALUE
. This method verifies thecolumn
argument, then delegates tosetUserObject(Object)
.This method does not accept null value, because setting a singleton property to null with
ValueExistencePolicy.NON_EMPTY
is equivalent to removing the property, and setting a collection element to null is not allowed. Those various behavior are at risk of causing confusion, so we are better to never allow null.- Specified by:
setValue
in interfaceTreeTable.Node
- Type Parameters:
V
- the base type of values in the given column.- Parameters:
column
- identifier of the column into which to set the value.value
- the value to set.- Throws:
UnsupportedOperationException
- if values in the given column cannot be modified.- See Also:
-
unmodifiableCellValue
Returns the error message for an unmodifiable cell value in the given column. -
isEditable
Returnstrue
if the given column isTableColumn.VALUE
and the property is writable, orfalse
in all other cases. This method verifies thecolumn
argument, then delegates toisWritable()
.- Specified by:
isEditable
in interfaceTreeTable.Node
- Parameters:
column
- the column to query.- Returns:
true
if the given column is a legal column for thisNode
implementation and the corresponding value is editable, orfalse
otherwise.
-
toString
Returns a string representation of this node for debugging purpose. -
appendStringTo
Implementation oftoString()
appending the string representation in the given buffer.
-