org.iids.aos.gui.structs
Class Struct

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by org.iids.aos.gui.structs.Struct
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode
Direct Known Subclasses:
Agent, Host, HostService, Location, Root, World

public abstract class Struct
extends javax.swing.tree.DefaultMutableTreeNode
implements java.lang.Comparable, java.io.Serializable

Parent object for all structs. These form a tree which is doubly linked and can be searched for name occurrences of children. Allows for removal of subtrees. Cleanup operations can be supplied in the respective struct implementation class.

A ServiceWrapper can be linked to a struct. This way a Struct and a service can be associated with each other. This is especially useful for services because now they automatically become part of the tree structure.

This is the abstract super class of all struct implementations. To implement a struct it is required to implement the functions refreshImpl() and getChildClass().

Author:
rjtimmer
See Also:
Serialized Form

Field Summary
protected  java.util.List<Struct> children
           
protected  java.lang.String name
           
protected  Struct parent
           
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, EMPTY_ENUMERATION, userObject
 
Constructor Summary
Struct(java.lang.String name)
          Creates a named orphan Struct (no parent, no children)
Struct(java.lang.String name, Struct parent, ServiceWrapper sw)
          Creates a named struct with a parent and a service wrapper.
 
Method Summary
<T extends Struct>
void
addChild(T child)
          Add a child to this Struct.
 boolean allowsChildren()
           
 boolean automaticChildShutdown()
          Indicates whether children are automatically shut down whenever the parent structure shuts down.
 java.util.Enumeration children()
           
 int compareTo(java.lang.Object o)
           
 boolean contains(java.lang.String name)
           
 boolean equals(java.lang.Object o)
          See if this struct equals a certain struct.
 java.util.List<Struct> find(java.lang.String name)
           
 java.util.List<Struct> find(java.lang.String name, java.util.List<Struct> result)
          Search recursively through descendants for a name containing the String find.
 Struct findChild(java.lang.String name)
          Find structs non recursively.
 Struct findStructByPath(java.lang.String path)
           
 Struct findStructByQueue(java.util.Queue<java.lang.String> names)
           
 boolean getAllowsChildren()
           
 java.lang.String getCanonicalPath()
           
 javax.swing.tree.TreeNode getChildAt(int index)
           
abstract  java.lang.Class<? extends Struct> getChildClass()
          Returns the allowed Class type for child nodes.
 int getChildCount()
           
 java.util.List<Struct> getChildren()
          Get a list of all children of this Struct.
 Host getHost()
           
 int getIndex(javax.swing.tree.TreeNode node)
           
 Location getLocation()
           
 java.lang.String getName()
           
 Struct getParent()
          Obtain parent Struct.
 Root getRoot()
           
 ServiceWrapper getService()
           
 java.util.List<Struct> getSiblings()
           
 javax.swing.tree.TreePath getTreePath()
          Obtain the tree path for a certain struct in the tree.
 World getWorld()
           
 boolean hasLocalService()
           
 boolean hasRemoteService()
           
 boolean isExpanded()
           
 boolean isLeaf()
           
 boolean isShuttingDown()
           
 boolean refresh()
          The refresh method queries all of the services below for a refresh.
 boolean refresh(boolean newNode)
          Refresh service info from this struct instance.
protected abstract  boolean refreshImpl()
          Refresh implementation.
 void removeChild(Struct child)
          Remove a child from this Struct.
 void setExpanded(boolean expanded)
           
 void setName(java.lang.String name)
          Changed name for this Struct.
 void setParent(Struct parent)
          Set the parent struct for this Struct.
 void setReadOnly()
          Set struct to readonly.
 void setService(ServiceWrapper service)
           
 void shutdown()
          Delete the struct and shut down its associated service (if any).
 boolean subtreeHasLocalService()
           
 boolean subtreeIsRefreshing()
          A method that can be used to find out whether a subtree of this tree is (at this moment) executing its refresh() method.
 java.lang.String toString()
           
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, clone, depthFirstEnumeration, getChildAfter, getChildBefore, getDepth, getFirstChild, getFirstLeaf, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

parent

protected Struct parent

children

protected java.util.List<Struct> children
Constructor Detail

Struct

public Struct(java.lang.String name)
Creates a named orphan Struct (no parent, no children)


Struct

public Struct(java.lang.String name,
              Struct parent,
              ServiceWrapper sw)
Creates a named struct with a parent and a service wrapper. Both may be null in case they do not exist. This is useful for importing existing services into a tree (for example, services that are referenced from remote locations).

Parameters:
parent - Structs organize themselves in a tree structure. Changes are propagated to the parent structures (if any), searches may descend down to children structures etc. If parent is not null then this struct is automatically registered with the parent and vice-versa (doubly linked tree).
sw - The ServiceWrapper associated with this struct. The wrapper will be associated with this struct, and this struct will also be associated with sw. This way, the corresponding struct can always be obtained from the service and vice-versa.
Method Detail

getChildClass

