-
Notifications
You must be signed in to change notification settings - Fork 1
DevFaqTrackingExplorerSelections
How should I keep track of what the current nodeselection in the Explorer window is? Should I use the ExplorerManager
?
You can use the ExplorerManager
if you created the explorer window, or you can programmatically get a reference to it. If you can somehow find a class implementing ExplorerManager.Provider
then you can get the Explorer manager. This provider might in fact be a TopComponent
in the TopComponent.Registry
, if for example it was actually a ExplorerPanel
.
But this is bad style - for example, if someone wrote a TopComponent
that included a component implementing ExplorerManager.Provider
, but as a subcomponent, and manually managed the node selection, this trick would fail.
Rather, if you know which top component you care about, you can just call TopComponent.getActivatedNodes()
and this will work correctly even for non-Explorer components with a node selection, such as Editor panes open on Java sources.
Better still is to be agnostic about which top component should be providing the activated nodes, and just listen to changes in the TopComponent.Registry.PROP''ACTIVATED''NODES
(or TopComponent.Registry.PROP_CURRENT_NODES
as appropriate).
But best of all is not to have to ever directly pay attention to
the node selection. If you only need to know the node selection in
order to make some user action enabled or not, you should simply
extend NodeAction
;
this class does all the dirty work for you of listening to changes
in the node selection and updating its state automatically.
If you just want to write some code that is sensitive to the global selection (not an action), you probably want to use Utilities.actionsGlobalContext().
If you allow multiple nodes to be selected you also have to keep in mind that certain other Netbeans components may only operate on single nodes.
One example is the Navigator. Let’s suppose you have a navigator window associated with your selected node. What you will notice is that while your multiple selection is in focus, your code for acquiring the selected nodes returns all the selected nodes. If the focus is then switched to the Navigator window, only one node is retrieved, all that while the multiple selection is still there, in the un-focused window.
The reason is because along with the focus change, the (single) node represented by the Navigator and stored in its lookup becomes the global selection which your retrieval code will then grab.
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqTrackingExplorerSelections , that was last modified by NetBeans user Admin on 2009-11-06T16:02:52Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-01-26, and needs to be reviewed.
Apache NetBeans is an effort undergoing incubation at The Apache Software Foundation (ASF).
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
This wiki is an experiment pending Apache NetBeans Community approval.