com.metamatrix.toolbox.ui.widget.tree
Class DefaultTreeNodeEditor

java.lang.Object
  extended by com.metamatrix.toolbox.ui.widget.tree.DefaultTreeNodeEditor
All Implemented Interfaces:
PropertiedObjectEditor, PropertyAccessPolicy, UserTransactionFactory, TreeNodeEditor

public class DefaultTreeNodeEditor
extends java.lang.Object
implements TreeNodeEditor

Since:
2.0
Version:
2.0
Author:
John P. A. Verhaeg

Field Summary
 
Fields inherited from interface com.metamatrix.common.object.PropertiedObjectEditor
NO_VALUE
 
Fields inherited from interface com.metamatrix.common.object.PropertyAccessPolicy
DEFAULT_READ_ONLY_PRIVILEGE
 
Constructor Summary
DefaultTreeNodeEditor(DefaultTreeNode root, java.util.HashMap parentMap, java.util.HashMap childrenMap)
           
 
Method Summary
 TreeNode create(TreeNode parent, ObjectDefinition type)
          Create a new instance of a TreeNode under the specified parent and with the specified type.
 TreeNode create(TreeNode parent, java.lang.String childName, ObjectDefinition type)
          Create a new instance of a TreeNode under the specified parent, with the specified type and with the specified name
 UserTransaction createReadTransaction()
          Create a new instance of a UserTransaction that may be used to read information.
 UserTransaction createWriteTransaction()
          Create a new instance of a UserTransaction that may be used to write and/or update information.
 UserTransaction createWriteTransaction(java.lang.Object source)
          Create a new instance of a UserTransaction that may be used to write and/or update information.
 boolean delete(TreeNode node)
          Removes the specified TreeNode instance (and all its children) from its parent.
 java.util.List getAllowedValues(PropertiedObject object, PropertyDefinition def)
          Get the allowed values for the property on the specified object.
 PropertyDefinition getNamePropertyDefinition(TreeNode obj)
          Filter the specified PropertyDefinition instances and return the first definition that is mapped to "the name" property for the tree node.
 PropertyAccessPolicy getPolicy()
           
 java.util.List getPropertyDefinitions(PropertiedObject object)
          Obtain the list of PropertyDefinitions that apply to the specified object's type.
 java.lang.Object getValue(PropertiedObject object, PropertyDefinition definition)
          Obtain from the specified PropertiedObject the property value that corresponds to the specified PropertyDefinition.
protected  void initializeDefaultTreeEditor()
           
 boolean isAncestorOf(TreeNode ancestor, TreeNode descendent)
          Determine whether the specified node is a descendent of the given ancestor node.
 boolean isMarked(TreeNode node)
          Return the marked state of the specified node.
 boolean isParentOf(TreeNode parent, TreeNode child)
          Determine whether the specified node is a child of the given parent node.
 boolean isReadOnly(PropertiedObject object)
          Return whether this editor may be used to set property values on the specified PropertiedObject.
 boolean isReadOnly(PropertiedObject object, PropertyDefinition definition)
           
 boolean isValidValue(PropertiedObject object, PropertyDefinition definition, java.lang.Object value)
          Return whether the specified value is considered valid.
 boolean move(TreeNode child, TreeNode parent)
          Moves this TreeNode to be a child of the specified new parent.
 boolean move(TreeNode child, TreeNode parent, int index)
          Moves this TreeNode to be a child at a particular index in the specified new parent.
 boolean moveChild(TreeNode child, int index)
          Moves this TreeNode to the specified location within the ordered list of children for the node's parent.
 TreeNode paste(TreeNode child, TreeNode parent, boolean isCopyDeep)
          Creates and places a copy of the specified original TreeNode under the specified new parent.
 boolean rename(TreeNode node, java.lang.String name)
          Renames this TreeNode to the specified new name.
 void reset(PropertiedObject object)
           
 void setMarked(TreeNode node, boolean isMarked)
          Set the marked state of the TreeNode node.
 void setPolicy(PropertyAccessPolicy policy)
           
 void setReadOnly(PropertiedObject object, boolean isReadOnly)
           
 void setReadOnly(PropertiedObject object, PropertyDefinition definition, boolean isReadOnly)
           
 void setValue(PropertiedObject object, PropertyDefinition definition, java.lang.Object value)
          Set on the specified PropertiedObject the value defined by the specified PropertyDefinition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTreeNodeEditor

