Class PreferenceManager


  • public class PreferenceManager
    extends java.lang.Object
    A preference manager maintains a hierarchy of preference nodes and associated preference pages.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int POST_ORDER
      Post-order means visit the children, and then the root.
      static int PRE_ORDER
      Pre-order traversal means visit the root first, then the children.
    • Constructor Summary

      Constructors 
      Constructor Description
      PreferenceManager()
      Creates a new preference manager.
      PreferenceManager​(char separatorChar)
      Creates a new preference manager with the given path separator.
      PreferenceManager​(char separatorChar, PreferenceNode rootNode)
      Creates a new preference manager with the given path separator and root node.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addTo​(java.lang.String path, IPreferenceNode node)
      Adds the given preference node as a subnode of the node at the given path.
      void addToRoot​(IPreferenceNode node)
      Adds the given preference node as a subnode of the root.
      protected void buildSequence​(IPreferenceNode node, java.util.List<IPreferenceNode> sequence, int order)
      Recursively enumerates all nodes at or below the given node and adds them to the given list in the given order.
      IPreferenceNode find​(java.lang.String path)
      Finds and returns the contribution node at the given path.
      protected IPreferenceNode find​(java.lang.String path, IPreferenceNode top)
      Finds and returns the preference node directly below the top at the given path.
      java.util.List<IPreferenceNode> getElements​(int order)
      Returns all preference nodes managed by this manager.
      protected IPreferenceNode getRoot()
      Returns the root node.
      IPreferenceNode[] getRootSubNodes()
      Returns the root level nodes of this preference manager.
      IPreferenceNode remove​(java.lang.String path)
      Removes the preference node at the given path.
      boolean remove​(IPreferenceNode node)
      Removes the given preference node if it is managed by this contribution manager.
      void removeAll()
      Removes all contribution nodes known to this manager.
      • Methods inherited from class java.lang.Object

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

      • PRE_ORDER

        public static final int PRE_ORDER
        Pre-order traversal means visit the root first, then the children.
        See Also:
        Constant Field Values
      • POST_ORDER

        public static final int POST_ORDER
        Post-order means visit the children, and then the root.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PreferenceManager

        public PreferenceManager()
        Creates a new preference manager.
      • PreferenceManager

        public PreferenceManager​(char separatorChar)
        Creates a new preference manager with the given path separator.
        Parameters:
        separatorChar - preference node separator
      • PreferenceManager

        public PreferenceManager​(char separatorChar,
                                 PreferenceNode rootNode)
        Creates a new preference manager with the given path separator and root node.
        Parameters:
        separatorChar - the separator character
        rootNode - the root node.
        Since:
        3.4
    • Method Detail

      • addTo

        public boolean addTo​(java.lang.String path,
                             IPreferenceNode node)
        Adds the given preference node as a subnode of the node at the given path.
        Parameters:
        path - the path
        node - the node to add
        Returns:
        true if the add was successful, and false if there is no contribution at the given path
      • addToRoot

        public void addToRoot​(IPreferenceNode node)
        Adds the given preference node as a subnode of the root.
        Parameters:
        node - the node to add, which must implement IPreferenceNode
      • buildSequence

        protected void buildSequence​(IPreferenceNode node,
                                     java.util.List<IPreferenceNode> sequence,
                                     int order)
        Recursively enumerates all nodes at or below the given node and adds them to the given list in the given order.
        Parameters:
        node - the starting node
        sequence - a read-write list of preference nodes (element type: IPreferenceNode) in the given order
        order - the traversal order, one of PRE_ORDER and POST_ORDER
      • find

        public IPreferenceNode find​(java.lang.String path)
        Finds and returns the contribution node at the given path.
        Parameters:
        path - the path
        Returns:
        the node, or null if none
      • find

        protected IPreferenceNode find​(java.lang.String path,
                                       IPreferenceNode top)
        Finds and returns the preference node directly below the top at the given path.
        Parameters:
        path - the path
        top - top at the given path
        Returns:
        the node, or null if none
        Since:
        3.1
      • getElements

        public java.util.List<IPreferenceNode> getElements​(int order)
        Returns all preference nodes managed by this manager.
        Parameters:
        order - the traversal order, one of PRE_ORDER and POST_ORDER
        Returns:
        a list of preference nodes (element type: IPreferenceNode) in the given order
      • getRoot

        protected IPreferenceNode getRoot()
        Returns the root node. Note that the root node is a special internal node that is used to collect together all the nodes that have no parent; it is not given out to clients.
        Returns:
        the root node
      • getRootSubNodes

        public final IPreferenceNode[] getRootSubNodes()
        Returns the root level nodes of this preference manager.
        Returns:
        an array containing the root nodes
        Since:
        3.2
      • remove

        public IPreferenceNode remove​(java.lang.String path)
        Removes the preference node at the given path.
        Parameters:
        path - the path
        Returns:
        the node that was removed, or null if there was no node at the given path
      • remove

        public boolean remove​(IPreferenceNode node)
        Removes the given preference node if it is managed by this contribution manager.
        Parameters:
        node - the node to remove
        Returns:
        true if the node was removed, and false otherwise
      • removeAll

        public void removeAll()
        Removes all contribution nodes known to this manager.