KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > webservices > ui > panels > SelectHandlerPanel


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.websvc.core.webservices.ui.panels;
21
22 import javax.swing.JPanel JavaDoc;
23 import org.openide.explorer.ExplorerManager;
24 import org.openide.nodes.Node;
25 import java.awt.BorderLayout JavaDoc;
26 import java.awt.Dimension JavaDoc;
27 import org.openide.explorer.view.BeanTreeView;
28 import org.openide.util.NbBundle;
29 import java.beans.PropertyChangeEvent JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collections JavaDoc;
33 import java.util.LinkedList JavaDoc;
34 import java.util.List JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import org.netbeans.api.project.Project;
37 import org.openide.nodes.Children;
38 import org.netbeans.api.java.project.JavaProjectConstants;
39 import org.netbeans.api.project.ProjectUtils;
40 import org.netbeans.api.project.SourceGroup;
41 import org.netbeans.api.project.Sources;
42 import org.netbeans.spi.java.project.support.ui.PackageView;
43 import org.netbeans.spi.project.ui.LogicalViewProvider;
44 import org.openide.nodes.AbstractNode;
45 import org.openide.nodes.FilterNode;
46
47 /**
48  * @author rico
49  */

50 public class SelectHandlerPanel extends JPanel JavaDoc implements ExplorerManager.Provider {
51     
52     private ExplorerManager manager;
53     private Node[] selectedNodes;
54     private JPanel JavaDoc panel;
55     private Project project;
56     
57     /** Creates a new instance of SelectHandlerPanel */
58     public SelectHandlerPanel(Project project) {
59         this.project = project;
60         initComponents();
61         manager = new ExplorerManager();
62         manager.addPropertyChangeListener(
63                 new PropertyChangeListener JavaDoc() {
64             public void propertyChange(PropertyChangeEvent JavaDoc pce) {
65                 selectedNodes = manager.getSelectedNodes();
66             }
67         });
68         populateTree();
69     }
70     
71     public Node[] getSelectedNodes(){
72         return selectedNodes;
73     }
74     
75     public ExplorerManager getExplorerManager() {
76         return manager;
77     }
78     
79     private void populateTree(){
80         LogicalViewProvider lvp = (LogicalViewProvider)project.getLookup().lookup(LogicalViewProvider.class);
81         Node projectView = lvp.createLogicalView();
82         Children.Array children = new Children.Array();
83         FilterNode filter = new FilterNode(projectView, new SourceListViewChildren());
84         children.add(new FilterNode[] {filter});
85         Node root = new AbstractNode(children);
86         manager.setRootContext(filter);
87         
88     }
89     
90     private void initComponents() {
91         panel = new JPanel JavaDoc();
92         setLayout(new BorderLayout JavaDoc());
93         BorderLayout JavaDoc bl = new BorderLayout JavaDoc();
94         panel.setLayout(bl);
95         bl.setVgap(10);
96         add(panel, BorderLayout.CENTER);
97         
98         BeanTreeView btv = new BeanTreeView();
99         btv.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
100         btv.getAccessibleContext().
101                 setAccessibleName(NbBundle.getMessage(SelectHandlerPanel.class,"LBL_Class_Tree"));
102         btv.getAccessibleContext().setAccessibleDescription
103                 (NbBundle.getMessage(SelectHandlerPanel.class,"TTL_SelectHandler"));
104         String JavaDoc projectName = project.getProjectDirectory().getName();
105         String JavaDoc classesLabel = projectName + " " +
106                 NbBundle.getMessage(SelectHandlerPanel.class, "LBL_PROJECT_CLASSES") + ":";
107         JLabel JavaDoc label = new JLabel JavaDoc(classesLabel);
108         panel.add(label, BorderLayout.NORTH);
109         panel.add(btv, BorderLayout.CENTER); //NOI18N
110
panel.validate();
111         validate();
112     }
113     
114     
115     class SourceListViewChildren extends Children.Keys {
116         public static final String JavaDoc KEY_SOURCES = "sourcesKey"; //NOI18N
117

118         protected Node[] createNodes(Object JavaDoc key) {
119             Node n = null;
120             List JavaDoc<Node> sourceNodes = new LinkedList JavaDoc<Node>();
121             if (key == KEY_SOURCES) {
122                 Sources sources = ProjectUtils.getSources(project);
123                 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
124                 for(int i = 0; i < groups.length; i++){
125                     sourceNodes.add(PackageView.createPackageView(groups[i]));
126                 }
127             }
128             return sourceNodes.<Node>toArray(new Node[sourceNodes.size()]);
129         }
130         
131         @Override JavaDoc
132         protected void addNotify() {
133             super.addNotify();
134             createNodes();
135         }
136         
137         private void createNodes() {
138             List JavaDoc l = new ArrayList JavaDoc();
139             l.add(KEY_SOURCES);
140             setKeys(l);
141         }
142         
143         @Override JavaDoc
144         protected void removeNotify() {
145             setKeys(Collections.EMPTY_SET);
146             super.removeNotify();
147         }
148         
149     }
150 }
151
Popular Tags