| // |
| // 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. |
| // |
| |
| = DevFaqNodeSubclass |
| :jbake-type: wiki |
| :jbake-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :keywords: Apache NetBeans wiki DevFaqNodeSubclass |
| :description: Apache NetBeans wiki DevFaqNodeSubclass |
| :toc: left |
| :toc-title: |
| :syntax: true |
| |
| === Creating Node Subclasses |
| |
| Nodes are useful for many things beyond just representing files. If you just need a placeholder `Node`, you do not need a subclass - just instantiate an `AbstractNode` - despite its name, `AbstractNode` is not an abstract class. For example: |
| |
| [source,java] |
| ---- |
| |
| AbstractNode nue = new AbstractNode (Children.LEAF); |
| nue.setDisplayName ("Please wait..."); |
| nue.setIcon (Utilities.loadImage ("path/in/jar/to/image.gif")); |
| return nue; |
| ---- |
| |
| If you are creating link:DevFaqWhatIsANode.asciidoc[Node]s, you will typically deal with one of four things |
| |
| * link:http://bits.netbeans.org/dev/javadoc/org-openide-nodes/org/openide/nodes/AbstractNode.html[AbstractNode] - create a Node which represents anything you want - you will implement all its logic, provide children, etc. Typically most logic goes in the Children object. |
| * link:http://bits.netbeans.org/dev/javadoc/org-openide-nodes/org/openide/nodes/BeanNode.html[BeanNode] - a very convenient Node subclass, which can represent any JavaBean as a Node and expose its bean properties as Property objects that can be edited on the property sheet |
| * link:http://bits.netbeans.org/dev/javadoc/org-openide-nodes/org/openide/nodes/FilterNode.html[FilterNode] - a Node subclass that proxies another Node. You can subclass this to take an existing Node (possibly representing a file on disk or in the link:DevFaqSystemFilesystem.asciidoc[system filesystem ] and keep most of its attributes, but provide different actions or display name or icons or properties |
| * link:http://bits.netbeans.org/dev/javadoc/org-openide-loaders/org/openide/loaders/DataNode.html[DataNode] - a Node subclass specific to editing files. If you are writing a module that adds support for a new file type (such as `.svg` files), you will write a `DataNode` subclass to give files of that type icons, display names, and possibly provide access to the file's content |
| |
| Note that if you just want to write context sensitive code, not provide your own Nodes, you may be able to do it without a dependency on the Nodes API, using link:DevFaqTrackGlobalSelection.asciidoc[Utilities.actionsGlobalContext()]. |
| |
| === Apache Migration Information |
| |
| The content in this page was kindly donated by Oracle Corp. to the |
| Apache Software Foundation. |
| |
| This page was exported from link:http://wiki.netbeans.org/DevFaqNodeSubclass[http://wiki.netbeans.org/DevFaqNodeSubclass] , |
| that was last modified by NetBeans user Tboudreau |
| on 2010-01-24T05:48:37Z. |
| |
| |
| *NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed. |