1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.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 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.api.progress.ProgressHandle; 31 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings; 32 import org.netbeans.spi.project.ui.support.ProjectChooser; 33 34 import org.openide.WizardDescriptor; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileUtil; 37 38 import org.netbeans.api.project.Project; 39 import org.netbeans.api.project.ProjectManager; 40 import org.netbeans.modules.j2ee.api.ejbjar.Ear; 41 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 42 import org.openide.util.NbBundle; 43 44 import org.netbeans.modules.j2ee.ejbjarproject.api.EjbJarProjectGenerator; 45 import org.netbeans.modules.j2ee.ejbjarproject.Utils; 46 import org.netbeans.spi.project.support.ant.AntProjectHelper; 47 48 49 53 public class ImportEjbJarProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { 54 55 private static final long serialVersionUID = 1L; 56 58 private static final String [] STEPS = new String []{ 60 NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_IW_ImportTitle"), NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LAB_ConfigureSourceRoots") }; 63 64 65 public ImportEjbJarProjectWizardIterator() {} 66 67 private WizardDescriptor.Panel[] createPanels() { 68 return new WizardDescriptor.Panel[] { 69 new ImportLocation(), 70 new PanelSourceFolders.Panel() 71 }; 72 } 73 74 public Set instantiate() throws IOException { 75 assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator."; 76 return null; 77 } 78 79 public Set <FileObject> instantiate(ProgressHandle handle) throws IOException { 80 handle.start(3); 81 handle.progress(NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_CreatingProject"), 1); 82 83 Set resultSet = new HashSet (); 84 File dirF = (File ) wiz.getProperty(WizardProperties.PROJECT_DIR); 85 if (dirF != null) { 86 dirF = FileUtil.normalizeFile(dirF); 87 } 88 String name = (String ) wiz.getProperty(WizardProperties.NAME); 89 File [] sourceFolders = (File []) wiz.getProperty(WizardProperties.JAVA_ROOT); 90 File [] testFolders = (File []) wiz.getProperty(WizardProperties.TEST_ROOT); 91 File configFilesFolder = (File ) wiz.getProperty(WizardProperties.CONFIG_FILES_FOLDER); 92 File libName = (File ) wiz.getProperty(WizardProperties.LIB_FOLDER); 93 String serverInstanceID = (String ) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID); 94 String j2eeLevel = (String ) wiz.getProperty(WizardProperties.J2EE_LEVEL); 95 96 AntProjectHelper h = EjbJarProjectGenerator.importProject(dirF, name, sourceFolders, testFolders, configFilesFolder, libName, j2eeLevel, serverInstanceID); 97 handle.progress(2); 98 FileObject dir = FileUtil.toFileObject (dirF); 99 100 Project earProject = (Project) wiz.getProperty(WizardProperties.EAR_APPLICATION); 101 EjbJarProject createdEjbJarProject = (EjbJarProject) ProjectManager.getDefault().findProject(dir); 102 if (earProject != null && createdEjbJarProject != null) { 103 Ear ear = Ear.getEar(earProject.getProjectDirectory()); 104 if (ear != null) { 105 ear.addEjbJarModule(createdEjbJarProject.getAPIEjbJar()); 106 } 107 } 108 109 resultSet.add (dir); 110 111 dirF = (dirF != null) ? dirF.getParentFile() : null; 112 if (dirF != null && dirF.exists()) { 113 ProjectChooser.setProjectsFolder (dirF); 114 } 115 116 FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID); 118 119 String platformName = (String )wiz.getProperty(WizardProperties.JAVA_PLATFORM); 121 String sourceLevel = (String )wiz.getProperty(WizardProperties.SOURCE_LEVEL); 122 if (platformName != null || sourceLevel != null) { 123 EjbJarProjectGenerator.setPlatform(h, platformName, sourceLevel); 124 } 125 126 handle.progress(NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_NewEjbJarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3); 127 128 return resultSet; 129 } 130 131 private transient int index; 132 private transient WizardDescriptor.Panel[] panels; 133 private transient WizardDescriptor wiz; 134 135 public void initialize(WizardDescriptor wiz) { 136 this.wiz = wiz; 137 index = 0; 138 panels = createPanels(); 139 Utils.setSteps(panels, STEPS); 140 } 141 142 public void uninitialize(WizardDescriptor wiz) { 143 this.wiz.putProperty(WizardProperties.PROJECT_DIR, null); 144 this.wiz.putProperty(WizardProperties.NAME, null); 145 this.wiz.putProperty (WizardProperties.SOURCE_ROOT, null); 146 this.wiz.putProperty(WizardProperties.JAVA_ROOT, null); 147 this.wiz.putProperty(WizardProperties.TEST_ROOT, null); 148 this.wiz.putProperty(WizardProperties.CONFIG_FILES_FOLDER, null); 149 this.wiz.putProperty(WizardProperties.LIB_FOLDER, null); 150 this.wiz.putProperty(WizardProperties.SERVER_INSTANCE_ID, null); 151 this.wiz.putProperty(WizardProperties.J2EE_LEVEL, null); 152 this.wiz = null; 153 panels = null; 154 } 155 156 public String name() { 157 return MessageFormat.format(NbBundle.getMessage(ImportEjbJarProjectWizardIterator.class, "LBL_WizardStepsCount"), 158 new Object [] {(new Integer (index + 1)), (new Integer (panels.length))}); } 160 161 public boolean hasNext() { 162 return index < panels.length - 1; 163 } 164 public boolean hasPrevious() { 165 return index > 0; 166 } 167 public void nextPanel() { 168 if (!hasNext()) throw new NoSuchElementException (); 169 index++; 170 } 171 public void previousPanel() { 172 if (!hasPrevious()) throw new NoSuchElementException (); 173 index--; 174 } 175 public WizardDescriptor.Panel current() { 176 return panels[index]; 177 } 178 179 public final void addChangeListener(ChangeListener l) {} 181 public final void removeChangeListener(ChangeListener l) {} 182 } 183 | Popular Tags |