KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > selectors > NodeOperation2


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
20 package org.netbeans.modules.versioning.system.cvss.ui.selectors;
21
22 import org.openide.explorer.view.BeanTreeView;
23 import org.openide.explorer.ExplorerManager;
24 import org.openide.nodes.Node;
25 import org.openide.nodes.NodeAcceptor;
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.awt.Mnemonics;
29 import org.openide.util.UserCancelException;
30 import org.openide.util.HelpCtx;
31
32 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
33 import javax.swing.*;
34 import java.awt.*;
35 import java.beans.PropertyChangeListener JavaDoc;
36 import java.beans.PropertyChangeEvent JavaDoc;
37
38 /**
39  * NodeOperations without icons and root.
40  *
41  * @author Petr Kuzel
42  * @see issue #63249
43  */

44 public final class NodeOperation2 extends BeanTreeView implements PropertyChangeListener JavaDoc {
45
46     private final ExplorerManager manager = new ExplorerManager();
47
48     private DialogDescriptor dd;
49     private boolean hideIcons;
50     private NodeAcceptor acceptor;
51     private HelpCtx helpCtx;
52
53     /**
54      * Creates new selector with default node renderer.
55      */

56     public NodeOperation2() {
57     }
58
59     public Node[] select(String JavaDoc title, String JavaDoc subtitle, String JavaDoc acsd, Node root, String JavaDoc browserAcsn, String JavaDoc browserAcsd, NodeAcceptor acceptor) throws UserCancelException {
60         manager.setRootContext(root);
61         manager.addPropertyChangeListener(this);
62
63         if (hideIcons) {
64             DefaultTreeCellRenderer JavaDoc renderer = new DefaultTreeCellRenderer JavaDoc();
65             renderer.setOpenIcon(null);
66             renderer.setClosedIcon(null);
67             renderer.setLeafIcon(null);
68             tree.setCellRenderer(renderer);
69         }
70
71         setPopupAllowed (false);
72         setDefaultActionAllowed (false);
73         setBorder(UIManager.getBorder("Nb.ScrollPane.border")); // NOI18N
74

75         JLabel label = new JLabel();
76         Mnemonics.setLocalizedText(label, subtitle);
77         label.setLabelFor(tree);
78         label.setToolTipText(browserAcsd);
79         getAccessibleContext().setAccessibleDescription(browserAcsd);
80         getAccessibleContext().setAccessibleName(browserAcsn);
81         ExplorerParent pane = new ExplorerParent(this);
82         pane.add(label, BorderLayout.NORTH);
83         pane.setBorder(BorderFactory.createEmptyBorder(12,12,0,12));
84
85         dd = new DialogDescriptor(pane, title);
86         dd.setModal(true);
87         if (helpCtx != null) {
88             dd.setHelpCtx(helpCtx);
89         }
90         this.acceptor = acceptor;
91         testAccept();
92
93         Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
94         dialog.getAccessibleContext().setAccessibleDescription(acsd);
95         dialog.setVisible(true);
96
97         if (dd.getValue() == DialogDescriptor.OK_OPTION) {
98             return manager.getSelectedNodes();
99         } else {
100             throw new UserCancelException();
101         }
102     }
103
104     public void setIconsVisible(boolean visible) {
105         hideIcons = visible == false;
106     }
107
108     public void setHelpCtx(HelpCtx help) {
109         helpCtx = help;
110     }
111
112     public void propertyChange (PropertyChangeEvent JavaDoc ev) {
113         if (ev.getPropertyName().equals (ExplorerManager.PROP_SELECTED_NODES)) {
114             testAccept();
115         }
116     }
117
118     private void testAccept() {
119         dd.setValid(acceptor.acceptNodes (manager.getSelectedNodes()));
120     }
121
122     /**
123      * Provides explorer manager for given client.
124      * Workarounds ExprorerManager.find behaviour.
125      */

126     private class ExplorerParent extends JPanel implements ExplorerManager.Provider {
127         public ExplorerParent(Component client) {
128             super(new BorderLayout(6, 6));
129             add(client, BorderLayout.CENTER);
130         }
131
132         public ExplorerManager getExplorerManager() {
133             return manager;
134         }
135     }
136 }
137
Popular Tags