qflib 0.98.1

de.qfs.lib.gui
Class TreeNotification

java.lang.Object
  |
  +--de.qfs.lib.gui.TreeNotification

public class TreeNotification
extends java.lang.Object

A TreeNotification supports a mechanism similar to TreeEvents, but with a different philosophy.

Often a user has access to a TreeNode that has changed in some way, but doesn't know anything about the TreeModel or the affected tree. Similarly, the node itself might like to notify its model of some change, but it may not be wise to have every node in the tree know about its model.

In a typical tree structure a node knows its parent though, so a notification mechanism can be implemented by passing the notification up through the hierarchy to the root node, which must decide what to do with it. As a side effect the path to the affected node can be constructed on the way.

This is especially useful when there is a large hierarchy which is displayed in several trees, possibly rooted at different nodes. In this case, structural changes have to be forwarded to all relevant tree models, which may reside in totally unrelated places. Instead of having a central logic that registers all of the models, it suffices if the root nodes of the models know to which model they belong and forward the notification to them.

Things get more difficult when the type of the notification is visual rather than structural, e.g. a node should be selected and made visible. In this case typically only one tree is the designated recipient of the notification. Having a root node know about its tree view would violate the Model/View pattern as implemented by TreeModel/JTree anyway.

One possible solution is to carry the intended receiver of the notification in the notification itself. A root node can then check, if the receiver is a tree to which the node belongs and act accordingly.

Version:
$Revision: 1.8 $
Author:
Gregor Schmid

Field Summary
static int ADD_TO_SELECTION
          Indicates that a node should be selected
static int COLLAPSE
          Indicates that a node should be collapsed
static int EXPAND
          Indicates that a node should be expanded
static int INSERTED
          Indicates that a node has been inserted
static int MODIFIED
          Indicates that a node has been modified
static int REMOVED
          Indicates that a node has been removed
static int SELECT
          Indicates that a node should be selected
static int SELECT_AND_SHOW
          Indicates that a node should be selected and shown
static int SHOW
          Indicates that a node should be made visible
static int STRUCTURE_CHANGED
          Indicates that the node structure has changed
 
Constructor Summary
TreeNotification(int operation, int index)
          Create a new TreeNotification.
TreeNotification(java.lang.Object receiver, int operation, int index)
          Create a new TreeNotification.
 
Method Summary
 int getIndex()
          Get the index of the TreeNotification.
 int getOperation()
          Get the operation of the TreeNotification.
 java.lang.Object[] getPath()
          Get the path of the TreeNotification.
 java.lang.Object getReceiver()
          Get the designated receiver of the TreeNotification.
 void prependNode(java.lang.Object node)
          Prepend a node to the path for the TreeNotification.
 void setIndex(int index)
          Set the index of the TreeNotification.
 void setOperation(int operation)
          Set the operation of the TreeNotification.
 void setPath(java.lang.Object[] path)
          Set the path of the TreeNotification.
 void setReceiver(java.lang.Object receiver)
          Set the designated receiver of the TreeNotification.
 java.lang.String toString()
          Get a string representation of the TreeNotification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODIFIED

public static final int MODIFIED
Indicates that a node has been modified

INSERTED

public static final int INSERTED
Indicates that a node has been inserted

REMOVED

public static final int REMOVED
Indicates that a node has been removed

STRUCTURE_CHANGED

public static final int STRUCTURE_CHANGED
Indicates that the node structure has changed

ADD_TO_SELECTION

public static final int ADD_TO_SELECTION
Indicates that a node should be selected

SELECT

public static final int SELECT
Indicates that a node should be selected

SHOW

public static final int SHOW
Indicates that a node should be made visible

SELECT_AND_SHOW

public static final int SELECT_AND_SHOW
Indicates that a node should be selected and shown

EXPAND

public static final int EXPAND
Indicates that a node should be expanded

COLLAPSE

public static final int COLLAPSE
Indicates that a node should be collapsed
Constructor Detail

TreeNotification

public TreeNotification(int operation,
                        int index)
Create a new TreeNotification.
Parameters:
operation - The type of the notification.
index - An optional index for INSERTED or REMOVED changes.

TreeNotification

public TreeNotification(java.lang.Object receiver,
                        int operation,
                        int index)
Create a new TreeNotification.
Parameters:
receiver - The designated receiver of the notification.
operation - The type of the notification.
index - An optional index for INSERTED or REMOVED changes.
Method Detail

prependNode

public void prependNode(java.lang.Object node)
Prepend a node to the path for the TreeNotification.
Parameters:
node - The node to prepend.

getReceiver

public final java.lang.Object getReceiver()
Get the designated receiver of the TreeNotification.
Returns:
The receiver of the TreeNotification.

setReceiver

public final void setReceiver(java.lang.Object receiver)
Set the designated receiver of the TreeNotification.
Parameters:
receiver - The receiver to set.

getPath

public final java.lang.Object[] getPath()
Get the path of the TreeNotification.
Returns:
The path of the TreeNotification.

setPath

public final void setPath(java.lang.Object[] path)
Set the path of the TreeNotification.
Parameters:
path - The path to set.

getOperation

public final int getOperation()
Get the operation of the TreeNotification.
Returns:
The operation of the TreeNotification.

setOperation

public final void setOperation(int operation)
Set the operation of the TreeNotification.
Parameters:
operation - The operation to set.

getIndex

public final int getIndex()
Get the index of the TreeNotification.
Returns:
The index of the TreeNotification.

setIndex

public final void setIndex(int index)
Set the index of the TreeNotification.
Parameters:
index - The index to set.

toString

public java.lang.String toString()
Get a string representation of the TreeNotification.
Overrides:
toString in class java.lang.Object
Returns:
The string representation.

qflib 0.98.1