intarsys runtime library

de.intarsys.tools.tree
Class CommonNode<T>

java.lang.Object
  extended by de.intarsys.tools.tree.CommonNode<T>
Type Parameters:
T - The type of the wrapped POJO
All Implemented Interfaces:
IAttributeSupport, INotificationSupport, IPresentationSupport
Direct Known Subclasses:
NoneNode, PropertiesNode, PropertyNode

public abstract class CommonNode<T>
extends Object
implements IPresentationSupport, INotificationSupport, IAttributeSupport

A common implementation for a node in a tree. This node wraps a POJO for use in presentation or other contexts.

The node factory acts as the "role" in which the POJO wants to be wrapped or seen. This allows a POJO to be seen differently in different usage contexts by simply using another factory (role).

There are two main usage scenarios:

Implement a concrete CommonNode and CommonNodeFactory subclass to determine node behavior. This results in quick and easy to understand solution. The drawback is the static behavior - if you want to change some implementation detail down the hierarchy level you have to create subclasses according to this change up to the root level to ensure the changed leaf node factory is used.

The second scenario involves a callback to a strategy object INodeHandler where the node behavior is encapsulated. This allows for a more generic node implementation with the drawback of a "instanceof" style of coding in the callback handler.


Field Summary
 
Fields inherited from interface de.intarsys.tools.presentation.IPresentationSupport
ATTR_DESCRIPTION, ATTR_ICON, ATTR_LABEL, ATTR_TIP
 
Method Summary
 void addNotificationListener(EventType type, INotificationListener listener)
          Add listener to the collection of objects to be informed when the receiver triggers an event of type name.
 Object getAttribute(Object key)
          Get an attribute value from the context
 CommonNode<?>[] getChildren()
          Return all child nodes of this.
 String getDescription()
          A long, descriptive string representation.
 String getIconName()
          A name for an icon.
 String getLabel()
          A short string representation (suitable for example for use with an icon or menu item).
static CommonNode<?> getNode(CommonNode<?> parent, CommonNodeFactory<?> role, Object object)
          Return the node associated with object.
 INodeHandler getNodeHandler()
           
 T getObject()
          The object represented by this node.
 CommonNode<?> getParent()
          The optional parent node.
 String getTip()
          An "intermediate" length description (suitable for example with a tooltip).
 boolean hasChildren()
          true if this node has children.
 Object removeAttribute(Object key)
          Remove an attribute binding in the context
 void removeNotificationListener(EventType type, INotificationListener listener)
          Remove listener from the collection of objects to be informed about events of type name.
 Object setAttribute(Object key, Object value)
          Set the value of an attribute in the context
 void setNodeHandler(INodeHandler nodeHandler)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNode

public static CommonNode<?> getNode(CommonNode<?> parent,
                                    CommonNodeFactory<?> role,
                                    Object object)
Return the node associated with object. If no such node exists it will be created as a child of parent.

The strategy of associating an object o a node is up to the factory.

Parameters:
parent -
role -
object -
Returns:
Return the UNIQUE node associated with object.

addNotificationListener

public void addNotificationListener(EventType type,
                                    INotificationListener listener)
Description copied from interface: INotificationSupport
Add listener to the collection of objects to be informed when the receiver triggers an event of type name.

Specified by:
addNotificationListener in interface INotificationSupport
Parameters:
type - The event type we are interested in.
listener - The object to be informed about an event occurrence

getAttribute

public Object getAttribute(Object key)
Description copied from interface: IAttributeSupport
Get an attribute value from the context

Specified by:
getAttribute in interface IAttributeSupport
Parameters:
key - the name of the attribute to get
Returns:
The value of the attribute key

getChildren

public CommonNode<?>[] getChildren()
Return all child nodes of this.

Returns:
Return all child nodes of this.

getDescription

public String getDescription()
Description copied from interface: IPresentationSupport
A long, descriptive string representation.

Specified by:
getDescription in interface IPresentationSupport
Returns:
A long, descriptive string representation.

getIconName

public String getIconName()
Description copied from interface: IPresentationSupport
A name for an icon.

Specified by:
getIconName in interface IPresentationSupport
Returns:
A name for an icon.

getLabel

public String getLabel()
Description copied from interface: IPresentationSupport
A short string representation (suitable for example for use with an icon or menu item).

Specified by:
getLabel in interface IPresentationSupport
Returns:
A short string representation (suitable for example for use with an icon or menu item).

getNodeHandler

public INodeHandler getNodeHandler()

getObject

public T getObject()
The object represented by this node.

Returns:
The object represented by this node.

getParent

public CommonNode<?> getParent()
The optional parent node.

Returns:
The optional parent node.

getTip

public String getTip()
Description copied from interface: IPresentationSupport
An "intermediate" length description (suitable for example with a tooltip).

Specified by:
getTip in interface IPresentationSupport
Returns:
An "intermediate" length description (suitable for example with a tooltip).

hasChildren

public boolean hasChildren()
true if this node has children.

Returns:
true if this node has children.

removeAttribute

public Object removeAttribute(Object key)
Description copied from interface: IAttributeSupport
Remove an attribute binding in the context

Specified by:
removeAttribute in interface IAttributeSupport
Parameters:
key - the name of the attribute to remove
Returns:
The previously associated value for key

removeNotificationListener

public void removeNotificationListener(EventType type,
                                       INotificationListener listener)
Description copied from interface: INotificationSupport
Remove listener from the collection of objects to be informed about events of type name.

Specified by:
removeNotificationListener in interface INotificationSupport
Parameters:
type - The event type we are no longer interested in.
listener - The object registered for the event till now.

setAttribute

public Object setAttribute(Object key,
                           Object value)
Description copied from interface: IAttributeSupport
Set the value of an attribute in the context

Specified by:
setAttribute in interface IAttributeSupport
Parameters:
key - the name of the attribute to set
value - the new value the attribute
Returns:
The previously associated value for key

setNodeHandler

public void setNodeHandler(INodeHandler nodeHandler)

intarsys runtime library

Copyright © 2012 intarsys consulting GmbH. All Rights Reserved.