KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > ui > wizards > ImportAppClientProjectWizardIterator


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.clientproject.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.NoSuchElementException JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.api.progress.ProgressHandle;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.api.project.ProjectManager;
32 import org.netbeans.modules.j2ee.api.ejbjar.Ear;
33 import org.netbeans.modules.j2ee.clientproject.AppClientProject;
34 import org.netbeans.modules.j2ee.clientproject.Utils;
35 import org.netbeans.modules.j2ee.clientproject.api.AppClientProjectGenerator;
36 import org.netbeans.modules.j2ee.clientproject.ui.FoldersListSettings;
37 import org.netbeans.spi.project.support.ant.AntProjectHelper;
38 import org.netbeans.spi.project.ui.support.ProjectChooser;
39 import org.openide.WizardDescriptor;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileUtil;
42 import org.openide.util.NbBundle;
43
44 /**
45  * Wizard to create a new Application Client project for an existing one.
46  * @author Pavel Buzek
47  */

48 public class ImportAppClientProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
49     
50     private static final long serialVersionUID = 1L;
51 // private boolean imp = true;
52

53     // Make sure list of steps is accurate.
54
private static final String JavaDoc[] STEPS = new String JavaDoc[]{
55         NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LBL_IW_ImportTitle"), //NOI18N
56
NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LAB_ConfigureSourceRoots") //NOI18N
57
};
58     
59     private WizardDescriptor.Panel[] createPanels() {
60         return new WizardDescriptor.Panel[] {
61             new ImportLocation(),
62             new PanelSourceFolders.Panel()
63         };
64     }
65
66     public Set JavaDoc<FileObject> instantiate() throws IOException JavaDoc/*, IllegalStateException*/ {
67         assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator.";
68         return null;
69     }
70         
71     public Set JavaDoc<FileObject> instantiate(ProgressHandle handle) throws IOException JavaDoc {
72         handle.start(3);
73         handle.progress(NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LBL_NewAppClientProjectWizardIterator_WizardProgress_CreatingProject"), 1);
74         
75         Set JavaDoc<FileObject> resultSet = new HashSet JavaDoc<FileObject>();
76         File JavaDoc dirF = (File JavaDoc) wiz.getProperty(WizardProperties.PROJECT_DIR);
77         if (dirF != null) {
78             dirF = FileUtil.normalizeFile(dirF);
79         }
80         String JavaDoc name = (String JavaDoc) wiz.getProperty(WizardProperties.NAME);
81 // File dirSrcF = (File) wiz.getProperty (WizardProperties.SOURCE_ROOT);
82
File JavaDoc[] sourceFolders = (File JavaDoc[]) wiz.getProperty(WizardProperties.JAVA_ROOT);
83         File JavaDoc[] testFolders = (File JavaDoc[]) wiz.getProperty(WizardProperties.TEST_ROOT);
84         File JavaDoc configFilesFolder = (File JavaDoc) wiz.getProperty(WizardProperties.CONFIG_FILES_FOLDER);
85         File JavaDoc libName = (File JavaDoc) wiz.getProperty(WizardProperties.LIB_FOLDER);
86         String JavaDoc serverInstanceID = (String JavaDoc) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID);
87         String JavaDoc j2eeLevel = (String JavaDoc) wiz.getProperty(WizardProperties.J2EE_LEVEL);
88         
89         AntProjectHelper h = AppClientProjectGenerator.importProject(dirF, name, sourceFolders, testFolders, configFilesFolder, libName, j2eeLevel, serverInstanceID);
90         handle.progress(2);
91         
92         FileObject dir = FileUtil.toFileObject (dirF);
93
94         Project earProject = (Project) wiz.getProperty(WizardProperties.EAR_APPLICATION);
95         AppClientProject createdAppClientProject = (AppClientProject) ProjectManager.getDefault().findProject(dir);
96         if (earProject != null && createdAppClientProject != null) {
97             Ear ear = Ear.getEar(earProject.getProjectDirectory());
98             if (ear != null) {
99                 ear.addCarModule(createdAppClientProject.getAPICar());
100             }
101         }
102         
103         resultSet.add (dir);
104
105         dirF = (dirF != null) ? dirF.getParentFile() : null;
106         if (dirF != null && dirF.exists()) {
107             ProjectChooser.setProjectsFolder (dirF);
108         }
109         
110         // remember last used server
111
FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID);
112         
113         // downgrade the Java platform or src level to 1.4
114
String JavaDoc platformName = (String JavaDoc)wiz.getProperty(WizardProperties.JAVA_PLATFORM);
115         String JavaDoc sourceLevel = (String JavaDoc)wiz.getProperty(WizardProperties.SOURCE_LEVEL);
116         if (platformName != null || sourceLevel != null) {
117             AppClientProjectGenerator.setPlatform(h, platformName, sourceLevel);
118         }
119                 
120         handle.progress(NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LBL_NewAppClientProjectWizardIterator_WizardProgress_PreparingToOpen"), 3);
121         
122         return resultSet;
123     }
124     
125     private transient int index;
126     private transient WizardDescriptor.Panel[] panels;
127     private transient WizardDescriptor wiz;
128     
129     public void initialize(WizardDescriptor wiz) {
130         this.wiz = wiz;
131         index = 0;
132         panels = createPanels();
133         Utils.setSteps(panels, STEPS);
134     }
135
136     public void uninitialize(WizardDescriptor wiz) {
137         this.wiz.putProperty(WizardProperties.PROJECT_DIR, null);
138         this.wiz.putProperty(WizardProperties.NAME, null);
139         this.wiz.putProperty (WizardProperties.SOURCE_ROOT, null);
140         this.wiz.putProperty(WizardProperties.JAVA_ROOT, null);
141         this.wiz.putProperty(WizardProperties.TEST_ROOT, null);
142         this.wiz.putProperty(WizardProperties.CONFIG_FILES_FOLDER, null);
143         this.wiz.putProperty(WizardProperties.LIB_FOLDER, null);
144         this.wiz.putProperty(WizardProperties.SERVER_INSTANCE_ID, null);
145         this.wiz.putProperty(WizardProperties.J2EE_LEVEL, null);
146         this.wiz = null;
147         panels = null;
148     }
149     
150     public String JavaDoc name() {
151         return MessageFormat.format(
152                 NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LBL_WizardStepsCount"),
153                 index + 1, panels.length);
154     }
155     
156     public boolean hasNext() {
157         return index < panels.length - 1;
158     }
159     public boolean hasPrevious() {
160         return index > 0;
161     }
162     public void nextPanel() {
163         if (!hasNext()) {
164             throw new NoSuchElementException JavaDoc();
165         }
166         index++;
167     }
168     public void previousPanel() {
169         if (!hasPrevious()) {
170             throw new NoSuchElementException JavaDoc();
171         }
172         index--;
173     }
174     public WizardDescriptor.Panel current() {
175         return panels[index];
176     }
177     
178     // If nothing unusual changes in the middle of the wizard, simply:
179
public final void addChangeListener(ChangeListener JavaDoc l) {}
180     public final void removeChangeListener(ChangeListener JavaDoc l) {}
181     
182 }
183
184
Popular Tags