KickJava   Java API By Example, From Geeks To Geeks.

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

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

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