KickJava   Java API By Example, From Geeks To Geeks.

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


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

128     private class BottomPanel implements WizardDescriptor.Panel {
129         
130         public void storeSettings(Object JavaDoc settings) {
131         }
132         
133         public void readSettings(Object JavaDoc settings) {
134         }
135         
136         public java.awt.Component JavaDoc getComponent() {
137             return new javax.swing.JPanel JavaDoc();
138         }
139         
140         public void addChangeListener(ChangeListener JavaDoc l) {
141         }
142         
143         public void removeChangeListener(ChangeListener JavaDoc l) {
144         }
145         
146         public boolean isValid() {
147             //TODO test for conditions in JSE
148

149             //if platform is Tomcat, source level must be jdk 1.5 and jaxws library must be in classpath
150
WebServiceCreator creator = new WebServiceCreator(project);
151             int projectType = creator.getProjectType();
152             if(!Util.isJavaEE5orHigher(project) && projectType == WebServiceCreator.WEB_PROJECT_TYPE
153                     && !PlatformUtil.isJsr109Supported(project)
154                     && !PlatformUtil.isJsr109OldSupported(project) ){
155                 //has to be at least jdk 1.5
156
if (Util.isSourceLevel14orLower(project)) {
157                     wiz.putProperty("WizardPanel_errorMessage",
158                             NbBundle.getMessage(LogicalHandlerWizard.class, "ERR_HandlerNeedProperSourceLevel")); // NOI18N
159
return false;
160                 }
161                 if (!PlatformUtil.hasJAXWSLibrary(project)) { //must have jaxws library
162
wiz.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(BottomPanel.class, "LBL_LogicalHandlerWarning")); // NOI18N
163
return false;
164                 } else
165                     return true;
166             }
167             return true;
168         }
169         
170         public HelpCtx getHelp() {
171             return new HelpCtx(MessageHandlerWizard.class);
172         }
173         
174     }
175     
176 }
177
Popular Tags