KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.NoSuchElementException JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import org.netbeans.api.project.Project;
28 import org.netbeans.api.project.SourceGroup;
29 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
30 import org.netbeans.spi.project.ui.templates.support.Templates;
31 import org.openide.WizardDescriptor;
32 import javax.swing.event.ChangeListener JavaDoc;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.netbeans.modules.j2ee.common.Util;
36
37 public class LogicalHandlerWizard implements WizardDescriptor.InstantiatingIterator {
38     public int currentPanel = 0;
39     private WizardDescriptor.Panel [] wizardPanels;
40     private WizardDescriptor.Panel firstPanel; //special case: use Java Chooser
41
private WizardDescriptor wiz;
42     private Project project;
43     private String JavaDoc handlerName;
44     public static final String JavaDoc JAVAC_CLASSPATH = "javac.classpath"; //NOI18N
45

46     public static LogicalHandlerWizard create() {
47         return new LogicalHandlerWizard();
48     }
49     
50     private static final String JavaDoc [] HANDLER_STEPS =
51             new String JavaDoc [] {
52         NbBundle.getMessage(LogicalHandlerWizard.class, "LBL_SpecifyLogicalHandlerInfo") //NOI18N
53
};
54     
55     public void initialize(WizardDescriptor wizard) {
56         
57         wiz = wizard;
58         project = Templates.getProject(wiz);
59         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
60         
61         //create the Java Project chooser
62
// firstPanel = JavaTemplates.createPackageChooser(project, sourceGroups, new BottomPanel());
63

64         if (sourceGroups.length == 0)
65             firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, sourceGroups, new BottomPanel()));
66         else
67             firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, new BottomPanel(), true));
68         
69         JComponent JavaDoc c = (JComponent JavaDoc) firstPanel.getComponent();
70         Util.changeLabelInComponent(c, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), //NOI18N
71
NbBundle.getMessage(WebServiceWizard.class, "LBL_LogicalHandler_Name") ); //NOI18N
72
c.putClientProperty("WizardPanel_contentData", //NOI18N
73
HANDLER_STEPS);
74         c.putClientProperty("WizardPanel_contentSelectedIndex", //NOI18N
75
new Integer JavaDoc(0));
76         c.getAccessibleContext().setAccessibleDescription
77                 (HANDLER_STEPS[0]);
78         wizardPanels = new WizardDescriptor.Panel[] {firstPanel};
79     }
80     
81     public void uninitialize(WizardDescriptor wizard) {
82     }
83     
84     public Set JavaDoc instantiate() throws IOException JavaDoc {
85         new WebServiceCreator(project, wiz).createLogicalHandler();
86         
87         return Collections.EMPTY_SET;
88     }
89     
90     
91     public WizardDescriptor.Panel current() {
92         return wizardPanels[currentPanel];
93     }
94     
95     public boolean hasNext() {
96         return currentPanel < wizardPanels.length -1;
97     }
98     
99     public boolean hasPrevious() {
100         return currentPanel > 0;
101     }
102     
103     public String JavaDoc name() {
104         return NbBundle.getMessage(WebServiceWizard.class, "LBL_Create_LogicalHandler_Title"); //NOI18N
105
}
106     
107     public void nextPanel() {
108         if(!hasNext()){
109             throw new NoSuchElementException JavaDoc();
110         }
111         currentPanel++;
112     }
113     
114     public void previousPanel() {
115         if(!hasPrevious()){
116             throw new NoSuchElementException JavaDoc();
117         }
118         currentPanel--;
119     }
120     
121     public void addChangeListener(javax.swing.event.ChangeListener JavaDoc l) {
122     }
123     
124     public void removeChangeListener(ChangeListener JavaDoc l) {
125     }
126     
127     
128     protected int getCurrentPanelIndex() {
129         return currentPanel;
130     }
131     
132     /** Dummy implementation of WizardDescriptor.Panel required in order to provide Help Button
133      */

134     private class BottomPanel implements WizardDescriptor.Panel {
135         
136         public void storeSettings(Object JavaDoc settings) {
137         }
138         
139         public void readSettings(Object JavaDoc settings) {
140         }
141         
142         public java.awt.Component JavaDoc getComponent() {
143             return new javax.swing.JPanel JavaDoc();
144         }
145         
146         public void addChangeListener(ChangeListener JavaDoc l) {
147         }
148         
149         public void removeChangeListener(ChangeListener JavaDoc l) {
150         }
151         
152         public boolean isValid() {
153             WebServiceCreator creator = new WebServiceCreator(project);
154             int projectType = creator.getProjectType();
155             
156             if (projectType == WebServiceCreator.JSE_PROJECT_TYPE && Util.isSourceLevel16orHigher(project))
157                 return true;
158             
159             if (projectType == WebServiceCreator.JSE_PROJECT_TYPE && Util.getSourceLevel(project).equals("1.5")) { //NOI18N
160
//test JAX-WS library
161
if (!PlatformUtil.hasJAXWSLibrary(project)) {
162                     wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); // NOI18N
163
return false;
164                 } else
165                     return true;
166             }
167             
168             if (Util.isJavaEE5orHigher(project) && (projectType == WebServiceCreator.WEB_PROJECT_TYPE || projectType == WebServiceCreator.EJB_PROJECT_TYPE)) { //NOI18N
169
return true;
170             }
171             
172             //if platform is Tomcat, source level must be jdk 1.5 and jaxws library must be in classpath
173
if(!Util.isJavaEE5orHigher(project) && projectType == WebServiceCreator.WEB_PROJECT_TYPE
174                     && !PlatformUtil.isJsr109Supported(project)
175                     && !PlatformUtil.isJsr109OldSupported(project) ){
176                 //has to be at least jdk 1.5
177
if (Util.isSourceLevel14orLower(project)) {
178                     wiz.putProperty("WizardPanel_errorMessage",
179                             NbBundle.getMessage(LogicalHandlerWizard.class, "ERR_HandlerNeedProperSourceLevel")); // NOI18N
180
return false;
181                 }
182                 if (!PlatformUtil.hasJAXWSLibrary(project)) { //must have jaxws library
183
wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); // NOI18N
184
return false;
185                 } else
186                     return true;
187             }
188             
189             wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); // NOI18N
190

191             return false;
192         }
193         
194         public HelpCtx getHelp() {
195             return new HelpCtx(LogicalHandlerWizard.class);
196         }
197     }
198 }
199
Popular Tags