KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > dev > wizard > CreateWebServiceFromExistingCodePanel


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.dev.wizard;
21
22 import javax.swing.JPanel JavaDoc;
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Component JavaDoc;
26 import java.awt.Dimension JavaDoc;
27 import java.util.List JavaDoc;
28 import java.beans.PropertyChangeEvent JavaDoc;
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import javax.swing.event.ChangeEvent JavaDoc;
32 import javax.swing.event.ChangeListener JavaDoc;
33 import org.netbeans.api.project.Project;
34 import org.openide.explorer.ExplorerManager;
35 import org.openide.explorer.view.BeanTreeView;
36 import org.openide.nodes.AbstractNode;
37 import org.openide.nodes.Node;
38 import org.openide.util.HelpCtx;
39 import org.openide.util.NbBundle;
40 import org.openide.WizardDescriptor;
41 import org.netbeans.api.project.ui.OpenProjects;
42 import org.netbeans.spi.project.ui.LogicalViewProvider;
43 import org.openide.nodes.Children;
44 import org.netbeans.modules.j2ee.api.ejbjar.EjbReference;
45
46 public class CreateWebServiceFromExistingCodePanel extends JPanel JavaDoc
47 implements WizardDescriptor.FinishablePanel, ExplorerManager.Provider, WebServiceWizard.HasWizardHelper {
48     private ExplorerManager manager;
49     private JPanel JavaDoc panel;
50     private Node[] selectedNodes;
51     private ChangeListener JavaDoc listener;
52     private WebServiceWizardHelper helper;
53     
54     public CreateWebServiceFromExistingCodePanel(WebServiceWizardHelper helper) {
55         this.helper = helper;
56         initComponents();
57         manager = new ExplorerManager();
58         manager.addPropertyChangeListener(
59         new PropertyChangeListener JavaDoc() {
60             public void propertyChange(PropertyChangeEvent JavaDoc pce) {
61                 selectedNodes = manager.getSelectedNodes();
62                 fireStateChange();
63             }
64         });
65     }
66     
67     
68     private void initComponents() {
69         panel = new JPanel JavaDoc();
70         setLayout(new BorderLayout JavaDoc());
71         setPreferredSize(new Dimension JavaDoc(550, 440));
72         panel.setLayout(new BorderLayout JavaDoc());
73         add(panel, BorderLayout.CENTER);
74         
75         BeanTreeView btv = new BeanTreeView();
76         btv.getAccessibleContext().
77         setAccessibleName(NbBundle.getMessage(CreateWebServiceFromExistingCodePanel.class,
78         "LBL_ExistingCode_Tree")); //NOI18N
79
btv.getAccessibleContext().setAccessibleDescription
80         (NbBundle.getMessage(CreateWebServiceFromExistingCodePanel.class,
81         "LBL_SelectExistingCode")); //NOI18N
82

83         panel.add(btv, "Center"); //NOI18N
84
panel.validate();
85         validate();
86     }
87     
88     public ExplorerManager getExplorerManager() {
89         return manager;
90     }
91     
92     public void addChangeListener(ChangeListener JavaDoc l) {
93         listener = l;
94     }
95     
96     private void fireStateChange() {
97         if (listener != null) {
98             ChangeEvent JavaDoc evt = new ChangeEvent JavaDoc(this);
99             listener.stateChanged(evt);
100         }
101     }
102     
103     public Component JavaDoc getComponent() {
104         return this;
105     }
106     
107     public HelpCtx getHelp() {
108         return null;
109     }
110     
111     public boolean isValid() {
112         for(int i = 0; i < selectedNodes.length; i++) {
113             Node node = selectedNodes[i];
114             if (node.getCookie(EjbReference.class) == null) {
115                 return false;
116             }
117             /*
118             DataObject d = (DataObject)node.getCookie(DataObject.class);
119             if (d!= null) {
120                 Resource res = JavaModel.getResource(d.getPrimaryFile());
121                 List classes = res.getClassifiers();
122                 TypeClass tc = JavaModel.getDefaultExtent().getType();
123                 JavaClass entityBeanInterface = (JavaClass)tc.resolve("javax.ejb.EntityBean"); //NOI18N
124                 JavaClass msgBeanInterface = (JavaClass)tc.resolve("javax.ejb.MessageDrivenBean"); //NOI18N
125                 JavaClass msgListenerInterface = (JavaClass)tc.resolve("javax.jms.MessageListener"); //NOI18N
126                 JavaClass localHomeInterface = (JavaClass)tc.resolve("javax.ejb.EJBLocalHome"); //NOI18N
127                 JavaClass homeInterface = (JavaClass)tc.resolve("javax.ejb.EJBHome"); //NOI18N
128                 JavaClass localInterface = (JavaClass)tc.resolve("javax.ejb.EJBLocalObject"); //NOI18N
129                 JavaClass remoteInterface = (JavaClass)tc.resolve("javax.ejb.EJBObject"); //NOI18N
130                 for (int c=0; c < classes.size(); c++) {
131                     JavaClass jc = (JavaClass)classes.get(c);
132                     if (jc.isSubTypeOf(entityBeanInterface) ||
133                         jc.isSubTypeOf(msgBeanInterface) ||
134                         jc.isSubTypeOf(msgListenerInterface) ||
135                         jc.isSubTypeOf(localHomeInterface) ||
136                         jc.isSubTypeOf(homeInterface) ||
137                         jc.isSubTypeOf(localInterface) ||
138                         jc.isSubTypeOf(remoteInterface)) {
139                         return false;
140                     }
141                 }
142             }*/

143         }
144         return true;
145     }
146     
147     public void readSettings(Object JavaDoc settings) {
148         Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
149         List JavaDoc projectNodes = new LinkedList JavaDoc();
150         for(int i = 0; i < allProjects.length; i++) {
151             LogicalViewProvider lvp = (LogicalViewProvider)allProjects[i].getLookup().lookup(LogicalViewProvider.class);
152             if(lvp != null) {
153                 projectNodes.add(lvp.createLogicalView());
154             }
155         }
156         Children.Array children = new Children.Array();
157         children.add((Node[])projectNodes.toArray(new Node[projectNodes.size()]));
158         Node root = new AbstractNode(children);
159         root.setDisplayName(NbBundle.getMessage(CreateWebServiceFromExistingCodePanel.class, "LBL_Available_Projects"));
160         manager.setRootContext(root);
161     }
162     
163     public void removeChangeListener(ChangeListener JavaDoc l) {
164         if (listener == l) {
165             listener = null;
166         }
167     }
168     
169     public void storeSettings(Object JavaDoc settings) {
170         helper.setExistingCodeNodes(selectedNodes);
171     }
172     
173     public boolean isFinishPanel() {
174         return true;
175     }
176     
177     public void setWizardHelper(WebServiceWizardHelper h) {
178         helper = h;
179     }
180 }
181
Popular Tags