public class TreeComposite extends ICEObject implements Composite, IComponentVisitor
When a Component is added to a TreeComposite (keep in mind Composites are Components too!), it will visit that Component to determine its type. If it is another TreeComposite, it will set itself as the parent composite of the child TreeComposite. If it is anything else, it will just be added to the composite. Only TreeComposites can be parent nodes in the tree and the TreeComposite has getNextSibling():TreeComposite, getLastSibling():TreeComposite and getNextChild():TreeComposite operations to iterate across the tree in both breadth and depth. The getNextComponent():Component operation returns the next "data node" in the TreeComposite which is always a Component and never a TreeComposite. It may be any implementation of the Component interface except a Composite, so do not assume that it is just a TreeComposite. This type of trinary separation between siblings, children and data seems a bit odd at first, but it effectively separates the tree structure from data.
Both getNext/LastSibling() and getNextChild() work like standard tree iterators in that the reference can be updated and getNext*() called to go to the next child or sibling. Successively calling getNextChild() on a *child* walks down the tree, but calling it on the parent returns the next child for that parent. Successively calling getNext/LastSibling() walks across the tree. Successively calling getParent() walks up the tree. A node with zero or more children, no parent and no siblings is the root node and the last universal ancestor of all TreeComposites it contains. Children may also be retrieved in a random access mode using getChildAtIndex(), but siblings an only be retrieved by iteration. The resetChildIterator() will set the "iteration pointer" of the children back to the first element of the set.
TreeComposite.getComponents():Component[*] returns all components, both TreeComposites and regular Components. TreeComposite.getComponent(int id):Component returns both TreeComposites and regular Components by id or null if a Component with that id does not exist in the tree. The getDataNodes():Component[*] operation can be called to return a list of Components that contain only data. This list will not contain TreeComposites. TreeComposite.getComponent() assumes that the request is for regular Components first and checks the TreeComposites second. The removeComponent() operation makes the same assumption. That being said, in general you should still give all of your components, whether Component or Composite, unique ids.
If TreeComposite.addComponent() is called with a TreeComposite as an argument, it will be added as child if it not already a child of that parent.
One data node may be specified as the "active" data node. If a data node is marked as active it should take priority over the other data nodes when the nodes are considered for decision making or prioritized. Support for active nodes may be disabled by calling allowActiveDataNodes(false). If this option is specified, getActiveDataNode() will always return null and setActiveDataNode() will not function. Active data nodes are allowed by default. TreeComposites themselves can be marked as active too and this in this case it has the same meaning, but with the added requirement that the entire active composite should be given priority.
There is no concept of spatial ordering in a TreeComposite; Children are always add to the end of the set and next and last refer to the last member of the set with no implied spatial position or index.
The TreeComposite notifies is listeners whenever trees and data nodes are added or removed, whenever the active data node is set, if allowed, and whenever the parent is set. Those IComponentListeners that register with a TreeComposite are also registered as listeners of its children and data nodes because changes to those groups change the tree.
TreeComposites can be configured such that only nodes with specific configurations can be added as children using the setChildExemplars() operation. This capability is used to configure TreeComposites that cannot be universally modified and must be extended according to a specification. If a TreeComposite is configured with this list of allowed children, calling setNextChild() or addComponent() will fail if a child that is not cloned from the list returned by getChildExemplars() is submitted. Special care should be taken that children from this list are added to the TreeComposite *before* they themselves are modified.
iComponentVisitor
iComponentListener
Constructor and Description |
---|
TreeComposite()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(IComponentVisitor visitor)
(non-Javadoc)
|
void |
addChildExemplar(TreeComposite exemplar)
This method adds one TreeComposite to the list of child exemplars.
|
void |
addComponent(Component child)
(non-Javadoc)
|
void |
allowActiveDataNodes(boolean allow)
This operation specifies whether or not this TreeComposite will allow
clients to specify active data nodes.
|
java.lang.Object |
clone()
This operation provides a deep copy of the TreeComposite.
|
void |
copy(TreeComposite otherTreeComposite)
This operation performs a deep copy of the attributes of another
TreeComposite into the current TreeComposite.
|
void |
copy(TreeComposite otherTreeComposite,
boolean copyInPlace)
This operation performs a deep copy of the attributes of another
TreeComposite into the current TreeComposite.
|
boolean |
equals(java.lang.Object otherTreeComposite)
This operation is used to check equality between the TreeComposite and
another TreeComposite.
|
Component |
getActiveDataNode()
This operation returns the active data node for this TreeComposite or
null if the active data node has not been specified if and only if active
data nodes are allowed for this TreeComposite.
|
TreeComposite |
getChildAtIndex(int index)
This operation treats the set of children as if they are randomly
accessible and returns the child at the given index if it is between zero
and the number of children minus one.
|
java.util.ArrayList<TreeComposite> |
getChildExemplars()
This operation retrieves the list of TreeComposites that must be used to
create children for this TreeComposite.
|
Component |
getComponent(int childId)
(non-Javadoc)
|
java.util.ArrayList<Component> |
getComponents()
(non-Javadoc)
|
java.util.ArrayList<Component> |
getDataNodes()
This operation returns the set of data nodes managed by the TreeComposite
or null if no such nodes exist.
|
TreeComposite |
getNextChild()
This operation returns the next child of the TreeComposite.
|
TreeComposite |
getNextSibling()
This operation returns the next or "nearest right" sibling of the
TreeComposite.
|
int |
getNumberOfChildren()
This operation returns the number of children of this TreeComposite.
|
int |
getNumberOfComponents()
(non-Javadoc)
|
int |
getNumberOfDataNodes()
This operation returns the number of data nodes of this TreeComposite.
|
TreeComposite |
getParent()
This operation returns the parent TreeComposite of the current
TreeComposite.
|
TreeComposite |
getPreviousChild()
This operation returns the previous child of the TreeComposite.
|
TreeComposite |
getPreviousSibling()
This operation returns the previous or "nearest left" sibling of the
TreeComposite.
|
boolean |
hasChildExemplars()
This operation returns true if a list of exemplar child node types has
been configured and the TreeComposite can only add children of those
types and false if the TreeComposite is willing to store any component.
|
int |
hashCode()
This operation returns the hashcode value of the TreeComposite.
|
boolean |
isActive()
This operation indicates if the TreeComposite is active.
|
void |
register(IUpdateableListener listener)
Override the register operation so that listeners are also registered
with all
|
void |
removeChild(TreeComposite cNode)
This operation removes the specified child node from the set of children
or does nothing if it is not a child of this TreeComposite.
|
void |
removeComponent(int childId)
(non-Javadoc)
|
void |
resetChildIterator()
This operation resets the child iterator of this TreeComposite to its
initial position at the beginning of the set.
|
void |
setActive(boolean flag)
This operation sets specifies whether or not the TreeComposite is active.
|
void |
setActiveDataNode(Component node)
This operation sets the active data node for the TreeComposite if and
only if active data nodes are allowed for this TreeComposite.
|
void |
setChildExemplars(java.util.ArrayList<TreeComposite> exemplars)
This operation adds a list of TreeComposites that must be used to create
children for this TreeComposite.
|
void |
setNextChild(TreeComposite cNode)
This operation sets add a child to the list of children managed by this
TreeComposite.
|
void |
setParent(TreeComposite pNode)
This operation sets the parent TreeComposite of the current
TreeComposite.
|
void |
unregister(IUpdateableListener listener)
(non-Javadoc)
|
void |
visit(AdaptiveTreeComposite component)
(non-Javadoc)
|
void |
visit(DataComponent component)
(non-Javadoc)
|
void |
visit(EMFComponent component)
This operation informs the visitor that it is actually working with an
EMFComponent and should operate accordingly.
|
void |
visit(GeometryComponent component)
(non-Javadoc)
|
void |
visit(IReactorComponent component)
(non-Javadoc)
|
void |
visit(IShape component)
(non-Javadoc)
|
void |
visit(ListComponent component)
This operation informs the visitor that it is actually working with a
ListComponent.
|
void |
visit(MasterDetailsComponent component)
(non-Javadoc)
|
void |
visit(MatrixComponent component)
(non-Javadoc)
|
void |
visit(MeshComponent component)
(non-Javadoc)
|
void |
visit(ResourceComponent component)
(non-Javadoc)
|
void |
visit(TableComponent component)
(non-Javadoc)
|
void |
visit(TimeDataComponent component)
This operation informs the visitor that it is actually working with a
TimeDataComponent and should operate accordingly.
|
void |
visit(TreeComposite component)
(non-Javadoc)
|
copy, getDescription, getId, getName, setDescription, setId, setName, update
getClass, notify, notifyAll, toString, wait, wait, wait
update
getDescription, getId, getName, setDescription, setId, setName
public void setParent(TreeComposite pNode)
This operation sets the parent TreeComposite of the current TreeComposite. This operation will automatically "rewire" the original parent, if one existed, by removing the current node from the old parent. The TreeComposite for which this operation is called reset its siblings to null and add itself to the parent tree composite.
This operation is essentially a pass-through to setNextChild() with the exception of erasing the link to the siblings and removing the child from the previous parent.
pNode
- The parent node.
public TreeComposite getParent()
This operation returns the parent TreeComposite of the current TreeComposite.
The parent node.
public TreeComposite getNextChild()
This operation returns the next child of the TreeComposite.
The next child in the set of child TreeComposites or null if the end of the set has been reached.
public void setNextChild(TreeComposite cNode)
This operation sets add a child to the list of children managed by this TreeComposite. The child is added to the end of the set and the tree is not "rewired." This operation will not add children that are already members of the TreeComposite and it will not add itself as a child.
cNode
- The next and newest child TreeComposite at this level of the tree.
public TreeComposite getPreviousChild()
This operation returns the previous child of the TreeComposite.
The previous child in the set of child TreeComposites or null if the iterator has returned to the beginning of the set.
public void removeChild(TreeComposite cNode)
This operation removes the specified child node from the set of children or does nothing if it is not a child of this TreeComposite. Calling this operation will "rewire" the tree such that the previous and next siblings of the deleted node will point to each other.
cNode
- The child node to remove.
public int getNumberOfChildren()
This operation returns the number of children of this TreeComposite.
public void resetChildIterator()
This operation resets the child iterator of this TreeComposite to its initial position at the beginning of the set.
public TreeComposite getChildAtIndex(int index)
This operation treats the set of children as if they are randomly accessible and returns the child at the given index if it is between zero and the number of children minus one.
index
- The index at which the desired child can be found.
The child or null if the index is out of bounds.
public TreeComposite getNextSibling()
This operation returns the next or "nearest right" sibling of the TreeComposite. It returns null if there is not a sibling after this one.
The next or "nearest right" sibling in the tree.
public TreeComposite getPreviousSibling()
This operation returns the previous or "nearest left" sibling of the TreeComposite. It returns null if there is not a previous sibling.
The previous or "nearest left" sibling in the tree.
public java.util.ArrayList<Component> getDataNodes()
This operation returns the set of data nodes managed by the TreeComposite or null if no such nodes exist. Data nodes are those nodes which are only Components and not Composites. This includes things such as DataComponent and TableComponent.
The set of Components managed by the TreeComposite.
public int getNumberOfDataNodes()
This operation returns the number of data nodes of this TreeComposite.
public Component getActiveDataNode()
This operation returns the active data node for this TreeComposite or null if the active data node has not been specified if and only if active data nodes are allowed for this TreeComposite.
The active data node or null if it has not been specified.
public void setActiveDataNode(Component node)
This operation sets the active data node for the TreeComposite if and only if active data nodes are allowed for this TreeComposite. If the node is not a member of the set of data nodes, the TreeComposite ignores it and the currently specified data node (or null) remains in place. Calling this operation with a Component that is not a member of the set of data nodes will not add it to the set.
node
- The data node that should be marked as the active data node. If this node is null or not a member of the set of data nodes for this TreeComposite it is ignored.
public void allowActiveDataNodes(boolean allow)
This operation specifies whether or not this TreeComposite will allow clients to specify active data nodes. Support for active nodes may be disabled by calling allowActiveDataNodes(false) and enabled by calling allowActiveDataNodes(true). If this option is set to false, getActiveDataNode() will always return null and setActiveDataNode() will not function. Active data nodes are allowed by default.
allow
- public boolean equals(java.lang.Object otherTreeComposite)
This operation is used to check equality between the TreeComposite and another TreeComposite. It returns true if the TreeComposites are equal and false if they are not. It compares ALL of the nodes of a TreeComposite, child and data nodes alike. It does not compare the parent and sibling references.
equals
in interface Identifiable
equals
in class ICEObject
otherTreeComposite
- The other TreeComposite to which this component should be compared.
True if the TreeComposites are equal, false otherwise.
Identifiable.equals(Object otherObject)
public int hashCode()
This operation returns the hashcode value of the TreeComposite. It does not include the parent and sibling references when computing the hashcode.
hashCode
in interface Identifiable
hashCode
in class ICEObject
The hashcode.
Identifiable.hashCode()
public void copy(TreeComposite otherTreeComposite)
This operation performs a deep copy of the attributes of another TreeComposite into the current TreeComposite. It copies ALL of the children of the TreeComposite, data and child nodes alike.
otherTreeComposite
- The other TreeComposite from which information should be copied.
public void copy(TreeComposite otherTreeComposite, boolean copyInPlace)
This operation performs a deep copy of the attributes of another TreeComposite into the current TreeComposite. It copies ALL of the children of the TreeComposite, data and child nodes alike. This version of the copy method is tailored specifically for instances of TreeComposites that can be "copied in place" in a TreeComposite structure with multiple levels (ie. when copying data into a TreeComposite which isn't the most top-level node, so retaining familial references is crucial for other tasks). If the copyInPlace flag is set to true, parent and sibling references are not set to null, and only children and data is copied over.
otherTreeComposite
- The other TreeComposite from which information should be copied.
copyInPlace
- A boolean flag to indicate if the TreeComposite should be "copied in place" (ie. retain parent and sibling references). Setting this to true will keep all existing wiring in place.
public java.lang.Object clone()
This operation provides a deep copy of the TreeComposite. It clones ALL of the nodes of a TreeComposite, data and child nodes alike.
clone
in interface Identifiable
clone
in class ICEObject
The deep-copy clone of this TreeComposite.
public void setChildExemplars(java.util.ArrayList<TreeComposite> exemplars)
This operation adds a list of TreeComposites that must be used to create children for this TreeComposite. If a list of allowed child nodes exists, a TreeComposite will overwrite it.
exemplars
- The set of exemplar child types ("set of exemplars").
public void addChildExemplar(TreeComposite exemplar)
exemplar
- The child exemplar to be added to the list.public java.util.ArrayList<TreeComposite> getChildExemplars()
This operation retrieves the list of TreeComposites that must be used to create children for this TreeComposite. An individual from this set must be copied (via clone(), for example) and submitted to setNextChild() or addComponent().
The set of exemplar child types ("set of exemplars").
public boolean hasChildExemplars()
This operation returns true if a list of exemplar child node types has been configured and the TreeComposite can only add children of those types and false if the TreeComposite is willing to store any component. TreeComposites are configured to accept all components by default (this operation will return false, that is).
True if the exemplars exist, false otherwise.
public boolean isActive()
This operation indicates if the TreeComposite is active. True if Active, false if not.
True if Active, false if not
public void setActive(boolean flag)
This operation sets specifies whether or not the TreeComposite is active. True for active, false if not.
flag
- True if Active, false if not
public void accept(IComponentVisitor visitor)
accept
in interface Component
visitor
- The visitor
Component.accept(IComponentVisitor visitor)
public void addComponent(Component child)
addComponent
in interface Composite
child
- The Component that should be added to the Composite.
Composite.addComponent(Component child)
public void removeComponent(int childId)
removeComponent
in interface Composite
childId
- The id of the child Component that should be removed from the Composite.
Composite.removeComponent(int childId)
public Component getComponent(int childId)
getComponent
in interface Composite
childId
- The id of the child Component that should be retrieved from the Composite.
The child with id childId that was retrieved from the Composite. NULL if the childId was not found in the Composite.
Composite.getComponent(int childId)
public int getNumberOfComponents()
getNumberOfComponents
in interface Composite
The number of child Components contained in the Composite.
Composite.getNumberOfComponents()
public java.util.ArrayList<Component> getComponents()
getComponents
in interface Composite
The set of Components.
Composite.getComponents()
public void visit(DataComponent component)
visit
in interface IComponentVisitor
component
- DataComponent which was originally called by the accept()
operationIComponentVisitor.visit(DataComponent component)
public void visit(ResourceComponent component)
visit
in interface IComponentVisitor
component
- OutputComponent which was originally called by the accept()
operationIComponentVisitor.visit(ResourceComponent component)
public void visit(TableComponent component)
visit
in interface IComponentVisitor
component
- TableComponent which was originally called by the accept()
operationIComponentVisitor.visit(TableComponent component)
public void visit(MatrixComponent component)
visit
in interface IComponentVisitor
component
- MatrixComponent which was originally called by the accept()
operationIComponentVisitor.visit(MatrixComponent component)
public void visit(IShape component)
visit
in interface IComponentVisitor
component
- IShape which was originally called by the accept() operationIComponentVisitor.visit(IShape component)
public void visit(GeometryComponent component)
visit
in interface IComponentVisitor
component
- GeometryComponent which was originally called by the accept()
operationIComponentVisitor.visit(GeometryComponent component)
public void visit(MasterDetailsComponent component)
visit
in interface IComponentVisitor
component
- MasterDetailsComponent which was originally called by the
accept() operation.IComponentVisitor.visit(MasterDetailsComponent component)
public void visit(TreeComposite component)
visit
in interface IComponentVisitor
component
- The TreeCompositeIComponentVisitor.visit(TreeComposite component)
public void visit(IReactorComponent component)
visit
in interface IComponentVisitor
component
- The IReactorComponentIComponentVisitor.visit(IReactorComponent component)
public void visit(TimeDataComponent component)
IComponentVisitor
visit
in interface IComponentVisitor
component
- The TimeDataComponent.public void visit(MeshComponent component)
visit
in interface IComponentVisitor
component
- The MeshComponent.IComponentVisitor.visit(MeshComponent component)
public void visit(AdaptiveTreeComposite component)
visit
in interface IComponentVisitor
component
- The AdaptiveTreeCompositeIComponentVisitor.visit(AdaptiveTreeComposite component)
public void register(IUpdateableListener listener)
register
in interface IUpdateable
register
in class ICEObject
listener
- The new listener that should be notified when the the Component's state changes.
IUpdateable.register(IUpdateableListener listener)
public void unregister(IUpdateableListener listener)
unregister
in interface IUpdateable
unregister
in class ICEObject
listener
- The listener that should no longer receive updates.
IUpdateable.unregister(IUpdateableListener listener)
public void visit(EMFComponent component)
IComponentVisitor
visit
in interface IComponentVisitor
component
- The EMFComponent.public void visit(ListComponent component)
IComponentVisitor
visit
in interface IComponentVisitor
component
- The ListComponent