Class TreeNode.Element

java.lang.Object
org.apache.sis.metadata.TreeNode
org.apache.sis.metadata.TreeNode.Element
All Implemented Interfaces:
TreeTable.Node
Direct Known Subclasses:
TreeNode.CollectionElement
Enclosing class:
TreeNode

static class TreeNode.Element extends TreeNode
A node for a metadata property value. This class does not store the property value directly. Instead, is stores a reference to the metadata object that contains the property values, together with the index for fetching the value in that object. That way, the real storage objects still the metadata object, which allow TreeTableView to be a dynamic view.

Instances of this class shall be instantiated only for metadata singletons. If a metadata property is a collection, then the TreeNode.CollectionElement subclass shall be instantiated instead.

  • Field Details

    • accessor

      private final PropertyAccessor accessor
      The accessor to use for fetching the property names, types and values from the TreeNode.metadata object. Note that the reference stored in this field is the same for all siblings.
    • indexInData

      private final int indexInData
      Index of the value in the TreeNode.metadata object to be fetched with the accessor.
    • decorator

      final Function<TreeNode,TreeTable.Node> decorator
      If tree node should be wrapped in another object before to be returned, the function performing that wrapping. This is used if we want to render a metadata property in a different way than the way implied by JavaBeans. The wrapping operation should be cheap because it will be applied every time the user request the node.
      Example: the "defaultLocale+otherLocale" property is represented by Map.Entry<Locale,Charset> values. The nodes created by this class contain those Map.Entry values, but we want to show them to users as as a Locale node with a Charset child. This separation is done by LocaleAndCharset.
  • Constructor Details

    • Element

      Element(TreeNode parent, Object metadata, PropertyAccessor accessor, int indexInData)
      Creates a new child for a property of the given metadata at the given index.
      Parameters:
      parent - the parent of this node.
      metadata - the metadata object for which this node will be a value.
      accessor - accessor to use for fetching the name, type and value.
      indexInData - index to be given to the accessor for fetching the value.
  • Method Details

    • getIdentifier

      final String getIdentifier()
      The property identifier to be returned in the TableColumn.IDENTIFIER cells.
      Overrides:
      getIdentifier in class TreeNode
    • appendIdentifier

      void appendIdentifier(StringBuilder buffer)
      Appends an identifier for this node in the given buffer, for TreeNode.toString() implementation.
      Overrides:
      appendIdentifier in class TreeNode
    • getName

      CharSequence getName()
      Gets the name of this node. Current implementation derives the name from the KeyNamePolicy.UML_IDENTIFIER instead of KeyNamePolicy.JAVABEANS_PROPERTY in order to get the singular form instead of the plural one, because we will create one node for each element in a collection.

      If the property name is equal, ignoring case, to the simple type name, then this method returns the subtype name (SIS-298). For example, instead of:

      we format:
      Overrides:
      getName in class TreeNode
    • standardSubType

      private Class<?> standardSubType(Class<?>[] subtypes)
      Returns the element of the given array which is both assignable to TreeNode.baseType and a member of the standard represented by TreeTableView.standard. If no such type is found, returns null. If more than one type is found, returns the Void.TYPE sentinel value.
    • getRemarks

      final CharSequence getRemarks()
      Gets remarks about the value in this node, or null if none.
      Overrides:
      getRemarks in class TreeNode
    • getUserObject

      public Object getUserObject()
      Fetches the node value from the metadata object.
      Specified by:
      getUserObject in interface TreeTable.Node
      Overrides:
      getUserObject in class TreeNode
      Returns:
      any object stored at this node by the user, or null if none.
    • setUserObject

      void setUserObject(Object value)
      Sets the property value for this node.
      Overrides:
      setUserObject in class TreeNode
    • isWritable

      final boolean isWritable()
      Returns true if the metadata is writable.
      Overrides:
      isWritable in class TreeNode
    • equals

      public boolean equals(Object other)
      Returns true if the value returned by getUserObject() should be the same for both nodes.
      Specified by:
      equals in interface TreeTable.Node
      Overrides:
      equals in class TreeNode
      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 interface TreeTable.Node
      Overrides:
      hashCode in class TreeNode
      Returns:
      a hash code for this node, potentially based on values and children but ignoring parent.