org.openide.nodes
Class Children.Keys

java.lang.Object
  extended byorg.openide.nodes.Children
      extended byorg.openide.nodes.Children.Array
          extended byorg.openide.nodes.Children.Keys
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
BeanChildren, FilterNode.Children, Index.KeysChildren
Enclosing class:
Children

public abstract static class Children.Keys
extends Children.Array

Implements an array of child nodes associated nonuniquely with keys and sorted by these keys. There is a method that should for each key create an array of nodes that represents the key.

Typical usage:

  1. Subclass.
  2. Decide what type your key should be.
  3. Implement createNodes(java.lang.Object) to create some nodes (usually exactly one) per key.
  4. Override Children.addNotify() to compute a set of keys and set it using setKeys(Collection). The collection may be ordered.
  5. Override Children.removeNotify() to just call setKeys on Collections.EMPTY_SET.
  6. When your model changes, call setKeys with the new set of keys. Children.Keys will be smart and calculate exactly what it needs to do effficiently.
  7. (Optional) if your notion of what the node for a given key changes (but the key stays the same), you can call refreshKey(java.lang.Object). Usually this is not necessary.


Nested Class Summary
 
Nested classes inherited from class org.openide.nodes.Children
Children.Array, Children.Keys, Children.Map, Children.SortedArray, Children.SortedMap
 
Field Summary
 
Fields inherited from class org.openide.nodes.Children.Array
nodes
 
Fields inherited from class org.openide.nodes.Children
LEAF, MUTEX
 
Constructor Summary
Children.Keys()
           
 
Method Summary
 boolean add(Node[] arr)
          Add nodes this container.
 Object clone()
          Special handling for clonning.
protected abstract  Node[] createNodes(Object key)
          Create nodes for a given key.
protected  void destroyNodes(Node[] arr)
          Called when the nodes have been removed from the children.
protected  void refreshKey(Object key)
          Refresh the child nodes for a given key.
 boolean remove(Node[] arr)
          Remove nodes from the list.
protected  void setBefore(boolean b)
          Set whether new nodes should be added to the beginning or end of sublists for a given key.
protected  void setKeys(Collection keysSet)
          Set new keys for this children object.
protected  void setKeys(Object[] keys)
          Set keys for this list.
 
Methods inherited from class org.openide.nodes.Children.Array
initCollection, refresh
 
Methods inherited from class org.openide.nodes.Children
addNotify, findChild, getNode, getNodes, getNodes, getNodesCount, isInitialized, nodes, removeNotify
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Children.Keys

public Children.Keys()
Method Detail

clone

public Object clone()
Special handling for clonning.

Overrides:
clone in class Children.Array
Returns:
the cloned array for this children

add

public boolean add(Node[] arr)
Description copied from class: Children
Add nodes this container. The parent node of these nodes is changed to the parent node of this list. Each node can be added only once. If there is some reason a node cannot be added, for example if the node expects only a special type of subnodes, the method should do nothing and return false to signal that the addition has not been successful.

This method should be implemented by subclasses to filter some nodes, etc.

Overrides:
add in class Children.Array

remove

public boolean remove(Node[] arr)
Description copied from class: Children
Remove nodes from the list. Only nodes that are present are removed.

Overrides:
remove in class Children.Array

refreshKey

protected final void refreshKey(Object key)
Refresh the child nodes for a given key.

Parameters:
key - the key to refresh

setKeys

protected final void setKeys(Collection keysSet)
Set new keys for this children object. Setting of keys does not necessarily lead to the creation of nodes. It happens only when the list has already been initialized.

Parameters:
keysSet - the keys for the nodes (collection of any objects)

setKeys

protected final void setKeys(Object[] keys)
Set keys for this list.

Parameters:
keys - the keys for the nodes
See Also:
setKeys(Collection)

setBefore

protected final void setBefore(boolean b)
Set whether new nodes should be added to the beginning or end of sublists for a given key.

Parameters:
b - true if the children should be added before

createNodes

protected abstract Node[] createNodes(Object key)
Create nodes for a given key.

Parameters:
key - the key
Returns:
child nodes for this key or null if there should be no nodes for this key

destroyNodes

protected void destroyNodes(Node[] arr)
Called when the nodes have been removed from the children. This method should allow subclasses to clean the nodes somehow.

Current implementation notifies all listeners on the nodes that nodes have been deleted.

Parameters:
arr - array of deleted nodes

 

Built on May 3 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.