KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > JMSWizard


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  * JMSWizard.java
21  *
22  * Created on October 9, 2003, 10:29 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 import java.awt.Component JavaDoc;
28 import java.util.Set JavaDoc;
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31 import java.io.InputStream JavaDoc;
32
33 import org.openide.util.NbBundle;
34 import org.openide.WizardDescriptor;
35 import org.netbeans.api.project.Project;
36 import org.openide.filesystems.FileObject;
37 import org.netbeans.spi.project.ui.templates.support.Templates;
38
39 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
40
41 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
42 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
43 import org.openide.ErrorManager;
44
45 /**
46  *
47  * @author nityad
48  */

49 public class JMSWizard implements WizardDescriptor.InstantiatingIterator, WizardConstants{
50     
51     private static Project project;
52     
53     /** An array of all wizard panels */
54     private WizardDescriptor.Panel panels[];
55 // private transient WizardDescriptor wiz;
56
private transient String JavaDoc[] steps;
57     private transient int index;
58     
59     private ResourceConfigHelper helper;
60     private Wizard wizardInfo;
61     
62     private static final String JavaDoc DATAFILE = "org/netbeans/modules/j2ee/sun/sunresources/beans/JMSWizard.xml"; //NOI18N
63

64     
65     /** Creates a new instance of JMSWizard */
66     public static JMSWizard create() {
67         return new JMSWizard();
68     }
69     
70     private WizardDescriptor.Panel[] createPanels() {
71         return new WizardDescriptor.Panel[] {
72             new JMSWizardPanel(this.helper, this.wizardInfo),
73             new JmsPropertyPanel(this.helper, this.wizardInfo)
74         };
75     }
76     
77     private String JavaDoc[] createSteps() {
78         return new String JavaDoc[] {
79             NbBundle.getMessage(JMSWizard.class, __FirstStepChoose),
80             NbBundle.getMessage(JMSWizard.class, "LBL_GeneralAttributes_JMS"), //NOI18N
81
NbBundle.getMessage(JMSWizard.class, "LBL_AddProperty") //NOI18N
82
};
83     }
84     
85     public Set JavaDoc instantiate(){
86         try{
87             ResourceUtils.saveJMSResourceDatatoXml(this.helper.getData());
88         }catch (Exception JavaDoc ex){
89                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
90                                         ex);
91         }
92         return java.util.Collections.EMPTY_SET;
93     }
94     
95     public void initialize(WizardDescriptor wiz){
96         this.wizardInfo = getWizardInfo();
97         this.helper = new ResourceConfigHelperHolder().getJMSHelper();
98         
99         //this.wiz = wiz;
100
wiz.putProperty("NewFileWizard_Title", NbBundle.getMessage(JMSWizard.class, "Templates/SunResources/JMS_Resource")); //NOI18N
101
index = 0;
102         project = Templates.getProject(wiz);
103         
104         panels = createPanels();
105         // Make sure list of steps is accurate.
106

107         steps = createSteps();
108         
109         try{
110             FileObject pkgLocation = project.getProjectDirectory();
111             if (pkgLocation != null) {
112                 this.helper.getData().setTargetFileObject(pkgLocation);
113             }
114         }catch (Exception JavaDoc ex){
115                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
116                                         ex);
117         }
118         
119         for (int i = 0; i < panels.length; i++) {
120             Component JavaDoc c = panels[i].getComponent();
121             if (c instanceof JComponent JavaDoc) { // assume Swing components
122
JComponent JavaDoc jc = (JComponent JavaDoc)c;
123                 // Step #.
124
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
125
// Step name (actually the whole list for reference).
126
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
127
}
128         }
129     }
130     
131     public void uninitialize(WizardDescriptor wiz){
132         //this.wiz = null;
133
panels = null;
134     }
135     
136     public Wizard getWizardInfo(){
137         try{
138             InputStream JavaDoc in = Wizard.class.getClassLoader().getResourceAsStream(DATAFILE);
139             this.wizardInfo = Wizard.createGraph(in);
140         }catch(Exception JavaDoc ex){
141                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
142                                         ex);
143         }
144         return this.wizardInfo;
145     }
146     
147     public String JavaDoc name(){
148         return NbBundle.getMessage(JMSWizard.class, "Templates/SunResources/JMS_Resource"); //NOI18N
149
}
150     
151     public boolean hasNext(){
152         return index < panels.length - 1;
153     }
154     
155     public boolean hasPrevious(){
156         return index > 0;
157     }
158     
159     public synchronized void nextPanel(){
160         if (index + 1 == panels.length) {
161             throw new java.util.NoSuchElementException JavaDoc();
162         }
163         
164         if (index == 0){
165             ((JmsPropertyPanel) panels[1]).refreshFields();
166         }
167         
168         index ++;
169     }
170     
171     public synchronized void previousPanel(){
172         if (index == 0) {
173             throw new java.util.NoSuchElementException JavaDoc();
174         }
175         
176         index--;
177     }
178     
179     public WizardDescriptor.Panel current(){
180         return (WizardDescriptor.Panel)panels[index];
181     }
182     
183     public void addChangeListener(ChangeListener JavaDoc l){
184     }
185     
186     public void removeChangeListener(ChangeListener JavaDoc l){
187     }
188     
189     public ResourceConfigHelper getResourceConfigHelper(){
190         return this.helper;
191     }
192     
193     public void setResourceConfigHelper(ResourceConfigHelper helper){
194         this.helper = helper;
195     }
196 }
197
Popular Tags