KickJava   Java API By Example, From Geeks To Geeks.

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


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  * MailWizard.java
21  *
22  * Created on October 9, 2003, 11:39 AM
23  */

24 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
25
26 /**
27  *
28  * @author nityad
29  */

30
31 import java.awt.Component JavaDoc;
32 import java.util.Set JavaDoc;
33 import javax.swing.JComponent JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import javax.swing.event.ChangeListener JavaDoc;
36
37 import org.openide.util.NbBundle;
38 import org.openide.WizardDescriptor;
39 import org.netbeans.api.project.Project;
40 import org.openide.filesystems.FileObject;
41 import org.netbeans.spi.project.ui.templates.support.Templates;
42
43 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
44
45 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
46 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
47 import org.openide.ErrorManager;
48
49 public final class MailWizard implements WizardDescriptor.InstantiatingIterator, WizardConstants{
50     
51            
52     private static final String JavaDoc DATAFILE = "org/netbeans/modules/j2ee/sun/sunresources/beans/MailWizard.xml"; //NOI18N
53

54     /** An array of all wizard panels */
55     private transient WizardDescriptor.Panel[] panels;
56 // private transient WizardDescriptor wiz;
57
private transient String JavaDoc[] steps;
58     private transient int index;
59     
60     private ResourceConfigHelper helper;
61     private Wizard wizardInfo;
62         
63     /** Creates a new instance of MailWizard */
64     public static MailWizard create () {
65         return new MailWizard ();
66     }
67     
68     private WizardDescriptor.Panel[] createPanels() {
69         return new WizardDescriptor.Panel[] {
70             new CommonGeneralFinishPanel(this.helper, this.wizardInfo, new String JavaDoc[] {"general", "advanced"}), //NOI18N
71
new MailPropertyPanel(this.helper, this.wizardInfo)
72         };
73     }
74     
75     private String JavaDoc[] createSteps() {
76         return new String JavaDoc[] {
77             NbBundle.getMessage(MailWizard.class, __FirstStepChoose),
78             NbBundle.getMessage(MailWizard.class, "LBL_GeneralAttributes_MAIL"), //NOI18N
79
NbBundle.getMessage(MailWizard.class, "LBL_AddProperty") //NOI18N
80
};
81     }
82     
83     public Set JavaDoc instantiate(){
84         try{
85             ResourceUtils.saveMailResourceDatatoXml(this.helper.getData());
86         }catch (Exception JavaDoc ex){
87                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
88                                         ex);
89         }
90         return java.util.Collections.EMPTY_SET;
91     }
92     
93     public void initialize(WizardDescriptor wiz){
94         this.wizardInfo = getWizardInfo();
95         this.helper = new ResourceConfigHelperHolder().getMailHelper();
96         
97         //this.wiz = wiz;
98
wiz.putProperty("NewFileWizard_Title", NbBundle.getMessage(MailWizard.class, "Templates/SunResources/JavaMail_Resource")); //NOI18N
99
index = 0;
100                 
101         Project project = Templates.getProject(wiz);
102         
103         panels = createPanels();
104         // Make sure list of steps is accurate.
105
steps = createSteps();
106         
107         try{
108             FileObject pkgLocation = project.getProjectDirectory();
109             if (pkgLocation != null) {
110                 this.helper.getData().setTargetFileObject(pkgLocation);
111             }
112         }catch (Exception JavaDoc ex){
113                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
114                                         ex);
115         }
116         
117         for (int i = 0; i < panels.length; i++) {
118             Component JavaDoc c = panels[i].getComponent();
119             if (c instanceof JComponent JavaDoc) { // assume Swing components
120
JComponent JavaDoc jc = (JComponent JavaDoc)c;
121                 // Step #.
122
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
123
// Step name (actually the whole list for reference).
124
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
125
}
126         }
127     }
128     
129     public void uninitialize(WizardDescriptor wiz){
130         //this.wiz = null;
131
panels = null;
132     }
133     
134     public Wizard getWizardInfo(){
135         try{
136             InputStream JavaDoc in = Wizard.class.getClassLoader().getResourceAsStream(DATAFILE);
137             this.wizardInfo = Wizard.createGraph(in);
138         }catch(Exception JavaDoc ex){
139                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
140                                         ex);
141         }
142         return this.wizardInfo;
143     }
144     
145     public String JavaDoc name(){
146         return NbBundle.getMessage(MailWizard.class, "Templates/SunResources/JavaMail_Resource"); //NOI18N
147
}
148     
149     public boolean hasNext(){
150         return index < panels.length - 1;
151     }
152     
153     public boolean hasPrevious(){
154         return index > 0;
155     }
156     
157     public synchronized void nextPanel(){
158         if (index + 1 == panels.length) {
159             throw new java.util.NoSuchElementException JavaDoc();
160         }
161         
162         if (index == 0){
163             ((MailPropertyPanel) panels[1]).refreshFields();
164         }
165         index ++;
166     }
167     
168     public synchronized void previousPanel(){
169         if (index == 0) {
170             throw new java.util.NoSuchElementException JavaDoc();
171         }
172         
173         index--;
174     }
175     
176     public WizardDescriptor.Panel current(){
177         return (WizardDescriptor.Panel)panels[index];
178     }
179     
180     public void addChangeListener(ChangeListener JavaDoc l){
181     }
182     
183     public void removeChangeListener(ChangeListener JavaDoc l){
184     }
185
186      
187     public void setResourceConfigHelper(ResourceConfigHelper helper){
188         this.helper = helper;
189     }
190     
191     public ResourceConfigHelper getResourceConfigHelper(){
192         return this.helper;
193     }
194     
195 }
196
Popular Tags