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.
Constructor and Description |
---|
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. |
Modifier and Type | Method and Description |
---|---|
boolean |
changeNodeName(org.apache.commons.configuration.tree.ConfigurationNode node,
String newName)
Changes the name of a
ConfigurationNode . |
void |
configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
Reacts on change events of the associated
Configuration . |
org.apache.commons.configuration.HierarchicalConfiguration |
getConfiguration()
Returns the
HierarchicalConfiguration associated with this
object. |
TreeModelChangeListener |
getModelChangeListener()
Returns the
TreeModelChangeListener associated with this object. |
public TreeConfigurationChangeHandler(org.apache.commons.configuration.HierarchicalConfiguration config, TreeModelChangeListener listener)
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.config
- the associated HierarchicalConfiguration
listener
- the change listenerpublic org.apache.commons.configuration.HierarchicalConfiguration getConfiguration()
HierarchicalConfiguration
associated with this
object.HierarchicalConfiguration
public TreeModelChangeListener getModelChangeListener()
TreeModelChangeListener
associated with this object.TreeModelChangeListener
public boolean changeNodeName(org.apache.commons.configuration.tree.ConfigurationNode node, String newName)
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.node
- the ConfigurationNode
to be changednewName
- the new name of this nodepublic void configurationChanged(org.apache.commons.configuration.event.ConfigurationEvent event)
Configuration
. This
implementation determines the root node of the sub tree affected by the
change. This node is then passed to the associated
TreeModelChangeListener
.configurationChanged
in interface org.apache.commons.configuration.event.ConfigurationListener
event
- the change event fired by the configurationCopyright © 2016 The JGUIraffe Team. All rights reserved.