Class DotNotationTree<N extends DotNotationNode>

    • Field Detail

      • m_Items

        protected List<String> m_Items
        the underlying dot notations.
      • m_Search

        protected String m_Search
        the current search string.
      • m_Compress

        protected boolean m_Compress
        whether to compress the tree as much as possible.
      • m_PopupMenuHandler

        protected PopupMenuHandler m_PopupMenuHandler
        the right-click menu handler.
      • m_Sorted

        protected boolean m_Sorted
        whether the items need to be sorted.
      • m_SelectionMode

        protected int m_SelectionMode
        the selection mode to use.
    • Constructor Detail

      • DotNotationTree

        public DotNotationTree()
        Initializes the tree with no items.
    • Method Detail

      • initialize

        protected void initialize()
        Further initialization of the tree.
        Overrides:
        initialize in class DragAndDropTree
      • setSelectionMode

        public void setSelectionMode​(int value)
        Sets the selection mode.
        Parameters:
        value - the selection mode
        See Also:
        postBuildTree(), TreeSelectionModel
      • getSelectionMode

        public int getSelectionMode()
        Returns the selection mode.
        Returns:
        the selection mode
        See Also:
        TreeSelectionModel
      • getDefaultRenderer

        protected TreeCellRenderer getDefaultRenderer()
        Returns the default renderer to use.
        Returns:
        the renderer
      • showPopup

        protected void showPopup​(MouseEvent e)
        Displays a popup menu, if available.
        Parameters:
        e - the mouse event that triggered the popup menu request
      • isDragEnabled

        protected boolean isDragEnabled()
        Returns whether dragging is enabled.
        Overrides:
        isDragEnabled in class DragAndDropTree
        Returns:
        always true
      • canStartDrag

        protected boolean canStartDrag​(BaseTreeNode[] source)
        Checks whether the source node can be dragged at all.
        Overrides:
        canStartDrag in class DragAndDropTree
        Parameters:
        source - the source node that is about to be dragged
        Returns:
        true if the source node can be dragged
      • getTreeModel

        public DefaultTreeModel getTreeModel()
        Returns the model.
        Returns:
        the model
      • setSorted

        public void setSorted​(boolean value)
        Sets whether the items are sorted or not.
        Parameters:
        value - if true items get sorted
      • isSorted

        public boolean isSorted()
        Returns whether the item get sorted.
        Returns:
        true if items get sorted
      • applySearchFilter

        protected List<String> applySearchFilter​(List<String> items)
        Filters the items according to the search string.
        Parameters:
        items - the items to apply the search filter
        Returns:
        the filtered items
      • hasRootNodeLabel

        protected boolean hasRootNodeLabel()
        Checks whether a root node label is in use.
        Returns:
        true if a root node label is used
      • getRootNodeLabel

        protected String getRootNodeLabel()
        Returns the label used for the root node.
        Returns:
        the label, null if not used
      • getRootPart

        protected String getRootPart​(String item)
        Returns the root part for the specified item.
        Parameters:
        item - the item to determine the root part for
        Returns:
        the root part
      • findRoot

        protected N findRoot​(N root,
                             String item)
        Finds the root for the given item. Creates the root node if necessary.
        Parameters:
        root - optional root node to use
        item - the item to find the root for
        Returns:
        the root node
      • newNode

        protected N newNode​(String label)
        Creates a new node with the specified label.
        Parameters:
        label - the label to use for the node
        Returns:
        the new node
      • postAddLeaf

        protected void postAddLeaf​(N node,
                                   String item)
        Post-processes a leaf after being added, i.e., info node generators are applied.
        Parameters:
        node - the node to process
        item - the full item string
        See Also:
        m_InfoNodeGenerators
      • splitItem

        protected String[] splitItem​(String item)
        Splits the item into its sub-parts.
        Parameters:
        item - the full item string to split
        Returns:
        the generated parts, without the separator
      • getSeparator

        public String getSeparator()
        Returns the separator in use.
        Returns:
        the separator
      • addItem

        protected N addItem​(N root,
                            String item)
        Adds the item to the tree structure.
        Parameters:
        root - the root node
        item - the item to add
        Returns:
        the added node or null if not added, e.g., if root was null
      • findItem

        protected Object[] findItem​(N root,
                                    String[] parts)
        Tries to match the parts of the string to children of the given root node.
        Parameters:
        root - the root node to start from
        parts - the string array to match against the items
        Returns:
        node + remaining array, or null if not found
      • findItem

        protected N findItem​(N root,
                             String item)
        Finds the item in the tree structure.
        Parameters:
        root - the root node
        item - the item to find
        Returns:
        the node or null if not found, e.g., if root was null
      • compress

        protected void compress​(N root)
        Removes unncessary nesting.
        Parameters:
        root - the root of the subtree to flatten
      • compress

        protected void compress()
        Removes unnecessary nesting, i.e., nodes with just one non-leaf child get collapsed.
      • buildTree

        protected void buildTree()
        Builds the tree. Takes any search string into account.
      • postBuildTree

        protected void postBuildTree()
        Hook method just after the tree got built and reloaded.

        Default implementation sets the selection mode.
      • setCompress

        public void setCompress​(boolean value)
        Sets whether to compress the tree (removal of unnecessary nestings) or not. Automatically rebuilds the tree, if necessary.
        Parameters:
        value - if true then compression is attempted
        See Also:
        compress()
      • getCompress

        public boolean getCompress()
        Returns whether the tree gets compressed or not. Compressing means the removal of unnecessary nestings, like nodes with only 1 child that is a non-leaf.
        Returns:
        true if tree gets compressed
        See Also:
        compress()
      • setFilter

        public void setFilter​(AbstractItemFilter value)
        Sets the filter to use for filtering the display.
        Parameters:
        value - the filter, null if to disable filtering
      • getFilter

        public AbstractItemFilter getFilter()
        Returns the current filter.
        Returns:
        the filter, null if none set
      • hasItem

        public boolean hasItem​(String item)
        Checks whether the item is among the stored ones.
        Parameters:
        item - the item to look for
        Returns:
        true if already present
      • addItem

        public void addItem​(String item)
        Adds the item, if necessary.
        Parameters:
        item - the item to add
      • applyItemFilter

        protected List<String> applyItemFilter​(List<String> items)
        Filters the items if a item filter has been specified.
        Parameters:
        items - the items to filter
        Returns:
        the filtered items
      • setItems

        public void setItems​(List<String> items)
        Displays the specified items.
        Parameters:
        items - the items to display
      • setItems

        public void setItems​(String[] items)
        Displays the specified items.
        Parameters:
        items - the items to display
      • setItems

        public void setItems​(BaseString[] items)
        Displays the specified items.
        Parameters:
        items - the items to display
      • addItems

        public void addItems​(List<String> items)
        Adds the items to the current ones and rebuilds the tree.
        Parameters:
        items - the additional items
      • addItems

        public void addItems​(String[] items)
        Adds the items to the current ones and rebuilds the tree.
        Parameters:
        items - the additional items
      • addItems

        public void addItems​(BaseString[] items)
        Adds the items to the current ones and rebuilds the tree.
        Parameters:
        items - the additional items
      • getFirstItem

        public String getFirstItem()
        Returns the first stored item.
        Returns:
        the item or null if no items stored
      • setSelectedItem

        public void setSelectedItem​(String item)
        The item to select initially.
        Parameters:
        item - the item to select
      • setSelectedItems

        public void setSelectedItems​(String[] items)
        The items to select initially.
        Parameters:
        items - the items to select
      • getSelectedItem

        public String getSelectedItem()
        Returns the item of the selected node.
        Returns:
        the selected item, null if none selected
      • getSelectedItems

        public String[] getSelectedItems()
        Returns the items of the selected nodes.
        Returns:
        the selected items, empty array if none selected
      • numItems

        public int numItems()
        Returns the number of items in the tree.
        Returns:
        the number of items
      • setSearch

        public void setSearch​(String value)
        Sets the search string.
        Parameters:
        value - the search string, use null or empty string to display all
      • expandAfterSearch

        protected void expandAfterSearch()
        Gets called after setting a search term (can be empty string).
      • getSearch

        public String getSearch()
        Returns the current search string.
        Returns:
        the search string, null if none set
      • addInfoNodeGenerator

        public void addInfoNodeGenerator​(AbstractInfoNodeGenerator generator)
        Adds the specified generator to the list of generators.
        Parameters:
        generator - the generator to add
      • removeInfoNodeGenerator

        public void removeInfoNodeGenerator​(AbstractInfoNodeGenerator generator)
        Removes the specified generator from the list of generators.
        Parameters:
        generator - the generator to remove
      • setPopupMenuHandler

        public void setPopupMenuHandler​(PopupMenuHandler value)
        Sets the popup menu (right-click) handler to use.
        Parameters:
        value - the handler, null to remove handler
      • getPopupMenuHandler

        public PopupMenuHandler getPopupMenuHandler()
        Returns the current popup menu (right-click) handler.
        Returns:
        the handler, null if none in use
      • main

        public static void main​(String[] args)
        For testing only.
        Parameters:
        args - ignored