KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsdl > wizard > SelectSchemaPanel


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.wsdl.wizard;
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 SelectSchemaPanel 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     /**
58      * Creates a new instance of SelectSchemaPanel
59      */

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

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