1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.HashSet ; 26 import java.util.NoSuchElementException ; 27 import java.util.Set ; 28 import javax.swing.JComponent ; 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.ui.OpenProjects; 32 import org.netbeans.modules.apisupport.project.NbModuleProjectGenerator; 33 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 34 import org.netbeans.modules.apisupport.project.suite.SuiteProjectGenerator; 35 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings; 36 import org.netbeans.modules.apisupport.project.ui.UIUtil; 37 import org.netbeans.modules.apisupport.project.ui.customizer.SuiteUtils; 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 49 public class NewNbModuleWizardIterator implements WizardDescriptor.AsynchronousInstantiatingIterator { 50 51 52 static final int TYPE_MODULE = 1; 53 54 55 static final int TYPE_SUITE = 2; 56 57 58 static final int TYPE_LIBRARY_MODULE = 3; 59 60 61 static final int TYPE_SUITE_COMPONENT = 4; 62 63 67 static final String PREFERRED_SUITE_DIR = "preferredSuiteDir"; 69 70 static final String ONE_SUITE_DEDICATED_MODE = "oneSuiteDedicatedMode"; 72 private final NewModuleProjectData data; 73 private int position; 74 private WizardDescriptor.Panel[] panels; 75 private FileObject createdProjectFolder; 76 77 78 private String preferredSuiteDir; 79 80 81 private Boolean suiteDedicated = Boolean.FALSE; 83 84 private NewNbModuleWizardIterator(int type) { 85 data = new NewModuleProjectData(type); 86 } 87 88 92 public static NewNbModuleWizardIterator createModuleIterator() { 93 return new NewNbModuleWizardIterator(TYPE_MODULE); 94 } 95 96 99 public static NewNbModuleWizardIterator createSuiteComponentIterator(final SuiteProject suite) { 100 NewNbModuleWizardIterator iterator = new NewNbModuleWizardIterator(TYPE_SUITE_COMPONENT); 101 iterator.preferredSuiteDir = suite.getProjectDirectoryFile().getAbsolutePath(); 102 iterator.suiteDedicated = Boolean.TRUE; 103 return iterator; 104 } 105 106 public static NewNbModuleWizardIterator createSuiteIterator() { 107 return new NewNbModuleWizardIterator(TYPE_SUITE); 108 } 109 110 115 public static NewNbModuleWizardIterator createLibraryModuleIterator(final Project project) { 116 NewNbModuleWizardIterator iterator = new NewNbModuleWizardIterator(TYPE_LIBRARY_MODULE); 117 iterator.preferredSuiteDir = SuiteUtils.getSuiteDirectoryPath(project); 118 assert iterator.preferredSuiteDir != null : project + " does not have a SuiteProvider in its lookup?"; iterator.suiteDedicated = Boolean.TRUE; 120 return iterator; 121 } 122 123 public static NewNbModuleWizardIterator createLibraryModuleIterator() { 124 return new NewNbModuleWizardIterator(TYPE_LIBRARY_MODULE); 125 } 126 127 public FileObject getCreateProjectFolder() { 128 return createdProjectFolder; 129 } 130 131 public Set instantiate() throws IOException { 132 final File projectFolder = new File (data.getProjectFolder()); 133 ProjectChooser.setProjectsFolder(new File (data.getProjectLocation())); 134 ModuleUISettings.getDefault().setLastUsedPlatformID(data.getPlatformID()); 135 WizardDescriptor settings = data.getSettings(); 136 switch (data.getWizardType()) { 137 case NewNbModuleWizardIterator.TYPE_SUITE: 138 ModuleUISettings.getDefault().setNewSuiteCounter(data.getSuiteCounter()); 139 SuiteProjectGenerator.createSuiteProject(projectFolder, data.getPlatformID()); 140 break; 141 case NewNbModuleWizardIterator.TYPE_MODULE: 142 case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT: 143 ModuleUISettings.getDefault().setNewModuleCounter(data.getModuleCounter()); 144 if (data.isNetBeansOrg()) { 145 NbModuleProjectGenerator.createNetBeansOrgModule(projectFolder, 147 data.getCodeNameBase(), data.getProjectDisplayName(), 148 data.getBundle(), data.getLayer()); 149 } else if (data.isStandalone()) { 150 NbModuleProjectGenerator.createStandAloneModule(projectFolder, 152 data.getCodeNameBase(), data.getProjectDisplayName(), 153 data.getBundle(), data.getLayer(), data.getPlatformID()); 154 } else { 155 NbModuleProjectGenerator.createSuiteComponentModule(projectFolder, 157 data.getCodeNameBase(), data.getProjectDisplayName(), 158 data.getBundle(), data.getLayer(), new File (data.getSuiteRoot())); 159 } 160 break; 161 case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE: 162 File [] jars = LibraryStartVisualPanel.convertStringToFiles((String ) settings.getProperty(LibraryStartVisualPanel.PROP_LIBRARY_PATH)); 164 165 File license = null; 166 String licPath = (String ) settings.getProperty(LibraryStartVisualPanel.PROP_LICENSE_PATH); 167 if (licPath != null && licPath.length() > 0) { 168 license = new File (licPath); 169 } 170 NbModuleProjectGenerator.createSuiteLibraryModule(projectFolder, 171 data.getCodeNameBase(), data.getProjectDisplayName(), 172 data.getBundle(), new File (data.getSuiteRoot()), 173 license, jars); 174 break; 175 default: 176 throw new IllegalStateException ("Uknown wizard type: " + data.getWizardType()); } 178 179 this.createdProjectFolder = FileUtil.toFileObject(FileUtil.normalizeFile(projectFolder)); 180 181 Set <FileObject> resultSet = new HashSet (); 182 resultSet.add(createdProjectFolder); 183 184 UIUtil.setProjectChooserDirParent(projectFolder); 185 186 settings.putProperty("setAsMain", Boolean.valueOf(data.isMainProject())); 189 return resultSet; 190 } 191 192 public void initialize(WizardDescriptor wiz) { 193 data.setSettings(wiz); 194 if (preferredSuiteDir == null) { 195 Project mainPrj = OpenProjects.getDefault().getMainProject(); 196 if (mainPrj != null) { 197 preferredSuiteDir = SuiteUtils.getSuiteDirectoryPath(mainPrj); 198 } 199 } 200 if (preferredSuiteDir != null) { 201 wiz.putProperty(PREFERRED_SUITE_DIR, preferredSuiteDir); 202 wiz.putProperty(ONE_SUITE_DEDICATED_MODE, suiteDedicated); 203 } 204 205 position = 0; 206 String [] steps = null; 207 switch (data.getWizardType()) { 208 case TYPE_MODULE: 209 steps = initModuleWizard(); 210 break; 211 case TYPE_SUITE_COMPONENT: 212 steps = initModuleWizard(); 213 break; 214 case TYPE_SUITE: 215 steps = initSuiteModuleWizard(); 216 break; 217 case TYPE_LIBRARY_MODULE: 218 steps = initLibraryModuleWizard(); 219 break; 220 default: 221 assert false : "Should never get here. type: " + data.getWizardType(); 222 } 223 for (int i = 0; i < panels.length; i++) { 224 Component c = panels[i].getComponent(); 225 if (c instanceof JComponent ) { JComponent jc = (JComponent ) c; 227 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); 232 jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); } 240 } 241 } 242 243 public void uninitialize(WizardDescriptor wiz) { 244 panels = null; 245 } 246 247 private String [] initModuleWizard() { 248 panels = new WizardDescriptor.Panel[] { 249 new BasicInfoWizardPanel(data), 250 new BasicConfWizardPanel(data) 251 }; 252 String [] steps = new String [] { 253 getMessage("LBL_BasicInfoPanel_Title"), getMessage("LBL_BasicConfigPanel_Title") }; 256 return steps; 257 } 258 259 private String [] initSuiteModuleWizard() { 260 panels = new WizardDescriptor.Panel[] { 261 new BasicInfoWizardPanel(data), 262 }; 263 String [] steps = new String [] { 264 getMessage("LBL_BasicInfoPanel_Title"), }; 266 return steps; 267 } 268 269 private String [] initLibraryModuleWizard() { 270 panels = new WizardDescriptor.Panel[] { 271 new LibraryStartWizardPanel(data), 272 new BasicInfoWizardPanel(data), 273 new LibraryConfWizardPanel(data) 274 }; 275 String [] steps = new String [] { 276 getMessage("LBL_LibraryStartPanel_Title"), getMessage("LBL_BasicInfoPanel_Title"), getMessage("LBL_PlatformSelectionPanel_Title") }; 280 return steps; 281 } 282 283 public String name() { 284 return ""; 289 } 290 291 public boolean hasNext() { 292 return position < (panels.length - 1); 293 } 294 295 public boolean hasPrevious() { 296 return position > 0; 297 } 298 299 public void nextPanel() { 300 if (!hasNext()) { 301 throw new NoSuchElementException (); 302 } 303 position++; 304 } 305 306 public void previousPanel() { 307 if (!hasPrevious()) { 308 throw new NoSuchElementException (); 309 } 310 position--; 311 } 312 313 public WizardDescriptor.Panel current() { 314 return panels[position]; 315 } 316 317 320 static String getMessage(String key) { 321 return NbBundle.getMessage(NewNbModuleWizardIterator.class, key); 322 } 323 324 public final void addChangeListener(ChangeListener l) {} 326 public final void removeChangeListener(ChangeListener l) {} 327 328 } 329 | Popular Tags |