public final class ExplorerManager extends Object implements Serializable, Cloneable
VetoableChangeListener
s and
PropertyChangeListener
s at the
ExplorerManager
of the Explorer they belong to
(usually found in AWT hierarchy using ExplorerManager.find(java.awt.Component)
.
The manager is then the mediator that keeps the shared state,
notifies PropertyChangeListener
s and VetoableChangeListener
s
about changes and allows views to call its setter methods to incluence
the root of the visible hierarchy using ExplorerManager.setRootContext(org.openide.nodes.Node)
, the
set of selected nodes using ExplorerManager.setSelectedNodes(org.openide.nodes.Node[])
and also the
explored context (useful for ListView
for
example) using ExplorerManager.setExploredContext(org.openide.nodes.Node)
.
This class interacts with Swing components in the
org.openide.explorer.view
package and as such it shall be
used according to Swing threading model.
To provide an ExplorerManager
from your component just let your
component implement ExplorerManager.Provider
as described at ExplorerUtils
.
Deserialization may throw SafeException
if the contexts cannot be
restored correctly, but the stream is uncorrupted.
ExplorerUtils
,
TreeView
,
ListView
,
Serialized FormModifier and Type | Class and Description |
---|---|
static interface |
ExplorerManager.Provider
Interface for components wishing to provide their own
ExplorerManager . |
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
ExplorerManager()
Construct a new manager.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener l)
Add a
PropertyChangeListener to the listener list. |
void |
addVetoableChangeListener(VetoableChangeListener l)
Add a
VetoableListener to the listener list. |
ExplorerManager |
clone()
Clones the manager.
|
static ExplorerManager |
find(Component comp)
Finds 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.
|
public static final String PROP_ROOT_CONTEXT
public static final String PROP_EXPLORED_CONTEXT
public static final String PROP_SELECTED_NODES
public static final String PROP_NODE_CHANGE
public ExplorerManager clone()
public Node[] getSelectedNodes()
null
) if none are selectedpublic final void setSelectedNodes(Node[] value) throws PropertyVetoException
value
- the nodes to select; empty (not null
) if none are to be selectedPropertyVetoException
- when the given nodes cannot be selectedIllegalArgumentException
- if null
is given (array or any element in array)public final Node getExploredContext()
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).
null
public final void setExploredContext(Node value)
value
- the new node to explore, or null
if none should be explored.IllegalArgumentException
- if the node is not within the current root context in the node hierarchypublic final void setExploredContext(Node value, Node[] selection)
value
- the new node to explore, or null
if none should be explored.IllegalArgumentException
- if the node is not within the current root context in the node hierarchypublic final void setExploredContextAndSelection(Node value, Node[] selection) throws PropertyVetoException
value
- the new node to explore, or null
if none should be explored.selection
- the new nodes to be selectedIllegalArgumentException
- if the node is not within the current root context in the node hierarchyPropertyVetoException
- if listeners attached to this explorer manager do sopublic final Node getRootContext()
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.
public final void setRootContext(Node value)
value
- the new node to serve as a rootIllegalArgumentException
- if it is null
public void addPropertyChangeListener(PropertyChangeListener l)
PropertyChangeListener
to the listener list.l
- the listener to addpublic void removePropertyChangeListener(PropertyChangeListener l)
PropertyChangeListener
from the listener list.l
- the listener to removepublic void addVetoableChangeListener(VetoableChangeListener l)
VetoableListener
to the listener list.l
- the listener to addpublic void removeVetoableChangeListener(VetoableChangeListener l)
VetoableChangeListener
from the listener list.l
- the listener to removepublic static ExplorerManager find(Component comp)
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); }
comp
- component to find the manager forProvider
ExplorerManager.Provider