KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > JaxWsExplorerPanel


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.jaxws;
21
22 import java.awt.Image JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import java.beans.PropertyChangeListener JavaDoc;
28 import javax.swing.border.EtchedBorder JavaDoc;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.ui.OpenProjects;
31 //import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
32
//import org.netbeans.modules.websvc.api.webservices.WebServicesView;
33
import org.netbeans.modules.websvc.core.jaxws.nodes.JaxWsNode;
34 //import org.netbeans.modules.websvc.core.webservices.action.JaxRpcWsdlCookie;
35
import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
36 import org.netbeans.modules.websvc.jaxws.api.JAXWSView;
37 import org.netbeans.modules.websvc.jaxws.api.JaxWsWsdlCookie;
38 import org.netbeans.spi.project.ui.LogicalViewProvider;
39
40 import org.openide.DialogDescriptor;
41 import org.openide.explorer.ExplorerManager;
42 import org.openide.explorer.view.BeanTreeView;
43 import org.openide.filesystems.FileObject;
44 import org.openide.nodes.AbstractNode;
45 import org.openide.nodes.Children;
46 import org.openide.nodes.Node;
47 import org.openide.nodes.FilterNode;
48 import org.openide.util.NbBundle;
49
50 /**
51  *
52  * @author Milan Kuchtiak
53  */

54 public class JaxWsExplorerPanel extends JPanel JavaDoc implements ExplorerManager.Provider, PropertyChangeListener JavaDoc {
55
56     private DialogDescriptor descriptor;
57     private ExplorerManager manager;
58     private BeanTreeView treeView;
59     private Node selectedServiceNode;
60
61     public JaxWsExplorerPanel() {
62         manager = new ExplorerManager();
63         selectedServiceNode = null;
64         
65         initComponents();
66         initUserComponents();
67     }
68
69     /** This method is called from within the constructor to
70      * initialize the form.
71      * WARNING: Do NOT modify this code. The content of this method is
72      * always regenerated by the Form Editor.
73      */

74     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75
private void initComponents() {
76         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
77
78         jLblTreeView = new javax.swing.JLabel JavaDoc();
79
80         setLayout(new java.awt.GridBagLayout JavaDoc());
81
82         jLblTreeView.setText(NbBundle.getMessage(JaxWsExplorerPanel.class, "LBL_AvailableWebServices"));
83         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
84         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
85         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
86         gridBagConstraints.weightx = 1.0;
87         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 11, 0, 11);
88         add(jLblTreeView, gridBagConstraints);
89
90     }// </editor-fold>//GEN-END:initComponents
91

92     
93     // Variables declaration - do not modify//GEN-BEGIN:variables
94
private javax.swing.JLabel JavaDoc jLblTreeView;
95     // End of variables declaration//GEN-END:variables
96

