1 19 20 package org.netbeans.modules.j2ee.clientproject.ui.wizards; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.text.MessageFormat ; 25 import java.util.HashSet ; 26 import java.util.NoSuchElementException ; 27 import java.util.Set ; 28 import javax.swing.event.ChangeListener ; 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 48 public class ImportAppClientProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { 49 50 private static final long serialVersionUID = 1L; 51 53 private static final String [] STEPS = new String []{ 55 NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LBL_IW_ImportTitle"), NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LAB_ConfigureSourceRoots") }; 58 59 private WizardDescriptor.Panel[] createPanels() { 60 return new WizardDescriptor.Panel[] { 61 new ImportLocation(), 62 new PanelSourceFolders.Panel() 63 }; 64 } 65 66 public Set <FileObject> instantiate() throws IOException { 67 assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator."; 68 return null; 69 } 70 71 public Set <FileObject> instantiate(ProgressHandle handle) throws IOException { 72 handle.start(3); 73 handle.progress(NbBundle.getMessage(ImportAppClientProjectWizardIterator.class, "LBL_NewAppClientProjectWizardIterator_WizardProgress_CreatingProject"), 1); 74 75 Set <FileObject> resultSet = new HashSet <FileObject>(); 76 File dirF = (File ) wiz.getProperty(WizardProperties.PROJECT_DIR); 77 if (dirF != null) { 78 dirF = FileUtil.normalizeFile(dirF); 79 } 80 String name = (String ) wiz.getProperty(WizardProperties.NAME); 81 File [] sourceFolders = (File []) wiz.getProperty(WizardProperties.JAVA_ROOT); 83 File [] testFolders = (File []) wiz.getProperty(WizardProperties.TEST_ROOT); 84 File configFilesFolder = (File ) wiz.getProperty(WizardProperties.CONFIG_FILES_FOLDER); 85 File libName = (File ) wiz.getProperty(WizardProperties.LIB_FOLDER); 86 String serverInstanceID = (String ) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID); 87 String j2eeLevel = (String ) 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 FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID); 112 113 String platformName = (String )wiz.getProperty(WizardProperties.JAVA_PLATFORM); 115 String sourceLevel = (String )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 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 (); 165 } 166 index++; 167 } 168 public void previousPanel() { 169 if (!hasPrevious()) { 170 throw new NoSuchElementException (); 171 } 172 index--; 173 } 174 public WizardDescriptor.Panel current() { 175 return panels[index]; 176 } 177 178 public final void addChangeListener(ChangeListener l) {} 180 public final void removeChangeListener(ChangeListener l) {} 181 182 } 183 184 | Popular Tags |