1 19 20 package org.netbeans.modules.j2ee.clientproject.ui.wizards; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.text.MessageFormat ; 26 import java.util.HashSet ; 27 import java.util.NoSuchElementException ; 28 import java.util.Set ; 29 import javax.swing.JComponent ; 30 import javax.swing.event.ChangeListener ; 31 import org.netbeans.api.progress.ProgressHandle; 32 import org.netbeans.api.project.Project; 33 import org.netbeans.api.project.ProjectManager; 34 import org.netbeans.modules.j2ee.api.ejbjar.Ear; 35 import org.netbeans.modules.j2ee.clientproject.AppClientProject; 36 import org.netbeans.modules.j2ee.clientproject.api.AppClientProjectGenerator; 37 import org.netbeans.modules.j2ee.clientproject.ui.FoldersListSettings; 38 import org.netbeans.spi.project.support.ant.AntProjectHelper; 39 import org.netbeans.spi.project.ui.support.ProjectChooser; 40 import org.openide.ErrorManager; 41 import org.openide.WizardDescriptor; 42 import org.openide.filesystems.FileObject; 43 import org.openide.filesystems.FileUtil; 44 import org.openide.util.NbBundle; 45 46 49 public class NewAppClientProjectWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { 50 51 static final String PROP_NAME_INDEX = "nameIndex"; 53 private static final long serialVersionUID = 1L; 54 55 public static NewAppClientProjectWizardIterator library() { 56 return new NewAppClientProjectWizardIterator(); 57 } 58 59 private WizardDescriptor.Panel[] createPanels() { 60 return new WizardDescriptor.Panel[] { 61 new PanelConfigureProject() 62 }; 63 } 64 65 private String [] createSteps() { 66 return new String [] { 67 NbBundle.getMessage(NewAppClientProjectWizardIterator.class,"LAB_ConfigureProject"), 68 }; 69 } 70 71 72 public Set <FileObject> instantiate() throws IOException { 73 assert false : "This method cannot be called if the class implements WizardDescriptor.ProgressInstantiatingIterator."; 74 return null; 75 } 76 77 public Set <FileObject> instantiate(ProgressHandle handle) throws IOException { 78 handle.start(3); 79 handle.progress(NbBundle.getMessage(NewAppClientProjectWizardIterator.class, "LBL_NewAppClientProjectWizardIterator_WizardProgress_CreatingProject"), 1); 80 81 Set <FileObject> resultSet = new HashSet <FileObject>(); 82 File dirF = (File )wiz.getProperty(WizardProperties.PROJECT_DIR); 83 if (dirF != null) { 84 dirF = FileUtil.normalizeFile(dirF); 85 } 86 String name = (String )wiz.getProperty(WizardProperties.NAME); 87 String mainClass = (String )wiz.getProperty(WizardProperties.MAIN_CLASS); 88 89 String serverInstanceID = (String ) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID); 90 String j2eeLevel = (String ) wiz.getProperty(WizardProperties.J2EE_LEVEL); 91 92 AntProjectHelper h = AppClientProjectGenerator.createProject(dirF, name, mainClass, j2eeLevel, serverInstanceID); 93 handle.progress(2); 94 95 if (mainClass != null && mainClass.length() > 0) { 96 try { 97 FileObject sourcesRoot = h.getProjectDirectory().getFileObject("src/java"); FileObject mainClassFo = getMainClassFO(sourcesRoot, mainClass); 100 assert mainClassFo != null : "sourcesRoot: " + sourcesRoot + ", mainClass: " + mainClass; resultSet.add(mainClassFo); 103 } catch (Exception x) { 104 ErrorManager.getDefault().notify(x); 105 } 106 } 107 FileObject dir = FileUtil.toFileObject(dirF); 108 109 Project earProject = (Project) wiz.getProperty(WizardProperties.EAR_APPLICATION); 110 AppClientProject createdAppClientProject = (AppClientProject) ProjectManager.getDefault().findProject(dir); 111 if (earProject != null && createdAppClientProject != null) { 112 Ear ear = Ear.getEar(earProject.getProjectDirectory()); 113 if (ear != null) { 114 ear.addCarModule(createdAppClientProject.getAPICar()); 115 } 116 } 117 118 FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID); 120 121 String platformName = (String )wiz.getProperty(WizardProperties.JAVA_PLATFORM); 123 String sourceLevel = (String )wiz.getProperty(WizardProperties.SOURCE_LEVEL); 124 if (platformName != null || sourceLevel != null) { 125 AppClientProjectGenerator.setPlatform(h, platformName, sourceLevel); 126 } 127 128 Integer index = (Integer ) wiz.getProperty(PROP_NAME_INDEX); 131 FoldersListSettings.getDefault().setNewApplicationCount(index.intValue()); 132 resultSet.add(dir); 133 134 dirF = (dirF != null) ? dirF.getParentFile() : null; 135 if (dirF != null && dirF.exists()) { 136 ProjectChooser.setProjectsFolder(dirF); 137 } 138 139 handle.progress(NbBundle.getMessage(NewAppClientProjectWizardIterator.class, "LBL_NewAppClientProjectWizardIterator_WizardProgress_PreparingToOpen"), 3); 140 141 return resultSet; 142 } 143 144 145 private transient int index; 146 private transient WizardDescriptor.Panel[] panels; 147 private transient WizardDescriptor wiz; 148 149 public void initialize(WizardDescriptor wiz) { 150 this.wiz = wiz; 151 index = 0; 152 panels = createPanels(); 153 String [] steps = createSteps(); 155 for (int i = 0; i < panels.length; i++) { 156 Component c = panels[i].getComponent(); 157 if (steps[i] == null) { 158 steps[i] = c.getName(); 162 } 163 if (c instanceof JComponent ) { JComponent jc = (JComponent )c; 165 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); } 170 } 171 this.wiz.putProperty(WizardProperties.SOURCE_ROOT, new File [0]); 173 this.wiz.putProperty(WizardProperties.TEST_ROOT, new File [0]); 174 } 175 176 public void uninitialize(WizardDescriptor wiz) { 177 if (this.wiz != null) { this.wiz.putProperty(WizardProperties.PROJECT_DIR, null); 179 this.wiz.putProperty(WizardProperties.NAME, null); 180 this.wiz.putProperty(WizardProperties.MAIN_CLASS, null); 181 this.wiz = null; 182 } 183 panels = null; 184 } 185 186 public String name() { 187 return MessageFormat.format(NbBundle.getMessage(NewAppClientProjectWizardIterator.class,"LAB_IteratorName"), 188 new Object [] {new Integer (index + 1), new Integer (panels.length) }); 189 } 190 191 public boolean hasNext() { 192 return index < panels.length - 1; 193 } 194 public boolean hasPrevious() { 195 return index > 0; 196 } 197 public void nextPanel() { 198 if (!hasNext()) throw new NoSuchElementException (); 199 index++; 200 } 201 public void previousPanel() { 202 if (!hasPrevious()) throw new NoSuchElementException (); 203 index--; 204 } 205 public WizardDescriptor.Panel current() { 206 return panels[index]; 207 } 208 209 public final void addChangeListener(ChangeListener l) {} 211 public final void removeChangeListener(ChangeListener l) {} 212 213 private FileObject getMainClassFO(FileObject sourcesRoot, String mainClass) { 215 mainClass = mainClass.replace('.', '/'); 217 218 220 return sourcesRoot.getFileObject(mainClass+ ".java"); } 222 223 static String getPackageName(String displayName) { 224 StringBuffer builder = new StringBuffer (); 225 boolean firstLetter = true; 226 for (int i=0; i< displayName.length(); i++) { 227 char c = displayName.charAt(i); 228 if ((!firstLetter && Character.isJavaIdentifierPart(c)) || (firstLetter && Character.isJavaIdentifierStart(c))) { 229 firstLetter = false; 230 if (Character.isUpperCase(c)) { 231 c = Character.toLowerCase(c); 232 } 233 builder.append(c); 234 } 235 } 236 return builder.length() == 0 ? NbBundle.getMessage(NewAppClientProjectWizardIterator.class,"TXT_DefaultPackageName") : builder.toString(); 237 } 238 239 } 240 | Popular Tags |