1 19 20 package org.netbeans.modules.j2ee.earproject.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.Map ; 28 import java.util.NoSuchElementException ; 29 import java.util.Set ; 30 import javax.swing.JComponent ; 31 import javax.swing.event.ChangeListener ; 32 import org.netbeans.api.progress.ProgressHandle; 33 import org.netbeans.modules.j2ee.earproject.EarProjectGenerator; 34 import org.netbeans.modules.j2ee.earproject.ModuleType; 35 import org.netbeans.modules.j2ee.earproject.ui.FoldersListSettings; 36 import org.openide.WizardDescriptor; 37 import org.openide.filesystems.FileObject; 38 import org.openide.filesystems.FileUtil; 39 import org.openide.util.HelpCtx; 40 import org.openide.util.NbBundle; 41 42 46 public class ImportBlueprintEarWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator { 47 48 private static final long serialVersionUID = 1L; 49 50 static final String PROP_NAME_INDEX = "nameIndex"; 52 private transient int index; 53 private transient WizardDescriptor.Panel[] panels; 54 transient WizardDescriptor wiz; 55 56 private WizardDescriptor.Panel[] createPanels() { 57 return new WizardDescriptor.Panel[] { 58 new PanelConfigureProject(PROP_NAME_INDEX, 59 NbBundle.getBundle(ImportBlueprintEarWizardIterator.class), 60 new HelpCtx(this.getClass()), true), 61 new PanelModuleDetection() 62 }; 63 } 64 65 private String [] createSteps() { 66 return new String [] { 67 NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NWP1_ProjectTitleName"), 68 NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_IW_ApplicationModulesStep") 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(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_CreatingProject"), 1); 80 81 File dirF = (File ) wiz.getProperty(WizardProperties.PROJECT_DIR); 82 File srcF = (File ) wiz.getProperty(WizardProperties.SOURCE_ROOT); 83 String name = (String ) wiz.getProperty(WizardProperties.NAME); 84 String j2eeLevel = (String ) wiz.getProperty(WizardProperties.J2EE_LEVEL); 85 String serverInstanceID = (String ) wiz.getProperty(WizardProperties.SERVER_INSTANCE_ID); 87 String platformName = (String )wiz.getProperty(WizardProperties.JAVA_PLATFORM); 88 String sourceLevel = (String )wiz.getProperty(WizardProperties.SOURCE_LEVEL); 89 @SuppressWarnings ("unchecked") 90 Map <FileObject, ModuleType> userModules = (Map <FileObject, ModuleType>) 91 wiz.getProperty(WizardProperties.USER_MODULES); 92 return testableInstantiate(platformName, sourceLevel, j2eeLevel, dirF, 93 srcF, serverInstanceID, name, userModules, handle); 94 } 95 96 97 static Set <FileObject> testableInstantiate(final String platformName, 98 final String sourceLevel, final String j2eeLevel, final File dirF, 99 final File srcF, final String serverInstanceID, final String name, 100 final Map <FileObject, ModuleType> userModules, ProgressHandle handle) throws IOException { 101 102 EarProjectGenerator.importProject(dirF, srcF, name, j2eeLevel, 103 serverInstanceID, platformName, sourceLevel, userModules); 104 if (handle != null) 105 handle.progress(2); 106 107 FileObject dir = FileUtil.toFileObject(FileUtil.normalizeFile(dirF)); 108 109 FoldersListSettings.getDefault().setLastUsedServer(serverInstanceID); 111 Set <FileObject> resultSet = new HashSet <FileObject>(); 112 resultSet.add(dir); 113 114 NewEarProjectWizardIterator.setProjectChooserFolder(dirF); 115 116 if (handle != null) 117 handle.progress(NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_NewEarProjectWizardIterator_WizardProgress_PreparingToOpen"), 3); 118 119 return resultSet; 122 } 123 124 public void initialize(WizardDescriptor wiz) { 125 this.wiz = wiz; 126 index = 0; 127 panels = createPanels(); 128 String [] steps = createSteps(); 130 for (int i = 0; i < panels.length; i++) { 131 Component c = panels[i].getComponent(); 132 if (steps[i] == null) { 133 steps[i] = c.getName(); 137 } 138 if (c instanceof JComponent ) { JComponent jc = (JComponent )c; 140 jc.putClientProperty("WizardPanel_contentSelectedIndex", i); jc.putClientProperty("WizardPanel_contentData", steps); } 145 } 146 } 147 148 public void uninitialize(WizardDescriptor wiz) { 149 if (this.wiz != null) { 150 this.wiz.putProperty(WizardProperties.PROJECT_DIR,null); 151 this.wiz.putProperty(WizardProperties.NAME,null); 152 } 153 this.wiz = null; 154 panels = null; 155 } 156 157 public String name() { 158 return MessageFormat.format( 159 NbBundle.getMessage(ImportBlueprintEarWizardIterator.class, "LBL_WizardStepsCount"), 160 index + 1, panels.length); 161 } 162 163 public boolean hasNext() { 164 return index < panels.length - 1; 165 } 166 167 public boolean hasPrevious() { 168 return index > 0; 169 } 170 171 public void nextPanel() { 172 if (!hasNext()) { 173 throw new NoSuchElementException (); 174 } 175 index++; 176 } 177 178 public void previousPanel() { 179 if (!hasPrevious()) { 180 throw new NoSuchElementException (); 181 } 182 index--; 183 } 184 185 public WizardDescriptor.Panel current() { 186 return panels[index]; 187 } 188 189 public final void addChangeListener(ChangeListener l) {} 191 public final void removeChangeListener(ChangeListener l) {} 192 193 FileObject getIndexJSPFO(FileObject webRoot, String indexJSP) { 195 return webRoot.getFileObject(indexJSP.replace('.', '/'), "jsp"); } 198 199 } 200 | Popular Tags |