KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > 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.core.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.modules.websvc.core.CreatorProvider;
30 import org.netbeans.modules.websvc.core.HandlerCreator;
31 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
32 import org.netbeans.spi.project.ui.templates.support.Templates;
33 import org.openide.WizardDescriptor;
34 import javax.swing.event.ChangeListener JavaDoc;
35 import org.openide.util.HelpCtx;
36 import org.openide.util.NbBundle;
37 import org.netbeans.modules.j2ee.common.Util;
38
39 public class LogicalHandlerWizard implements WizardDescriptor.InstantiatingIterator {
40     public int currentPanel = 0;
41     private WizardDescriptor.Panel [] wizardPanels;
42     private WizardDescriptor.Panel firstPanel; //special case: use Java Chooser
43
private WizardDescriptor wiz;
44     private Project project;
45     private String JavaDoc handlerName;
46     public static final String JavaDoc JAVAC_CLASSPATH = "javac.classpath"; //NOI18N
47

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

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

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

194             return false;
195         }
196         
197         public HelpCtx getHelp() {
198             return new HelpCtx(LogicalHandlerWizard.class);
199         }
200     }
201 }
202
Popular Tags