blob: e9f0ab01b8217397489222b25d4821c049fada2f [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= How do I show my node's properties in the Properties view?
:page-layout: wikidev
:page-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqPropertySheetNodes
:description: Apache NetBeans wiki DevFaqPropertySheetNodes
:toc: left
:toc-title:
:page-syntax: true
:page-wikidevsection: _properties_and_propertysheet
:page-position: 2
include::front::partial$database.adoc[]
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 [link:{apidoclink}org-openide-explorer/org/openide/explorer/ExplorerManager.html[ExplorerManager], and set the `activatedNodes` property on the parent xref:wiki/DevFaqWindowsTopComponent.adoc[TopComponent] which contains your tree view:
[source,java]
----
public class MyComponent extends TopComponent implements PropertyChangeListener {
private ExplorerManager explorerManager;
----
[source,java]
----
public MyComponent() {
explorerManager = new ExplorerManager();
explorerManager.addPropertyChangeListener(this);
}
----
[source,java]
----
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.