KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > nodes > NodeOperation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.nodes;
20
21 import org.openide.util.Lookup;
22 import org.openide.util.UserCancelException;
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Component JavaDoc;
26 import java.awt.Container JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29
30 import javax.swing.*;
31
32
33 /** Provides common operations on nodes.
34  * Any component may
35  * ask to open a customizer for, or explore, any node.
36  * @since 3.14
37  */

38 public abstract class NodeOperation {
39     /** Subclass constructor. */
40     protected NodeOperation() {
41     }
42
43     /** Get default instance from lookup.
44      * @return some instance
45      */

46     public static NodeOperation getDefault() {
47         NodeOperation no = Lookup.getDefault().lookup(NodeOperation.class);
48
49         if (no == null) {
50             throw new IllegalStateException JavaDoc(
51                 "To use NodeOperation you should have its implementation around. For example one from openide-explorer.jar" // NOI18N
52
);
53         }
54
55         return no;
56     }
57
58     /** Tries to open a customization dialog for the specified node.
59      * The dialog is
60      * modal and the function returns only after
61      * customization is finished, if it was possible.
62      *
63      * @param n the node to customize
64      * @return <CODE>true</CODE> if the node had a customizer,
65      * <CODE>false</CODE> if not
66      * @see Node#hasCustomizer
67      * @see Node#getCustomizer
68      */

69     public abstract boolean customize(Node n);
70
71     /** Explore a node (and its subhierarchy).
72      * It will be opened in a new Explorer view, as the root node of that window.
73      * @param n the node to explore
74      */

75     public abstract void explore(Node n);
76
77     /** Open a modal Property Sheet on a node.
78      * @param n the node to show properties of
79      */

80     public abstract void showProperties(Node n);
81
82     /** Open a modal Property Sheet on a set of nodes.
83      * @param n the array of nodes to show properties of
84      * @see #showProperties(Node)
85      */

86     public abstract void showProperties(Node[] n);
87
88     /** Open a modal Explorer on a root node, permitting a node selection to be returned.
89      * <p>The acceptor
90      * should be asked each time the set of selected nodes changes, whether to accept or
91      * reject the current result. This will affect for example the
92      * display of the "OK" button.
93      *
94      * @param title title of the dialog
95      * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
96      * @param root root node to explore
97      * @param acceptor class asked to accept or reject current selection
98      * @param top an extra component to be placed on the dialog (may be <code>null</code>)
99      * @return an array of selected (and accepted) nodes
100      *
101      * @exception UserCancelException if the selection is interrupted by the user
102      */

103     public abstract Node[] select(String JavaDoc title, String JavaDoc rootTitle, Node root, NodeAcceptor acceptor, Component JavaDoc top)
104     throws UserCancelException;
105
106     /** Open a modal Explorer without any extra dialog component.
107      * @param title title of the dialog
108      * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
109      * @param root root node to explore
110      * @param acceptor class asked to accept or reject current selection
111      * @return an array of selected (and accepted) nodes
112      *
113      * @exception UserCancelException if the selection is interrupted by the user
114      * @see #select(String, String, Node, NodeAcceptor, Component)
115      */

116     public Node[] select(String JavaDoc title, String JavaDoc rootTitle, Node root, NodeAcceptor acceptor)
117     throws UserCancelException {
118         //XXX AFAIK this is completely unused in NetBeans. Deprecate? -Tim
119
return select(title, rootTitle, root, acceptor, null);
120     }
121
122     /** Open a modal Explorer accepting only a single node.
123      * @param title title of the dialog
124      * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
125      * @param root root node to explore
126      * @return the selected node
127      *
128      * @exception UserCancelException if the selection is interrupted by the user
129      * @see #select(String, String, Node, NodeAcceptor)
130      */

131     public final Node select(String JavaDoc title, String JavaDoc rootTitle, Node root)
132     throws UserCancelException {
133         return select(
134             title, rootTitle, root,
135             new NodeAcceptor() {
136                 public boolean acceptNodes(Node[] nodes) {
137                     return nodes.length == 1;
138                 }
139             }
140         )[0];
141     }
142 }
143
Popular Tags