public DefaultTreeNodeEditor(DefaultTreeNode root,
                             java.util.HashMap parentMap,
                             java.util.HashMap childrenMap)
Since:
2.0
Method Detail

create

public TreeNode create(TreeNode parent,
                       ObjectDefinition type)
Description copied from interface: TreeNodeEditor
Create a new instance of a TreeNode under the specified parent and with the specified type. The name of the new object is created automatically.

Specified by:
create in interface TreeNodeEditor
Parameters:
parent - the TreeNode that is to be the parent of the new tree node object
type - the ObjectDefinition instance that defines the type of tree node object to instantiate.
Returns:
the new instance or null if the new instance could not be created.
Since:
2.0

create

public TreeNode create(TreeNode parent,
                       java.lang.String childName,
                       ObjectDefinition type)
Description copied from interface: TreeNodeEditor
Create a new instance of a TreeNode under the specified parent, with the specified type and with the specified name

Specified by:
create in interface TreeNodeEditor
Parameters:
parent - the TreeNode that is to be the parent of the new tree node object
childName - the name for the new object
type - the ObjectDefinition instance that defines the type of tree node object to instantiate.
Returns:
the new instance or null if the new instance could not be created.
Since:
2.0

createReadTransaction

public UserTransaction createReadTransaction()
Description copied from interface: UserTransactionFactory
Create a new instance of a UserTransaction that may be used to read information. Read transactions do not have a source object associated with them (since they never directly modify data).

The returned transaction object will not be bound to an underlying system transaction until begin() is called on the returned object.

Specified by:
createReadTransaction in interface UserTransactionFactory
Returns:
the new transaction object
Since:
2.0

createWriteTransaction

public UserTransaction createWriteTransaction()
Description copied from interface: UserTransactionFactory
Create a new instance of a UserTransaction that may be used to write and/or update information. The transaction will not have a source object associated with it.

The returned transaction object will not be bound to an underlying system transaction until begin() is called on the returned object.

Specified by:
createWriteTransaction in interface UserTransactionFactory
Returns:
the new transaction object
Since:
2.0

createWriteTransaction

public UserTransaction createWriteTransaction(java.lang.Object source)
Description copied from interface: UserTransactionFactory
Create a new instance of a UserTransaction that may be used to write and/or update information. The source object will be used for all events that are fired as a result of or as a product of this transaction.

The returned transaction object will not be bound to an underlying system transaction until begin() is called on the returned object.

Specified by:
createWriteTransaction in interface UserTransactionFactory
Parameters:
source - the object that is considered to be the source of the transaction; may be null
Returns:
the new transaction object
Since:
2.0

delete

public boolean delete(TreeNode node)
Description copied from interface: TreeNodeEditor
Removes the specified TreeNode instance (and all its children) from its parent. After this method is called, the caller is responsible for maintaining the referenced to the specified object (to prevent garbage collection).

Specified by:
delete in interface TreeNodeEditor
Returns:
true if deletion is successful, or false otherwise.
Since:
2.0

getPolicy

public PropertyAccessPolicy getPolicy()
Specified by:
getPolicy in interface PropertiedObjectEditor
Since:
2.0

getPropertyDefinitions

public java.util.List getPropertyDefinitions(PropertiedObject object)
Description copied from interface: PropertiedObjectEditor
Obtain the list of PropertyDefinitions that apply to the specified object's type.

Specified by:
getPropertyDefinitions in interface PropertiedObjectEditor
Parameters:
object - the propertied object for which the PropertyDefinitions are to be obtained; may not be null
Returns:
an unmodifiable list of the PropertyDefinition objects that define the properties for the object; never null but possibly empty
Since:
2.0

getAllowedValues

public java.util.List getAllowedValues(PropertiedObject object,
                                       PropertyDefinition def)
Description copied from interface: PropertiedObjectEditor
Get the allowed values for the property on the specified object.

Specified by:
getAllowedValues in interface PropertiedObjectEditor
Parameters:
object - the propertied object whose property value is to be obtained; may not be null
def - the reference to the PropertyDefinition describing the property whose value is to be returned; may not be null
Returns:
the unmodifiable list of allowed values for this property, or an empty set if the values do not have to conform to a fixed set.
Since:
2.0
See Also:
#hasAllowedValues

