blob: c96f89c3d612209b6a4d412e352425f30508aae6 [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.
//
= DevFaqNodeViewCapability
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqNodeViewCapability
:description: Apache NetBeans wiki DevFaqNodeViewCapability
:toc: left
:toc-title:
:syntax: true
=== How can I add a "View" capability for data my node represents
Let's say that you've added support for a new file type in your application. You want to be able to provide an action by which users can "view" the file, which might open it up in the source editor (for text-based files) or a custom editor you've created in Swing. How can you add this view action?
It turns out that there are a few ways:
1. Create a `ViewCookie` for your node and in display the contents in the cookie's view() method.
2. Create a subclass of `NodeAction` and displays the node's contents in its performAction() method.
3. Create a subclass of `Node.Cookie` that my node should return in its lookup and then create a `CookieAction` that acts upon this.
The first approach (`ViewCookie`) is the simplest of the three, though it can really only operate on a single node. If you just need something quick and easy, then it is probably your best bet.
The second approach (`NodeAction`) will work but is discouraged since someone creating a `FilterNode` on your node might inadvertently disable your action.
The third approach (`Node.Cookie/CookieAction`) is the most difficult of the three but also the most versatile. Your `CookieAction` can be enabled for multiple classes and can also operate on several nodes at once.
=== See also:
* link:DevFaqActionContextSensitive.asciidoc[How do I create an Action that is automatically enabled and disabled depending on the selection?]
=== 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/DevFaqNodeViewCapability[http://wiki.netbeans.org/DevFaqNodeViewCapability] ,
that was last modified by NetBeans user Admin
on 2009-11-06T15:56:35Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.