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:
-
Create a
ViewCookiefor your node and in display the contents in the cookie’s view() method. -
Create a subclass of
NodeActionand displays the node’s contents in its performAction() method. -
Create a subclass of
Node.Cookiethat my node should return in its lookup and then create aCookieActionthat 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.