KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > wizards > ImportBlueprintEarWizardIterator


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.j2ee.earproject.ui.wizards;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.NoSuchElementException JavaDoc;
29 import java.util.Set JavaDoc;
30 import javax.swing.JComponent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32 import org.netbeans.api.progress.ProgressHandle;
33 import org.netbeans.modules.j2ee.earproject.EarProjectGenerator;
34 import org.netbeans.modules.j2ee.earproject.ModuleType;
35 import org.netbeans.modules.j2ee.earproject.ui.FoldersListSettings;
36 import org.openide.WizardDescriptor;
37 import org.openide.filesystems.FileObject;
38 import org.openide.filesystems.FileUtil;
39 import org.openide.util.HelpCtx;
40 import org.openide.util.NbBundle;
41
42 /**
43  * Wizard for importing a new Enterprise Application project.
44  * @author Jesse Glick
45  */

46 public class ImportBlueprintEarWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
47     
48     private static final long serialVersionUID = 1L;
49     
50     static final String JavaDoc PROP_NAME_INDEX = "nameIndex"; //NOI18N
51

52     private transient int index;
53     private transient WizardDescriptor.Panel[] panels;
54     transient WizardDescriptor wiz;
55     
56     private WizardDescriptor.Panel[] createPanels() {
57         return new WizardDescriptor.Panel[] {
58             new PanelConfigureProject(PROP_NAME_INDEX,
59                     NbBundle.getBundle(ImportBlueprintEarWizardIterator.class),
60                     new HelpCtx(this.getClass()), true),
61             new PanelModuleDetection()
62         };
63     }
64     
65     private String JavaDoc[] createSteps() {
66         return new String JavaDoc[] {
67             NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NWP1_ProjectTitleName"),
68             NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_IW_ApplicationModulesStep")
69         };
70     }
71     
72     public Set JavaDoc<FileObject> instantiate() throws IOException JavaDoc {
73         assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator.";
74         return null;
75     }
76         
77     public Set JavaDoc<FileObject> instantiate(ProgressHandle handle) throws IOException JavaDoc {
78         handle.start(3);
79         handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_CreatingProject"), 1);
80         
81         File JavaDoc dirF = (File JavaDoc) wiz.getProperty(WizardProperties.PROJECT_DIR);
82         File JavaDoc srcF = (File JavaDoc) wiz.getProperty(WizardProperties.SOURCE_ROOT);
83         String JavaDoc name = (String JavaDoc) wiz.getProperty(WizardProperties.NAME);
84         String JavaDoc j2eeLevel = (String JavaDoc) wiz.getProperty(WizardProperties.J2EE_LEVEL);
85         // String contextPath = (String) wiz.getProperty(WizardProperties.CONTEXT_PATH);
86
String JavaDoc serverInstanceID = (String JavaDoc) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID);
87         String JavaDoc platformName = (String JavaDoc)wiz.getProperty(WizardProperties.JAVA_PLATFORM);
88         String JavaDoc sourceLevel = (String JavaDoc)wiz.getProperty(WizardProperties.SOURCE_LEVEL);
89         @SuppressWarnings JavaDoc("unchecked")
90         Map JavaDoc<FileObject, ModuleType> userModules = (Map JavaDoc<FileObject, ModuleType>)
91                 wiz.getProperty(WizardProperties.USER_MODULES);
92         return testableInstantiate(platformName, sourceLevel, j2eeLevel, dirF,
93                 srcF, serverInstanceID, name, userModules, handle);
94     }
95     
96     /** <strong>Package private for unit test only</strong>. */
97     static Set JavaDoc<FileObject> testableInstantiate(final String JavaDoc platformName,
98             final String JavaDoc sourceLevel, final String JavaDoc j2eeLevel, final File JavaDoc dirF,
99             final File JavaDoc srcF, final String JavaDoc serverInstanceID, final String JavaDoc name,
100             final Map JavaDoc<FileObject, ModuleType> userModules, ProgressHandle handle) throws IOException JavaDoc {
101         
102         EarProjectGenerator.importProject(dirF, srcF, name, j2eeLevel,
103                 serverInstanceID, platformName, sourceLevel, userModules);
104         if (handle != null)
105             handle.progress(2);
106
107         FileObject dir = FileUtil.toFileObject(FileUtil.normalizeFile(dirF));
108         
109         // remember last used server
110
FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID);
111         Set JavaDoc<FileObject> resultSet = new HashSet JavaDoc<FileObject>();
112         resultSet.add(dir);
113         
114         NewEarProjectWizardIterator.setProjectChooserFolder(dirF);
115         
116         if (handle != null)
117             handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3);
118
119         // Returning set of FileObject of project diretory.
120
// Project will be open and set as main
121
return resultSet;
122     }
123     
124     public void initialize(WizardDescriptor wiz) {
125         this.wiz = wiz;
126         index = 0;
127         panels = createPanels();
128         // Make sure list of steps is accurate.
129
String JavaDoc[] steps = createSteps();
130         for (int i = 0; i < panels.length; i++) {
131             Component JavaDoc c = panels[i].getComponent();
132             if (steps[i] == null) {
133                 // Default step name to component name of panel.
134
// Mainly useful for getting the name of the target
135
// chooser to appear in the list of steps.
136
steps[i] = c.getName();
137             }
138             if (c instanceof JComponent JavaDoc) { // assume Swing components
139
JComponent JavaDoc jc = (JComponent JavaDoc)c;
140                 // Step #.
141
jc.putClientProperty("WizardPanel_contentSelectedIndex", i); // NOI18N
142
// Step name (actually the whole list for reference).
143
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
144
}
145         }
146     }
147
148     public void uninitialize(WizardDescriptor wiz) {
149         if (this.wiz != null) {
150             this.wiz.putProperty(WizardProperties.PROJECT_DIR,null);
151             this.wiz.putProperty(WizardProperties.NAME,null);
152         }
153         this.wiz = null;
154         panels = null;
155     }
156     
157     public String JavaDoc name() {
158         return MessageFormat.format(
159                 NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_WizardStepsCount"),
160                 index + 1, panels.length);
161     }
162     
163     public boolean hasNext() {
164         return index < panels.length - 1;
165     }
166     
167     public boolean hasPrevious() {
168         return index > 0;
169     }
170     
171     public void nextPanel() {
172         if (!hasNext()) {
173             throw new NoSuchElementException JavaDoc();
174         }
175         index++;
176     }
177     
178     public void previousPanel() {
179         if (!hasPrevious()) {
180             throw new NoSuchElementException JavaDoc();
181         }
182         index--;
183     }
184     
185     public WizardDescriptor.Panel current() {
186         return panels[index];
187     }
188     
189     // If nothing unusual changes in the middle of the wizard, simply:
190
public final void addChangeListener(ChangeListener JavaDoc l) {}
191     public final void removeChangeListener(ChangeListener JavaDoc l) {}
192     
193     // helper methods, finds indexJSP's FileObject
194
FileObject getIndexJSPFO(FileObject webRoot, String JavaDoc indexJSP) {
195         // XXX: ignore unvalid mainClass?
196
return webRoot.getFileObject(indexJSP.replace('.', '/'), "jsp"); // NOI18N
197
}
198     
199 }
200
Popular Tags