public abstract java.lang.Class<? extends Struct> getChildClass()
Returns the allowed Class type for child nodes. Atttempting to operate the tree with different child nodes may result in an exception (for example @link #addChild).


setReadOnly

public void setReadOnly()
Set struct to readonly. This cannot be reverted.


getName

public java.lang.String getName()
Returns:
The name for this Struct.

setName

public void setName(java.lang.String name)
Changed name for this Struct.


getParent

public Struct getParent()
Obtain parent Struct.

Specified by:
getParent in interface javax.swing.tree.TreeNode
Overrides:
getParent in class javax.swing.tree.DefaultMutableTreeNode
Returns:
null if there is no parent.

setParent

public void setParent(Struct parent)
Set the parent struct for this Struct.


addChild

public <T extends Struct> void addChild(T child)
Add a child to this Struct.


removeChild

public void removeChild(Struct child)
Remove a child from this Struct. Not affected by readonly option.


shutdown

public final void shutdown()
Delete the struct and shut down its associated service (if any). This also affects the child nodes, so these get all deleted as well.

The shutdown order is children-first, ie. a Location first shuts down its corresponding children (Hosts, which control the host managers) and then it shuts down its own service (location manager) etc.


automaticChildShutdown

public boolean automaticChildShutdown()
Indicates whether children are automatically shut down whenever the parent structure shuts down. If the shutdown is automatically done, then we do not need to perform an explicit shutdown. For example, shutting down an agent server also shuts down any hosted agents, so it is not really required to explicitly shut down all children..

Currently unused (e.g. returns false: always do explicit shutdown).


isShuttingDown

public boolean isShuttingDown()

getChildren

public java.util.List<Struct> getChildren()
Get a list of all children of this Struct.


getSiblings

public java.util.List<Struct> getSiblings()

find

public java.util.List<Struct> find(java.lang.String name,
                                   java.util.List<Struct> result)
Search recursively through descendants for a name containing the String find. A list with all the nodes that match the criteria is returned.


find

public java.util.List<Struct> find(java.lang.String name)

contains

public boolean contains(java.lang.String name)

findChild

public Struct findChild(java.lang.String name)
Find structs non recursively. There should only be a single child (at most) that has this name. If there are more (I do not think this should happen?) then the first child to match the criteria is returned.

TODO if there can be more children, then return a list??

Returns:
null if there is no such struct, otherwise return the matching struct

getTreePath

public javax.swing.tree.TreePath getTreePath()
Obtain the tree path for a certain struct in the tree. Returns a list (starting at the root) containing all the parent nodes of the list.


getCanonicalPath

public final java.lang.String getCanonicalPath()

findStructByPath

public Struct findStructByPath(java.lang.String path)

findStructByQueue

public Struct findStructByQueue(java.util.Queue<java.lang.String> names)

equals

public boolean equals(java.lang.Object o)
See if this struct equals a certain struct. Only compares name and type (??) but not parent struct? TODO should just compare references??

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Overrides:
toString in class javax.swing.tree.DefaultMutableTreeNode

children

public java.util.Enumeration children()
Specified by:
children in interface javax.swing.tree.TreeNode
Overrides:
children in class javax.swing.tree.DefaultMutableTreeNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface javax.swing.tree.TreeNode
Overrides:
isLeaf in class javax.swing.tree.DefaultMutableTreeNode

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface javax.swing.tree.TreeNode
Overrides:
getChildCount in class javax.swing.tree.DefaultMutableTreeNode

getChildAt

public javax.swing.tree.TreeNode getChildAt(int index)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode
Overrides:
getChildAt in class javax.swing.tree.DefaultMutableTreeNode

getIndex

public int getIndex(javax.swing.tree.TreeNode node)
Specified by:
getIndex in interface javax.swing.tree.TreeNode
Overrides:
getIndex in class javax.swing.tree.DefaultMutableTreeNode

getAllowsChildren

public boolean getAllowsChildren()
Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode
Overrides:
getAllowsChildren in class javax.swing.tree.DefaultMutableTreeNode

allowsChildren

public boolean allowsChildren()

getService

public ServiceWrapper getService()

setService

public void setService(ServiceWrapper service)

isExpanded

public boolean isExpanded()

setExpanded

public void setExpanded(boolean expanded)

getHost

public Host getHost()

getLocation

public Location getLocation()

getWorld

public World getWorld()

getRoot

public Root getRoot()
Overrides:
getRoot in class javax.swing.tree.DefaultMutableTreeNode

refresh

public final boolean refresh()
The refresh method queries all of the services below for a refresh. If nodes are added, then these changes are automatically propagated to the registered tree views.

This (probably) only handles changes to remote locations/hosts. If a remote service (like a location) is added in the lookup service, then we request the AgentScapeLite class to bind the new service for us.

Binding via AgentScapeLite also creates the respective Structs. Whenever a new struct is created, the changes are automatically propagated to the model view.

Easy, no?? ;-) This is the theory. Minus any bugs the refreshing of the GUI should happen almost automatically :-)


refresh

public final boolean refresh(boolean newNode)
Refresh service info from this struct instance. Does not descend down the tree to do refreshes of


subtreeIsRefreshing

public final boolean subtreeIsRefreshing()
A method that can be used to find out whether a subtree of this tree is (at this moment) executing its refresh() method.

We do not need to revalidate the tree (thus, no multiple updates) so that the tree is only revalidated once the tree is done updating.


subtreeHasLocalService

public final boolean subtreeHasLocalService()

hasRemoteService

public boolean hasRemoteService()

hasLocalService

public boolean hasLocalService()

refreshImpl

protected abstract boolean refreshImpl()
Refresh implementation. Called from the recursive refresh implementation in refresh(). This makes sure that no duplicate refresh operations are performed (??? is this still needed ??? XXX).

Returns:
true if the tree structure was changed, false otherwise.


Copyright © 2003, 2004 IIDS Group. All Rights Reserved.