getNamePropertyDefinition

public PropertyDefinition getNamePropertyDefinition(TreeNode obj)
Description copied from interface: TreeNodeEditor
Filter the specified PropertyDefinition instances and return the first definition that is mapped to "the name" property for the tree node.

Specified by:
getNamePropertyDefinition in interface TreeNodeEditor
Parameters:
obj - the tree node; may not be null
Returns:
the first PropertyDefinition instance found in the list of PropertyDefinition instances that represents the name property for the object, or null if no such PropertyDefinition is found.
Since:
2.0

getValue

public java.lang.Object getValue(PropertiedObject object,
                                 PropertyDefinition definition)
Description copied from interface: PropertiedObjectEditor
Obtain from the specified PropertiedObject the property value that corresponds to the specified PropertyDefinition. The return type and cardinality (including whether the value may be null) depend upon the PropertyDefinition. If the property definition allows multiple values (i.e., its maximum multiplicity is greater than 1), the returned Object will be an Object[] containing Objects of the type prescribed by the PropertyDefinition.

Specified by:
getValue in interface PropertiedObjectEditor
Parameters:
object - the propertied object whose property value is to be obtained; may not be null
definition - the reference to the PropertyDefinition describing the property whose value is to be returned; may not be null
Returns:
the value for the property, which will be an object array if the property is multi-valued; the result may be null if the multiplicity includes "0", or the result may be the NO_VALUE reference if the specified object does not contain the specified PropertyDefinition
Since:
2.0

initializeDefaultTreeEditor

protected void initializeDefaultTreeEditor()
Since:
2.0

isAncestorOf

public boolean isAncestorOf(TreeNode ancestor,
                            TreeNode descendent)
Description copied from interface: TreeNodeEditor
Determine whether the specified node is a descendent of the given ancestor node.

Specified by:
isAncestorOf in interface TreeNodeEditor
Returns:
true if the node is a descendent of the given ancestor node.
Since:
2.0

isMarked

public boolean isMarked(TreeNode node)
Description copied from interface: TreeNodeEditor
Return the marked state of the specified node.

Specified by:
isMarked in interface TreeNodeEditor
Returns:
the marked state of the node.
Since:
2.0

isParentOf

public boolean isParentOf(TreeNode parent,
                          TreeNode child)
Description copied from interface: TreeNodeEditor
Determine whether the specified node is a child of the given parent node.

Specified by:
isParentOf in interface TreeNodeEditor
Returns:
true if the node is a child of the given parent node.
Since:
2.0

isReadOnly

public boolean isReadOnly(PropertiedObject object)
Description copied from interface: PropertiedObjectEditor
Return whether this editor may be used to set property values on the specified PropertiedObject.

Specified by:
isReadOnly in interface PropertiedObjectEditor
Specified by:
isReadOnly in interface PropertyAccessPolicy
Parameters:
object - the propertied object; may not be null
Returns:
true if the object may not be modified, or false otherwise.
Since:
2.0

isReadOnly

public boolean isReadOnly(PropertiedObject object,
                          PropertyDefinition definition)
Specified by:
isReadOnly in interface PropertyAccessPolicy
Since:
2.0

isValidValue

public boolean isValidValue(PropertiedObject object,
                            PropertyDefinition definition,
                            java.lang.Object value)
Description copied from interface: PropertiedObjectEditor
Return whether the specified value is considered valid. The value is not valid if the propertied object does not have the specified property definition, or if it does but the value is inconsistent with the requirements of the property definition. If the property is multi-valued, the value is expected to be an instance of Object[].

Specified by:
isValidValue in interface PropertiedObjectEditor
Parameters:
object - the propertied object whose property value is to be validated; may not be null
definition - the reference to the PropertyDefinition describing the property whose value is to be validated; may not be null
value - the proposed value for the property, which must be an object array if the property is multi-valued, and which may be null if the multiplicity includes "0"
Returns:
true if the value is considered valid, or false otherwise.
Since:
2.0

move

public boolean move(TreeNode child,
                    TreeNode parent)
Description copied from interface: TreeNodeEditor
Moves this TreeNode to be a child of the specified new parent. The specified object is modified, since it's namespace is changed to be newParent.

