Class TreeConfigurationChangeHandler

  • All Implemented Interfaces:
    org.apache.commons.configuration.event.ConfigurationListener

    public class TreeConfigurationChangeHandler
    extends Object
    implements org.apache.commons.configuration.event.ConfigurationListener

    A helper class for concrete tree view implementations that supports the processing of change events fired by a configuration serving as tree model.

    In JGUIraffe, for tree views instances of HierarchicalConfiguration are used as data model. It is desired that the tree view updates itself automatically if the underlying configuration object is changed. This is possible because a change listener can be registered at the configuration. This class implements such a change listener. It reacts on configuration change events, detects the configuration parent node affected by this change and passes it to an associated TreeModelChangeListener. This TreeModelChangeListener implementation can then update the underlying UI component.

    However, it is not a trivial task to find out the exact configuration node affected by a change. Configuration change events typically only contain the key of the node affected by a change, and this key is not necessarily unique. This implementation deals with this fact by trying to find a parent node common to all nodes referenced by a key. So the goal is to invalidate only a minimum part of the tree that has to be regenerated to be in sync with the model configuration. In the worst case, when no specific parent node can be determined, the root node used; this means that the whole tree component has to be reconstructed.

    One limitation of this implementation is that it is not fully thread-safe. It expects that only a single change event from a configuration is received at a given point in time. Typically, this should not be a problem because configuration implementations do not support concurrent updates.

    This class is mainly intended to be used internally by implementations for specific UI toolkits. Therefore, it does not do any sophisticated parameter checks.

    Since:
    1.3
    Version:
    $Id: $
    Author:
    Oliver Heger
    • Constructor Detail

      • TreeConfigurationChangeHandler

        public TreeConfigurationChangeHandler​(org.apache.commons.configuration.HierarchicalConfiguration config,
                                              TreeModelChangeListener listener)
        Creates a new instance of TreeConfigurationChangeHandler and initializes it with the given HierarchicalConfiguration and the change listener. Note that this constructor does not register the object as listener at the configuration; this has to be done manually.
        Parameters:
        config - the associated HierarchicalConfiguration
        listener - the change listener
    • Method Detail

      • getConfiguration

        public org.apache.commons.configuration.HierarchicalConfiguration getConfiguration()
        Returns the HierarchicalConfiguration associated with this object.
        Returns:
        the HierarchicalConfiguration
      • getModelChangeListener

        public TreeModelChangeListener getModelChangeListener()
        Returns the TreeModelChangeListener associated with this object.
        Returns:
        the TreeModelChangeListener
      • changeNodeName

        public boolean changeNodeName​(org.apache.commons.configuration.tree.ConfigurationNode node,
                                      String newName)
        Changes the name of a ConfigurationNode. This is a utility method which is probably needed by each concrete tree model implementation. Normally, the name of a configuration node cannot be changed if it is part of a node hierarchy. Therefore, this method uses some tricks to achieve this goal. The return value indicates if a change was done. If the passed in new name equals the current name, nothing is changed, and result is false.
        Parameters:
        node - the ConfigurationNode to be changed
        newName - the new name of this node
        Returns:
        true if a name change was necessary, false otherwise
      • configurationChanged

        public void configurationChanged​(org.apache.commons.configuration.event.ConfigurationEvent event)
        Reacts on change events of the associated Configuration. This implementation determines the root node of the sub tree affected by the change. This node is then passed to the associated TreeModelChangeListener.
        Specified by:
        configurationChanged in interface org.apache.commons.configuration.event.ConfigurationListener
        Parameters:
        event - the change event fired by the configuration