97     private void initUserComponents() {
98         treeView = new BeanTreeView();
99         treeView.setRootVisible(false);
100         treeView.setPopupAllowed(false);
101                 treeView.setBorder(new EtchedBorder JavaDoc());
102
103         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
104         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
105         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
106         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 11, 0, 11);
107         gridBagConstraints.weightx = 1.0;
108         gridBagConstraints.weighty = 1.0;
109         add(treeView, gridBagConstraints);
110         jLblTreeView.setLabelFor(treeView);
111     }
112
113     public ExplorerManager getExplorerManager() {
114         return manager;
115     }
116
117     public void addNotify() {
118         super.addNotify();
119         manager.addPropertyChangeListener(this);
120                 Project[] projects = OpenProjects.getDefault().getOpenProjects();
121                 Children rootChildren = new Children.Array();
122                 AbstractNode explorerClientRoot = new AbstractNode(rootChildren);
123                 List JavaDoc<Node> projectNodeList = new ArrayList JavaDoc<Node>();
124                 for (int i=0;i<projects.length;i++) {
125                     LogicalViewProvider logicalProvider = (LogicalViewProvider)projects[i].getLookup().lookup(LogicalViewProvider.class);
126                     if (logicalProvider!=null) {
127                         Node rootNode = logicalProvider.createLogicalView();
128                         JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(projects[i].getProjectDirectory());
129                         if (jaxWsSupport!=null && jaxWsSupport.getServices().size()>0) {
130                             Node servicesNode = JAXWSView.getJAXWSView().createJAXWSView(projects[i]);
131                             
132                             if (servicesNode!=null) {
133                                 Children children = new Children.Array();
134                                 Node[] nodes= servicesNode.getChildren().getNodes();
135                                 if (nodes!=null && nodes.length>0) {
136                                     Node[] serviceNodes = new Node[nodes.length];
137                                     for (int j=0;j<nodes.length;j++) {
138                                         serviceNodes[j] = new ServiceNode((JaxWsNode)nodes[j]);
139                                     }
140                                     children.add(serviceNodes);
141                                     projectNodeList.add(new ProjectNode(children, rootNode));
142                                 }
143                             }
144                         }/* else {
145                             WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(projects[i].getProjectDirectory());
146                             if (wsSupport!=null && wsSupport.getServices().size()>0) {
147                                 FileObject ddFolder = wsSupport.getWsDDFolder();
148                                 Node servicesNode = WebServicesView.getWebServicesView(ddFolder).createWebServicesView(ddFolder);
149                                 if (servicesNode!=null) {
150                                     Children children = new Children.Array();
151                                     Node[] nodes= servicesNode.getChildren().getNodes();
152                                     if (nodes!=null && nodes.length>0) {
153                                         Node[] filterNodes = new Node[nodes.length];
154                                         for (int j=0;j<nodes.length;j++) filterNodes[j] = new FilterNode(nodes[j]);
155                                         children.add(filterNodes);
156                                         projectNodeList.add(new ProjectNode(children, rootNode));
157                                     }
158                                 }
159                             }
160                         }*/

161                     }
162                 }
163                 Node[] projectNodes = new Node[projectNodeList.size()];
164                 projectNodeList.<Node>toArray(projectNodes);
165                 rootChildren.add(projectNodes);
166         manager.setRootContext(explorerClientRoot);
167         
168         // !PW If we preselect a node, this can go away.
169
descriptor.setValid(false);
170     }
171
172     public void removeNotify() {
173         manager.removePropertyChangeListener(this);
174         super.removeNotify();
175     }
176
177     public void setDescriptor(DialogDescriptor descriptor) {
178         this.descriptor = descriptor;
179     }
180     
181     public Node getSelectedService() {
182         return selectedServiceNode;
183     }
184
185     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
186         if(evt.getSource() == manager) {
187             if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
188                 Node nodes[] = manager.getSelectedNodes();
189                 if(nodes != null && nodes.length > 0 ) {
190                     Node node = nodes[0];
191                     if(node.getCookie(JaxWsWsdlCookie.class)!=null/* || node.getCookie(JaxRpcWsdlCookie.class)!=null*/) {
192                         // This is a method node.
193
selectedServiceNode = node;
194                         descriptor.setValid(true);
195                     } else {
196                         // This is not a method node.
197
selectedServiceNode = null;
198                         descriptor.setValid(false);
199                     }
200                 }
201             }
202         }
203     }
204         
205     private class ProjectNode extends AbstractNode {
206         private Node rootNode;
207         
208         ProjectNode(Children children, Node rootNode) {
209             super(children);
210             this.rootNode=rootNode;
211             setName(rootNode.getDisplayName());
212         }
213         
214         public Image JavaDoc getIcon(int type) {
215             return rootNode.getIcon(type);
216         }
217
218         public Image JavaDoc getOpenedIcon(int type) {
219             return rootNode.getOpenedIcon(type);
220         }
221     }
222     
223     private class ServiceNode extends AbstractNode implements JaxWsWsdlCookie{
224         
225         private JaxWsNode serviceNode;
226         
227         ServiceNode(JaxWsNode serviceNode) {
228             super(Children.LEAF);
229             this.serviceNode=serviceNode;
230             setName(serviceNode.getDisplayName());
231             getCookieSet().add(this);
232         }
233         
234         public Image JavaDoc getIcon(int type) {
235             return serviceNode.getIcon(type);
236         }
237         
238         public Image JavaDoc getOpenedIcon(int type) {
239             return serviceNode.getOpenedIcon(type);
240         }
241
242         public String JavaDoc getWsdlURL() {
243             return serviceNode.getWsdlURL();
244         }
245         
246     }
247 }
248
Popular Tags