This method may be used in conjunction with the delete method of an editor from this or another another session to cut TreeNode instances from the original's session and paste them (or move them) into this session.

Specified by:
move in interface TreeNodeEditor
parent - the node that is to be considered the parent of the existing instance; may not be null
Returns:
true if this node was moved, or false otherwise.
Since:
2.0

move

public boolean move(TreeNode child,
                    TreeNode parent,
                    int index)
Description copied from interface: TreeNodeEditor
Moves this TreeNode to be a child at a particular index in the specified new parent. The specified object is modified, since it's namespace is changed to be newParent.

This method may be used in conjunction with the delete method of an editor from this or another another session to cut TreeNode instances from the original's session and paste them (or move them) into this session.

Specified by:
move in interface TreeNodeEditor
parent - the node that is to be considered the parent of the existing instance; may not be null
index - the position that this node will occupy within the ordered list of children for newParent.
Returns:
true if this node was moved, or false otherwise.
Since:
2.0

moveChild

public boolean moveChild(TreeNode child,
                         int index)
Description copied from interface: TreeNodeEditor
Moves this TreeNode to the specified location within the ordered list of children for the node's parent.

Specified by:
moveChild in interface TreeNodeEditor
Parameters:
child - the node to be moved; may not be null
index - the position that this node will occupy within the ordered list of children for the node's parent.
Returns:
true if this node was moved, or false otherwise.
Since:
2.0

paste

public TreeNode paste(TreeNode child,
                      TreeNode parent,
                      boolean isCopyDeep)
Description copied from interface: TreeNodeEditor
Creates and places a copy of the specified original TreeNode under the specified new parent. This method does not affect the original TreeNode or its contents.

This methods may be used in conjunction with a reference to an existing TreeNode instance in this or another session to copy TreeNode instances and paste them in this session.

Specified by:
paste in interface TreeNodeEditor
Parameters:
child - the original node to be copied; may not be null
parent - the nodethat is to be considered the parent of the newly created instances; may not be null
isCopyDeep - true if this paste operation is to place a deep copy of original, or false if only the original node and its immediate properties are to be pasted.
Returns:
the node that resulted from the paste, or null if the paste failed.
Since:
2.0

rename

public boolean rename(TreeNode node,
                      java.lang.String name)
Description copied from interface: TreeNodeEditor
Renames this TreeNode to the specified new name. This operation will not succeed if there is already a node underneath the parent with the same name as the specified newName.

Specified by:
rename in interface TreeNodeEditor
name - the new name for the object; may not be null or zero-length, and must not be used by an existing sibling
Returns:
true if this node was renamed, or false otherwise.
Since:
2.0

reset

public void reset(PropertiedObject object)
Specified by:
reset in interface PropertyAccessPolicy
Since:
2.0

setMarked

public void setMarked(TreeNode node,
                      boolean isMarked)
Description copied from interface: TreeNodeEditor
Set the marked state of the TreeNode node.

Specified by:
setMarked in interface TreeNodeEditor
isMarked - the marked state of the node.
Since:
2.0

setPolicy

public void setPolicy(PropertyAccessPolicy policy)
Specified by:
setPolicy in interface PropertiedObjectEditor
Since:
2.0

setReadOnly

public void setReadOnly(PropertiedObject object,
                        boolean isReadOnly)
Specified by:
setReadOnly in interface PropertyAccessPolicy
Since:
2.0

setReadOnly

public void setReadOnly(PropertiedObject object,
                        PropertyDefinition definition,
                        boolean isReadOnly)
Specified by:
setReadOnly in interface PropertyAccessPolicy
Since:
2.0

setValue

public void setValue(PropertiedObject object,
                     PropertyDefinition definition,
                     java.lang.Object value)
Description copied from interface: PropertiedObjectEditor
Set on the specified PropertiedObject the value defined by the specified PropertyDefinition.

Specified by:
setValue in interface PropertiedObjectEditor
Parameters:
object - the propertied object whose property value is to be set; may not be null
definition - the reference to the PropertyDefinition describing the property whose value is to be changed; may not be null
value - the proposed value for the property, which must be an object array if the property is multi-valued, and which may be null if the multiplicity includes "0"
Since:
2.0


Copyright © 2009. All Rights Reserved.