Class ObjectTreeModel

  • All Implemented Interfaces:
    javax.swing.tree.TreeModel

    public class ObjectTreeModel
    extends java.lang.Object
    implements javax.swing.tree.TreeModel
    Tree model for inspecting objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static boolean enableObjectInspection
      flag to indicate if java objects should be inspectable in the tree TO DO: make configurable via GUI?
      protected static javax.swing.UIDefaults icons
      The image icons.
      protected java.util.List inspectors
      list for all created Attribute inspector nodes
      protected java.util.Set listeners
      The listeners.
      protected boolean notify
      The pending notification flag.
      protected ObjectTreeModel.ObjectInspectorNode root
      The root node.
      protected int uuidcounter
      UUID counter
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectTreeModel​(java.lang.Object root)
      Create new OAV tree model.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addTreeModelListener​(javax.swing.event.TreeModelListener l)
      Add a listener to the model.
      protected void fireTreeStructureChanged​(java.lang.Object[] treePath)
      Regenerate subtree if a node was replaced
      java.lang.Object getChild​(java.lang.Object parent, int index)
      Get the given child of a node.
      int getChildCount​(java.lang.Object parent)
      Get the number of children of the given node.
      protected int getIndexForChild​(java.util.List children, java.lang.Object child)
      Get the index for a child in children list, beginning with index=0
      protected int getIndexForChild​(java.util.List children, java.lang.Object child, int start)
      Returns the FIRST occurrence of child in given children list.
      int getIndexOfChild​(java.lang.Object parent, java.lang.Object child)
      Get the index of a given child.
      protected int getNextNodeUUID()
      Generate a unique id for ObjectNode's
      java.lang.Object getRoot()
      Get the root node of the tree.
      protected static boolean isInspectable​(java.lang.Class clazz, boolean inspectObjectClass)
      Decide if java object should be inspectable.
      protected static boolean isInspectable​(java.lang.Object obj)
      Decide if java object should be inspectable.
      boolean isLeaf​(java.lang.Object node)
      Check if a node is a leaf node.
      protected void refreshInspectorNodes()
      Refresh all displayed attributes
      void removeTreeModelListener​(javax.swing.event.TreeModelListener l)
      Remove a listener from the model.
      protected boolean testInspectorNodesListEquals​(java.util.List l1, java.util.List l2)
      Tests if two lists of Inspector nodes (e.g.
      void valueForPathChanged​(javax.swing.tree.TreePath path, java.lang.Object newValue)
      Called by user changes (when the tree is editable).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • enableObjectInspection

        protected static final boolean enableObjectInspection
        flag to indicate if java objects should be inspectable in the tree TO DO: make configurable via GUI?
        See Also:
        Constant Field Values
      • icons

        protected static final javax.swing.UIDefaults icons
        The image icons.
      • listeners

        protected java.util.Set listeners
        The listeners.
      • notify

        protected boolean notify
        The pending notification flag.
      • inspectors

        protected java.util.List inspectors
        list for all created Attribute inspector nodes
      • uuidcounter

        protected int uuidcounter
        UUID counter
    • Constructor Detail

      • ObjectTreeModel

        public ObjectTreeModel​(java.lang.Object root)
        Create new OAV tree model.
        Parameters:
        showempty - Flag, if empty attributes should be shown.
    • Method Detail

      • getRoot

        public java.lang.Object getRoot()
        Get the root node of the tree.
        Specified by:
        getRoot in interface javax.swing.tree.TreeModel
      • getChildCount

        public int getChildCount​(java.lang.Object parent)
        Get the number of children of the given node.
        Specified by:
        getChildCount in interface javax.swing.tree.TreeModel
      • getChild

        public java.lang.Object getChild​(java.lang.Object parent,
                                         int index)
        Get the given child of a node.
        Specified by:
        getChild in interface javax.swing.tree.TreeModel
      • getIndexOfChild

        public int getIndexOfChild​(java.lang.Object parent,
                                   java.lang.Object child)
        Get the index of a given child.
        Specified by:
        getIndexOfChild in interface javax.swing.tree.TreeModel
      • isLeaf

        public boolean isLeaf​(java.lang.Object node)
        Check if a node is a leaf node.
        Specified by:
        isLeaf in interface javax.swing.tree.TreeModel
      • addTreeModelListener

        public void addTreeModelListener​(javax.swing.event.TreeModelListener l)
        Add a listener to the model.
        Specified by:
        addTreeModelListener in interface javax.swing.tree.TreeModel
      • removeTreeModelListener

        public void removeTreeModelListener​(javax.swing.event.TreeModelListener l)
        Remove a listener from the model.
        Specified by:
        removeTreeModelListener in interface javax.swing.tree.TreeModel
      • valueForPathChanged

        public void valueForPathChanged​(javax.swing.tree.TreePath path,
                                        java.lang.Object newValue)
        Called by user changes (when the tree is editable).
        Specified by:
        valueForPathChanged in interface javax.swing.tree.TreeModel
      • getNextNodeUUID

        protected int getNextNodeUUID()
        Generate a unique id for ObjectNode's
        Returns:
        synchronized call to System.currentTimeMillis();
      • fireTreeStructureChanged

        protected void fireTreeStructureChanged​(java.lang.Object[] treePath)
        Regenerate subtree if a node was replaced
        Parameters:
        treePath - The Path to the node that was changed
      • testInspectorNodesListEquals

        protected boolean testInspectorNodesListEquals​(java.util.List l1,
                                                       java.util.List l2)
        Tests if two lists of Inspector nodes (e.g. children) are semantically equals
        Parameters:
        l1 - list to test
        l2 - list to test
        Returns:
        true if the lists are the same or contains the semantically same objects in the same order
      • getIndexForChild

        protected int getIndexForChild​(java.util.List children,
                                       java.lang.Object child,
                                       int start)
        Returns the FIRST occurrence of child in given children list. Be sure to remove the child from the list or to save the index to find additional occurrences of the child in later searches.
        Parameters:
        children - List to search for the child.
        child - The child to search for.
        Returns:
        the FIRST index for the child in the children list
      • refreshInspectorNodes

        protected void refreshInspectorNodes()
        Refresh all displayed attributes
        Parameters:
        oldRoot -
      • isInspectable

        protected static boolean isInspectable​(java.lang.Object obj)
        Decide if java object should be inspectable.
      • isInspectable

        protected static boolean isInspectable​(java.lang.Class clazz,
                                               boolean inspectObjectClass)
        Decide if java object should be inspectable. This method test if clazz.isAssignableFrom([String|Number|Character|])