|
qflib 0.98.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.qfs.lib.gui.TreeNotification
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.
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 |
public static final int MODIFIED
public static final int INSERTED
public static final int REMOVED
public static final int STRUCTURE_CHANGED
public static final int ADD_TO_SELECTION
public static final int SELECT
public static final int SHOW
public static final int SELECT_AND_SHOW
public static final int EXPAND
public static final int COLLAPSE
Constructor Detail |
public TreeNotification(int operation, int index)
operation
- The type of the notification.index
- An optional index for INSERTED or REMOVED
changes.public TreeNotification(java.lang.Object receiver, int operation, int index)
receiver
- The designated receiver of the notification.operation
- The type of the notification.index
- An optional index for INSERTED or REMOVED
changes.Method Detail |
public void prependNode(java.lang.Object node)
node
- The node to prepend.public final java.lang.Object getReceiver()
public final void setReceiver(java.lang.Object receiver)
receiver
- The receiver to set.public final java.lang.Object[] getPath()
public final void setPath(java.lang.Object[] path)
path
- The path to set.public final int getOperation()
public final void setOperation(int operation)
operation
- The operation to set.public final int getIndex()
public final void setIndex(int index)
index
- The index to set.public java.lang.String toString()
toString
in class java.lang.Object
|
qflib 0.98.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |