2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.earproject.ui.wizards;
44
import java.awt.Component;
46
import java.io.IOException;
47
import java.text.MessageFormat;
48
import java.util.HashSet;
50
import java.util.NoSuchElementException;
52
import javax.swing.JComponent;
53
import javax.swing.event.ChangeListener;
54
import org.netbeans.api.progress.ProgressHandle;
55
import org.netbeans.modules.j2ee.earproject.EarProjectGenerator;
56
import org.netbeans.modules.j2ee.earproject.ModuleType;
57
import org.netbeans.modules.j2ee.earproject.ui.FoldersListSettings;
58
import org.openide.WizardDescriptor;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.util.HelpCtx;
62
import org.openide.util.NbBundle;
65
* Wizard for importing a new Enterprise Application project.
68
public class ImportBlueprintEarWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
70
private static final long serialVersionUID = 1L;
72
static final String PROP_NAME_INDEX = "nameIndex"; //NOI18N
74
private transient int index;
75
private transient WizardDescriptor.Panel[] panels;
76
transient WizardDescriptor wiz;
78
private WizardDescriptor.Panel[] createPanels() {
79
return new WizardDescriptor.Panel[] {
80
new PanelConfigureProject(PROP_NAME_INDEX,
81
NbBundle.getBundle(ImportBlueprintEarWizardIterator.class),
82
new HelpCtx(this.getClass()), true),
83
new PanelModuleDetection()
87
private String[] createSteps() {
89
NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NWP1_ProjectTitleName"),
90
NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_IW_ApplicationModulesStep")
94
public Set<FileObject> instantiate() throws IOException {
95
assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator.";
99
public Set<FileObject> instantiate(ProgressHandle handle) throws IOException {
101
handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_CreatingProject"), 1);
103
File dirF = (File) wiz.getProperty(WizardProperties.PROJECT_DIR);
105
dirF = FileUtil.normalizeFile(dirF);
107
File srcF = (File) wiz.getProperty(WizardProperties.SOURCE_ROOT);
109
srcF = FileUtil.normalizeFile(srcF);
111
String name = (String) wiz.getProperty(WizardProperties.NAME);
112
String j2eeLevel = (String) wiz.getProperty(WizardProperties.J2EE_LEVEL);
113
// String contextPath = (String) wiz.getProperty(WizardProperties.CONTEXT_PATH);
114
String serverInstanceID = (String) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID);
115
String platformName = (String)wiz.getProperty(WizardProperties.JAVA_PLATFORM);
116
String sourceLevel = (String)wiz.getProperty(WizardProperties.SOURCE_LEVEL);
117
@SuppressWarnings("unchecked")
118
Map<FileObject, ModuleType> userModules = (Map<FileObject, ModuleType>)
119
wiz.getProperty(WizardProperties.USER_MODULES);
120
return testableInstantiate(platformName, sourceLevel, j2eeLevel, dirF,
121
srcF, serverInstanceID, name, userModules, handle);
124
/** <strong>Package private for unit test only</strong>. */
125
static Set<FileObject> testableInstantiate(final String platformName,
126
final String sourceLevel, final String j2eeLevel, final File dirF,
127
final File srcF, final String serverInstanceID, final String name,
128
final Map<FileObject, ModuleType> userModules, ProgressHandle handle) throws IOException {
130
EarProjectGenerator.importProject(dirF, srcF, name, j2eeLevel,
131
serverInstanceID, platformName, sourceLevel, userModules);
132
if (handle != null) {
136
FileObject dir = FileUtil.toFileObject(dirF);
138
// remember last used server
139
FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID);
140
Set<FileObject> resultSet = new HashSet<FileObject>();
143
NewEarProjectWizardIterator.setProjectChooserFolder(dirF);
145
if (handle != null) {
146
handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3);
149
// Returning set of FileObject of project diretory.
150
// Project will be open and set as main
154
public void initialize(WizardDescriptor wiz) {
157
panels = createPanels();
158
// Make sure list of steps is accurate.
159
String[] steps = createSteps();
160
for (int i = 0; i < panels.length; i++) {
161
Component c = panels[i].getComponent();
162
if (steps[i] == null) {
163
// Default step name to component name of panel.
164
// Mainly useful for getting the name of the target
165
// chooser to appear in the list of steps.
166
steps[i] = c.getName();
168
if (c instanceof JComponent) { // assume Swing components
169
JComponent jc = (JComponent)c;
171
jc.putClientProperty("WizardPanel_contentSelectedIndex", i); // NOI18N
172
// Step name (actually the whole list for reference).
173
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
178
public void uninitialize(WizardDescriptor wiz) {
179
if (this.wiz != null) {
180
this.wiz.putProperty(WizardProperties.PROJECT_DIR,null);
181
this.wiz.putProperty(WizardProperties.NAME,null);
187
public String name() {
188
return MessageFormat.format(
189
NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_WizardStepsCount"),
190
index + 1, panels.length);
193
public boolean hasNext() {
194
return index < panels.length - 1;
197
public boolean hasPrevious() {
201
public void nextPanel() {
203
throw new NoSuchElementException();
208
public void previousPanel() {
209
if (!hasPrevious()) {
210
throw new NoSuchElementException();
215
public WizardDescriptor.Panel current() {
216
return panels[index];
219
// If nothing unusual changes in the middle of the wizard, simply:
220
public final void addChangeListener(ChangeListener l) {}
221
public final void removeChangeListener(ChangeListener l) {}
223
// helper methods, finds indexJSP's FileObject
224
FileObject getIndexJSPFO(FileObject webRoot, String indexJSP) {
225
// XXX: ignore unvalid mainClass?
226
return webRoot.getFileObject(indexJSP.replace('.', '/'), "jsp"); // NOI18N