KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > openide > explorer > NodeOperationImpl


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.openide.explorer;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import javax.swing.*;
25
26 import org.openide.explorer.propertysheet.PropertySheet;
27 import org.openide.explorer.view.BeanTreeView;
28 import org.openide.nodes.*;
29 import org.openide.util.UserCancelException;
30
31 /**
32  * Default implementation of node operations like show properties, etc.
33  */

34 public final class NodeOperationImpl extends org.openide.nodes.NodeOperation {
35
36     public boolean customize(Node node) {
37         Component JavaDoc customizer = node.getCustomizer();
38         if (customizer == null) {
39             return false;
40         }
41         final JDialog d = new JDialog();
42         d.setModal(false);
43         d.setTitle(node.getDisplayName());
44         d.getContentPane().setLayout(new BorderLayout JavaDoc());
45         d.getContentPane().add(customizer, BorderLayout.CENTER);
46         d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
47         d.pack();
48         d.setVisible(true);
49         return true;
50     }
51
52     public void explore(Node n) {
53         JDialog d = new JDialog();
54         d.setTitle(n.getDisplayName());
55         d.setModal(false);
56         d.getContentPane().setLayout(new BorderLayout JavaDoc());
57         EP p = new EP();
58         p.getExplorerManager().setRootContext(n);
59         p.setLayout(new BorderLayout JavaDoc());
60         p.add(new JScrollPane(new BeanTreeView()), BorderLayout.CENTER);
61         d.getContentPane().add(p, BorderLayout.CENTER);
62         d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
63         d.pack();
64         d.setVisible(true);
65     }
66
67     public Node[] select(String JavaDoc title, String JavaDoc rootTitle, Node root, NodeAcceptor acceptor, Component JavaDoc top) throws UserCancelException {
68         // XXX rootTitle and acceptor currently ignored
69
JDialog d = new JDialog();
70         d.setTitle(title);
71         d.setModal(true);
72         d.getContentPane().setLayout(new BorderLayout JavaDoc());
73         EP p = new EP();
74         p.getExplorerManager().setRootContext(root);
75         p.setLayout(new BorderLayout JavaDoc());
76         p.add(new JScrollPane(new BeanTreeView()), BorderLayout.CENTER);
77         d.getContentPane().add(p, BorderLayout.CENTER);
78         if (top != null) {
79             d.getContentPane().add(top, BorderLayout.NORTH);
80         }
81         d.pack();
82         d.setVisible(true);
83         Node[] nodes = p.getExplorerManager().getSelectedNodes();
84         d.dispose();
85         return nodes;
86     }
87
88     public void showProperties(Node n) {
89         showProperties(new Node[] {n});
90     }
91
92     public void showProperties(Node[] nodes) {
93         PropertySheet ps = new PropertySheet();
94         ps.setNodes(nodes);
95         JDialog d = new JDialog();
96         d.setTitle("Properties"); // XXX I18N
97
d.setModal(true);
98         d.getContentPane().setLayout(new BorderLayout JavaDoc());
99         d.getContentPane().add(ps, BorderLayout.CENTER);
100         d.pack();
101         d.setVisible(true);
102         d.dispose();
103     }
104     
105     private static final class EP extends JPanel
106     implements org.openide.explorer.ExplorerManager.Provider {
107         private org.openide.explorer.ExplorerManager em = new org.openide.explorer.ExplorerManager ();
108         
109         public org.openide.explorer.ExplorerManager getExplorerManager () {
110             return em;
111         }
112     }
113 }
114
Popular Tags