org.knime.core.node.config
Class ConfigEditTreeModel

java.lang.Object
  extended by javax.swing.tree.DefaultTreeModel
      extended by org.knime.core.node.config.ConfigEditTreeModel
All Implemented Interfaces:
Serializable, TreeModel

public final class ConfigEditTreeModel
extends DefaultTreeModel

Config editor that keeps a mask of variables to overwrite existing settings. This class is used to modify node settings with values assigned from flow variables. It also keeps a list of "exposed variables", that is each individual setting can be exported as a new variable.

This class is not meant to be used anywhere else than in the KNIME framework classes.

Author:
Bernd Wiswedel, University of Konstanz
See Also:
Serialized Form

Nested Class Summary
static class ConfigEditTreeModel.ConfigEditTreeNode
          Single Tree node implementation.
 
Field Summary
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Method Summary
 void addConfigEditTreeEventListener(ConfigEditTreeEventListener listener)
          Adds new listener.
static ConfigEditTreeModel create(Config settingsTree)
          Parses a settings tree and creates an empty mask (for later modification).
static ConfigEditTreeModel create(Config settingsTree, Config variableTree)
          Factory method that parses the settings tree and constructs a new object of this class.
static boolean doesTypeAccept(FlowVariable.Type desiredType, FlowVariable.Type actualType)
          Determines whether a flow variable at hand (represented by its actual type) can be converted into a desired type.
 ConfigEditTreeModel.ConfigEditTreeNode findChildForKeyPath(String[] keyPath)
          Get the child tree node associated with the key path.
(package private)  void fireConfigEditTreeEvent(String[] treePath, String useVariable, String exposeVariableName)
          Fire an event.
 ConfigEditTreeModel.ConfigEditTreeNode getRoot()
          
 boolean hasConfiguration()
           
 List<FlowVariable> overwriteSettings(Config settingsTree, Map<String,FlowVariable> variables)
          Modifies the first argument to reflect the values of the mask represented by this object.
 void removeConfigEditTreeEventListener(ConfigEditTreeEventListener listener)
          Removes a registered listener.
 String toString()
          
 void update(Collection<FlowVariableModel> variableModels)
          Updates this tree with the settings available in the argument list.
 void writeVariablesTo(Config config)
          Write the mask to a config object (for storage in node settings object).
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static ConfigEditTreeModel create(Config settingsTree,
                                         Config variableTree)
                                  throws InvalidSettingsException
Factory method that parses the settings tree and constructs a new object of this class. It will use the mask as given by the second argument (which may be null, however).

Parameters:
settingsTree - The original settings object.
variableTree - The variables mask.
Returns:
a new object of this class.
Throws:
InvalidSettingsException - If setting can't be parsed

create

public static ConfigEditTreeModel create(Config settingsTree)
Parses a settings tree and creates an empty mask (for later modification).

Parameters:
settingsTree - to be parsed.
Returns:
a new object of this class.

doesTypeAccept

public static boolean doesTypeAccept(FlowVariable.Type desiredType,
                                     FlowVariable.Type actualType)
Determines whether a flow variable at hand (represented by its actual type) can be converted into a desired type. In short: string accepts also double and integer, double accepts integer, integer only accepts integer.

Parameters:
desiredType - The type that is requested.
actualType - The actual type.
Returns:
If a flow variable of type actualType can be used to represent a flow variable of type desiredType.

hasConfiguration

public boolean hasConfiguration()
Returns:
true if there is any mask (overwriting settings) below this branch of the tree.

writeVariablesTo

public void writeVariablesTo(Config config)
Write the mask to a config object (for storage in node settings object).

Parameters:
config - To save to.

overwriteSettings

public List<FlowVariable> overwriteSettings(Config settingsTree,
                                            Map<String,FlowVariable> variables)
                                     throws InvalidSettingsException
Modifies the first argument to reflect the values of the mask represented by this object.

Parameters:
settingsTree - settings tree to modify (supposed to have equivalent tree structure)
variables - The has of variables-values to apply.
Returns:
A list of exposed variables
Throws:
InvalidSettingsException - If reading fails

getRoot

public ConfigEditTreeModel.ConfigEditTreeNode getRoot()

Specified by:
getRoot in interface TreeModel
Overrides:
getRoot in class DefaultTreeModel

findChildForKeyPath

public ConfigEditTreeModel.ConfigEditTreeNode findChildForKeyPath(String[] keyPath)
Get the child tree node associated with the key path. Returns null if there is no child.

Parameters:
keyPath - The path the child.
Returns:
the child (or a children's child) for the given key path.

update

public void update(Collection<FlowVariableModel> variableModels)
Updates this tree with the settings available in the argument list. This becomes necessary if a dialog provides its "expert" settings also via small button attached to different controls. This method ensures that the tree and the button model are in sync.

Parameters:
variableModels - The models that were registered at the dialog.

toString

public String toString()

Overrides:
toString in class Object

addConfigEditTreeEventListener

public void addConfigEditTreeEventListener(ConfigEditTreeEventListener listener)
Adds new listener.

Parameters:
listener - to be added.

removeConfigEditTreeEventListener

public void removeConfigEditTreeEventListener(ConfigEditTreeEventListener listener)
Removes a registered listener.

Parameters:
listener - to be removed.

fireConfigEditTreeEvent

void fireConfigEditTreeEvent(String[] treePath,
                             String useVariable,
                             String exposeVariableName)
Fire an event.

Parameters:
treePath - The tree path that has changed.
useVariable - The new variable, which overwrites the user settings.
exposeVariableName - The variable name to expose.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.