DevFaqPropertySheetNodes

(Difference between revisions)
m (How do I show my node's properties in the Properties view?)
 
(One intermediate revision not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
-
'''Q:''' I want to have the properties of my custom nodes displayed in the Properties view when they are selected in my tree view. How do I go about doing that?
+
===How do I show my node's properties in the Properties view?===
 +
I want to have the properties of my custom nodes displayed in the Properties view when they are selected in my tree view. How do I go about doing that?
-
'''A:''' It is simply a matter of listening for the selected nodes property change and then setting the activated nodes on the parent<tt>TopComponent</tt>which contains your tree view.
+
Listen for changes in the selected nodes in the [http://bits.netbeans.org/dev/javadoc/org-openide-explorer/org/openide/explorer/ExplorerManager.html <tt>ExplorerManager</tt>], and set the <code>activatedNodes</code> property on the parent [[DevFaqWindowsTopComponent| <tt>TopComponent</tt>]] which contains your tree view:
-
 
+
public class MyComponent extends TopComponent implements PropertyChangeListener {
-
<pre>
+
    private ExplorerManager explorerManager;
-
public class MyComponent extends TopComponent implements PropertyChangeListener {
+
-
    private ExplorerManager explorerManager;
+
    public MyComponent() {
-
 
+
        explorerManager = new ExplorerManager();
-
    public MyComponent() {
+
        explorerManager.addPropertyChangeListener(this);
-
        explorerManager = new ExplorerManager();
+
    }
-
        explorerManager.addPropertyChangeListener(this);
+
-
    }
+
    public void propertyChange(PropertyChangeEvent evt) {
-
 
+
        if (evt.getSource() == explorerManager &amp;&amp;
-
    public void propertyChange(PropertyChangeEvent evt) {
+
                ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
-
        if (evt.getSource() == explorerManager &amp;&amp;
+
-
                ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
+
             setActivatedNodes(explorerManager.getSelectedNodes());
             setActivatedNodes(explorerManager.getSelectedNodes());
-
        }
+
        }
-
    }
+
    }
-
}
+
}
-
</pre>
+
-
 
+
Note that the example above is not a complete <tt>TopComponent</tt> implementation with a tree view and nodes. It is simply demonstrating how to have the selected node's properties shown in the Properties view.
Note that the example above is not a complete <tt>TopComponent</tt> implementation with a tree view and nodes. It is simply demonstrating how to have the selected node's properties shown in the Properties view.

Current revision as of 16:17, 25 February 2010

How do I show my node's properties in the Properties view?

I want to have the properties of my custom nodes displayed in the Properties view when they are selected in my tree view. How do I go about doing that?

Listen for changes in the selected nodes in the ExplorerManager, and set the activatedNodes property on the parent TopComponent which contains your tree view:

public class MyComponent extends TopComponent implements PropertyChangeListener {
    private ExplorerManager explorerManager;

    public MyComponent() {
        explorerManager = new ExplorerManager();
        explorerManager.addPropertyChangeListener(this);
    }

    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getSource() == explorerManager &&
                ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
           setActivatedNodes(explorerManager.getSelectedNodes());
        }
    }
}

Note that the example above is not a complete TopComponent implementation with a tree view and nodes. It is simply demonstrating how to have the selected node's properties shown in the Properties view.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo