org.openide.explorer
Class ExplorerManager

java.lang.Object
  |
  +--org.openide.explorer.ExplorerManager
All Implemented Interfaces:
Cloneable, Serializable

public final class ExplorerManager
extends Object
implements Serializable, Cloneable

Manages a selection and root context for a (set of) Explorer view(s). The views should register their VetoableChangeListeners and PropertyChangeListeners at the ExplorerManager of the Explorer they belong to. The manager listens on changes to the node hierarchy and updates the selection and root node.

Deserialization of this object is done with validation with priority 10. In readObject the ExplorerManager is temporarily initialized with void values. These values are replaced with original ones when the validation proceeds. Deserialization may throw SafeException if the contexts cannot be restored correctly, but the stream is uncorrupted.

See Also:
Serialized Form

Inner Class Summary
static interface ExplorerManager.Provider
          Interface for components wishing to provide their own ExplorerManager.
 
Field Summary
static String PROP_EXPLORED_CONTEXT
          Name of property for the explored context.
static String PROP_NODE_CHANGE
          Name of property for change in a node.
static String PROP_ROOT_CONTEXT
          Name of property for the root context.
static String PROP_SELECTED_NODES
          Name of property for the node selection.
 
Constructor Summary
ExplorerManager()
          Construct a new manager.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Add a PropertyChangeListener to the listener list.
 void addVetoableChangeListener(VetoableChangeListener l)
          Add a VetoableListener to the listener list.
 Object clone()
          Clones the manager.
static ExplorerManager find(Component comp)
          Find the proper Explorer manager for a given component.
 Node getExploredContext()
          Get the explored context.
 Node getRootContext()
          Get the root context.
 Node[] getSelectedNodes()
          Get the set of selected nodes.
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a PropertyChangeListener from the listener list.
 void removeVetoableChangeListener(VetoableChangeListener l)
          Remove a VetoableChangeListener from the listener list.
 void setExploredContext(Node value)
          Set the explored context.
 void setExploredContext(Node value, Node[] selection)
          Set the explored context.
 void setExploredContextAndSelection(Node value, Node[] selection)
          Set the explored context and selected nodes.
 void setRootContext(Node value)
          Set the root context.
 void setSelectedNodes(Node[] value)
          Set the set of selected nodes.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_ROOT_CONTEXT

public static final String PROP_ROOT_CONTEXT
Name of property for the root context.

PROP_EXPLORED_CONTEXT

public static final String PROP_EXPLORED_CONTEXT
Name of property for the explored context.

PROP_SELECTED_NODES

public static final String PROP_SELECTED_NODES
Name of property for the node selection.

PROP_NODE_CHANGE

public static final String PROP_NODE_CHANGE
Name of property for change in a node.
Constructor Detail

ExplorerManager

public ExplorerManager()
Construct a new manager.
Method Detail

clone

public Object clone()
Clones the manager.
Overrides:
clone in class Object
Returns:
manager with the same settings like this one

getSelectedNodes

public Node[] getSelectedNodes()
Get the set of selected nodes.
Returns:
the selected nodes; empty (not null) if none are selected

setSelectedNodes

public final void setSelectedNodes(Node[] value)
                            throws PropertyVetoException
Set the set of selected nodes.
Parameters:
value - the nodes to select; empty (not null) if none are to be selected
Throws:
PropertyVetoException - when the given nodes cannot be selected
IllegalArgumentException - if null is given, or if any elements of the selection are not within the current root context

getExploredContext

public final Node getExploredContext()
Get the explored context.

The "explored context" is not as frequently used as the node selection; generally it refers to a parent node which contains all of the things being displayed at this moment. For BeanTreeView this is irrelevant, but ContextTreeView uses it (in lieu of the node selection) and for IconView it is important (the node whose children are visible, i.e. the "background" of the icon view).

Returns:
the node being explored, or null

setExploredContext

public final void setExploredContext(Node value)
Set the explored context. The node selection will be cleared as well.
Parameters:
value - the new node to explore, or null if none should be explored.
Throws:
IllegalArgumentException - if the node is not within the current root context in the node hierarchy

setExploredContext

public final void setExploredContext(Node value,
                                     Node[] selection)
Set the explored context. The node selection will be changed as well. Note: node selection cannot be vetoed if calling this method. It is generally better to call setExploredContextAndSelection.
Parameters:
value - the new node to explore, or null if none should be explored.
Throws:
IllegalArgumentException - if the node is not within the current root context in the node hierarchy

setExploredContextAndSelection

public final void setExploredContextAndSelection(Node value,
                                                 Node[] selection)
                                          throws PropertyVetoException
Set the explored context and selected nodes. If the change in selected nodes is vetoed, PropertyVetoException is rethrown from here.
Parameters:
value - the new node to explore, or null if none should be explored.
selection - the new nodes to be selected
Throws:
IllegalArgumentException - if the node is not within the current root context in the node hierarchy
PropertyVetoExcepion - if listeners attached to this explorer manager do so

getRootContext

public final Node getRootContext()
Get the root context.

The "root context" is simply the topmost node that this explorer can display or manipulate. For BeanTreeView, this would mean the root node of the tree. For e.g. IconView, this would mean the uppermost possible node that that icon view could display; while the explored context would change at user prompting via the up button and clicking on subfolders, the root context would be fixed by the code displaying the explorer.

Returns:
the root context node

setRootContext

public final void setRootContext(Node value)
Set the root context. The explored context will be set to the new root context as well. If any of the selected nodes are not inside it, the selection will be cleared.
Parameters:
value - the new node to serve as a root
IllegalArgumentException - if it is null

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Add a PropertyChangeListener to the listener list.
Parameters:
l - the listener to add

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove a PropertyChangeListener from the listener list.
Parameters:
l - the listener to remove

addVetoableChangeListener

public void addVetoableChangeListener(VetoableChangeListener l)
Add a VetoableListener to the listener list.
Parameters:
l - the listener to add

removeVetoableChangeListener

public void removeVetoableChangeListener(VetoableChangeListener l)
Remove a VetoableChangeListener from the listener list.
Parameters:
l - the listener to remove

find

public static ExplorerManager find(Component comp)
Find the proper Explorer manager for a given component. This is done by traversing the component hierarchy and finding the first ancestor that implements ExplorerManager.Provider.

This method should be used in Component.addNotify() of each component that works with the Explorer manager, e.g.:

 private transient ExplorerManager explorer;
 
 public void addNotify () {
   super.addNotify ();
   explorer = ExplorerManager.find (this);
 }
 
Parameters:
comp - component to find the manager for
Returns:
the manager, or a new empty manager if no ancestor implements Provider
See Also:
ExplorerManager.Provider


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.