KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsitconf > wizard > UsernameCallbackHandlerWizard


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 2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.wsitconf.wizard;
21
22 import org.netbeans.api.project.Project;
23 import org.netbeans.api.project.SourceGroup;
24 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates;
25 import org.netbeans.spi.project.ui.templates.support.Templates;
26 import org.openide.WizardDescriptor;
27 import org.openide.filesystems.FileObject;
28 import org.openide.loaders.DataFolder;
29 import org.openide.loaders.DataObject;
30 import org.openide.loaders.TemplateWizard;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33
34 import javax.swing.*;
35 import javax.swing.event.ChangeListener JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.util.Collections JavaDoc;
38 import java.util.NoSuchElementException JavaDoc;
39 import java.util.Set JavaDoc;
40 import org.netbeans.modules.websvc.wsitconf.util.Util;
41
42 public class UsernameCallbackHandlerWizard implements TemplateWizard.Iterator {
43     public int currentPanel = 0;
44     private WizardDescriptor.Panel [] wizardPanels;
45     private WizardDescriptor.Panel firstPanel; //special case: use Java Chooser
46
private TemplateWizard wiz;
47     private Project project;
48     private String JavaDoc handlerName;
49     public static final String JavaDoc JAVAC_CLASSPATH = "javac.classpath"; //NOI18N
50

51     public static UsernameCallbackHandlerWizard create() {
52         return new UsernameCallbackHandlerWizard();
53     }
54     
55     private static final String JavaDoc [] HANDLER_STEPS =
56     new String JavaDoc [] {
57         NbBundle.getMessage(UsernameCallbackHandlerWizard.class,
58         "LBL_SpecifyHandlerInfo") //NOI18N
59
};
60     
61     public void initialize(TemplateWizard wizard) {
62         
63         wiz = wizard;
64         project = Templates.getProject(wiz);
65         SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project);
66         
67         //create the Java Project chooser
68
firstPanel = JavaTemplates.createPackageChooser(project,sourceGroups, new BottomPanel());
69         JComponent c = (JComponent)firstPanel.getComponent();
70         Util.changeLabelInComponent(c, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), //NOI18N
71
NbBundle.getMessage(UsernameCallbackHandlerWizard.class, "LBL_Handler_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(TemplateWizard wizard)
82     {}
83     
84     public Set JavaDoc instantiate(TemplateWizard wiz) throws IOException JavaDoc {
85         FileObject pkg = Templates.getTargetFolder(wiz);
86         handlerName = Templates.getTargetName(wiz);
87         
88         DataFolder df = DataFolder.findFolder(pkg);
89         FileObject template = Templates.getTemplate(wiz);
90
91         DataObject dTemplate = DataObject.find(template);
92         DataObject dobj = dTemplate.createFromTemplate(df, handlerName);
93         
94         return Collections.singleton(dobj);
95     }
96     
97     public WizardDescriptor.Panel current() {
98         return wizardPanels[currentPanel];
99     }
100     
101     public boolean hasNext() {
102         return currentPanel < wizardPanels.length -1;
103     }
104     
105     public boolean hasPrevious() {
106         return currentPanel > 0;
107     }
108     
109     public String JavaDoc name() {
110         return NbBundle.getMessage(UsernameCallbackHandlerWizard.class, "LBL_Create_MessageHandler_Title"); //NOI18N
111
}
112     
113     public void nextPanel() {
114         if(!hasNext()){
115             throw new NoSuchElementException JavaDoc();
116         }
117         currentPanel++;
118     }
119     
120     public void previousPanel() {
121         if(!hasPrevious()){
122             throw new NoSuchElementException JavaDoc();
123         }
124         currentPanel--;
125     }
126     
127     public void addChangeListener(javax.swing.event.ChangeListener JavaDoc l) {
128     }
129     
130     public void removeChangeListener(ChangeListener JavaDoc l) {
131     }
132     
133     
134     protected int getCurrentPanelIndex() {
135         return currentPanel;
136     }
137     
138     /** Dummy implementation of WizardDescriptor.Panel required in order to provide Help Button
139      */

140     private class BottomPanel implements WizardDescriptor.Panel {
141         
142         public void storeSettings(Object JavaDoc settings) {
143         }
144
145         public void readSettings(Object JavaDoc settings) {
146             
147         }
148
149         public java.awt.Component JavaDoc getComponent() {
150             return new javax.swing.JPanel JavaDoc();
151         }
152
153         public void addChangeListener(ChangeListener JavaDoc l) {
154         }
155
156         public void removeChangeListener(ChangeListener JavaDoc l) {
157         }
158
159         public boolean isValid() {
160             return true;
161         }
162
163         public HelpCtx getHelp() {
164             return new HelpCtx(UsernameCallbackHandlerWizard.class);
165         }
166         
167     }
168     
169 }
170
Popular Tags