1 19 20 package org.netbeans.modules.java.platform.wizard; 21 22 import java.io.IOException ; 23 import java.util.*; 24 import javax.swing.JComponent ; 25 import javax.swing.event.*; 26 import org.netbeans.modules.java.platform.InstallerRegistry; 27 import org.netbeans.spi.java.platform.CustomPlatformInstall; 28 import org.netbeans.spi.java.platform.GeneralPlatformInstall; 29 import org.netbeans.spi.java.platform.PlatformInstall; 30 31 import org.openide.loaders.*; 32 import org.openide.util.NbBundle; 33 import org.openide.WizardDescriptor; 34 35 39 public class PlatformInstallIterator implements WizardDescriptor.InstantiatingIterator, ChangeListener { 40 41 WizardDescriptor.InstantiatingIterator typeIterator; 42 int panelIndex; boolean hasSelectorPanel; 44 WizardDescriptor wizard; 45 int panelNumber = -1; 46 47 ResourceBundle bundle = NbBundle.getBundle(PlatformInstallIterator.class); 48 LocationChooser.Panel locationPanel = new LocationChooser.Panel(); 49 SelectorPanel.Panel selectorPanel = new SelectorPanel.Panel (); 50 Collection listeners = new ArrayList(); 51 52 PlatformInstallIterator() { 53 selectorPanel.addChangeListener(this); 54 locationPanel.addChangeListener(this); 55 } 56 57 public static PlatformInstallIterator create() { 58 return new PlatformInstallIterator(); 59 } 60 61 62 66 int getPanelIndex () { 67 return this.panelIndex; 68 } 69 70 void updatePanelsList (JComponent [] where) { 71 Collection c = new LinkedList(); 72 if (this.hasSelectorPanel) { 73 c.add (bundle.getString("TXT_SelectPlatformTypeTitle")); 74 } 75 if (this.panelIndex == 1 || this.panelIndex == 2 || 76 (this.panelIndex == 0 && this.selectorPanel.getInstallerIterator()==null)) { 77 c.add(bundle.getString("TXT_PlatformFolderTitle")); } 79 if (typeIterator != null) { 80 WizardDescriptor.Panel p = typeIterator.current(); 82 if (p != null) { 83 javax.swing.JComponent pc = (javax.swing.JComponent )p.getComponent(); 84 String [] steps = (String [])pc.getClientProperty("WizardPanel_contentData"); if (steps != null) 86 c.addAll(Arrays.asList(steps)); 87 } 88 } else { 89 c.add(bundle.getString("TITLE_PlatformLocationUnknown")); } 91 String [] names = (String [])c.toArray(new String [c.size()]); 92 for (int i=0; i< where.length; i++) { 93 where[i].putClientProperty("WizardPanel_contentData",names); } 95 } 96 97 public void addChangeListener(ChangeListener l) { 98 listeners.add(l); 99 } 100 101 public WizardDescriptor.Panel current() { 102 if (panelIndex == 0) { 103 return selectorPanel; 104 } 105 else if (panelIndex == 1) { 106 return locationPanel; 107 } else { 108 return typeIterator.current(); 109 } 110 } 111 112 118 public boolean hasNext() { 119 if (panelIndex == 0) { 120 WizardDescriptor.InstantiatingIterator typeIt = this.selectorPanel.getInstallerIterator(); 121 if (typeIt == null) { 123 return true; 124 } 125 else { 126 return typeIt.current() != null; 127 } 128 } 129 else if (panelIndex == 1) { 130 WizardDescriptor.InstantiatingIterator typeIt = locationPanel.getInstallerIterator(); 131 if (typeIt == null) { 132 return false; 133 } else { 134 WizardDescriptor.Panel p = typeIt.current(); 135 return p != null; 136 } 137 } else { 138 return this.typeIterator.hasNext(); 139 } 140 } 141 142 public boolean hasPrevious() { 143 return this.panelIndex != 0 && 144 !(this.panelIndex == 1 && !hasSelectorPanel) && 145 !(this.panelIndex == 3 && !hasSelectorPanel && this.typeIterator != null && !this.typeIterator.hasPrevious()); 146 } 147 148 public void initialize(WizardDescriptor wiz) { 149 this.wizard = wiz; 150 List installers = InstallerRegistry.getDefault().getAllInstallers(); 151 if (installers.size()>1) { 152 panelIndex = 0; 153 hasSelectorPanel = true; 154 } 155 else { 156 if (installers.get(0) instanceof CustomPlatformInstall) { 157 panelIndex = 3; 158 hasSelectorPanel = false; 159 this.typeIterator = ((CustomPlatformInstall) installers.get(0)).createIterator(); 160 } 161 else { 162 panelIndex = 1; 163 hasSelectorPanel = false; 164 this.locationPanel.setPlatformInstall((PlatformInstall) installers.get(0)); 165 } 166 } 167 updatePanelsList(new JComponent []{((JComponent )current().getComponent())}); 168 this.wizard.setTitle(NbBundle.getMessage(PlatformInstallIterator.class,"TXT_AddPlatformTitle")); 169 panelNumber = 0; 170 wizard.putProperty("WizardPanel_contentSelectedIndex", new Integer (panelNumber)); 172 } 173 174 public java.util.Set instantiate() throws IOException { 175 return typeIterator.instantiate(); 176 } 177 178 public String name() { 179 if (panelIndex == 0) { 180 return bundle.getString("TXT_PlatformSelectorTitle"); 181 } 182 else if (panelIndex == 1) { 183 return bundle.getString("TXT_PlatformFolderTitle"); 184 } else { 185 return typeIterator.name(); 186 } 187 } 188 189 public void nextPanel() { 190 if (this.panelIndex == 0) { 191 if (this.selectorPanel.getInstallerIterator() == null) { 192 panelIndex = 1; 193 } 194 else { 195 panelIndex = 3; 196 } 197 } else if (panelIndex == 1) { 198 panelIndex = 2; 199 } 200 else { 201 typeIterator.nextPanel(); 202 } 203 panelNumber++; 204 wizard.putProperty("WizardPanel_contentSelectedIndex", new Integer (panelNumber)); 206 } 207 208 public void previousPanel() { 209 if (panelIndex == 1) { 210 panelIndex = 0; 211 } 212 else if (panelIndex == 2) { 213 if (typeIterator.hasPrevious()) { 214 typeIterator.previousPanel(); 215 } else { 216 panelIndex = 1; 217 } 218 } else if (panelIndex == 3) { 219 if (typeIterator.hasPrevious()) { 220 typeIterator.previousPanel(); 221 } else { 222 panelIndex = 0; 223 } 224 } 225 panelNumber--; 226 wizard.putProperty("WizardPanel_contentSelectedIndex", new Integer (panelNumber)); 228 } 229 230 public void removeChangeListener(ChangeListener l) { 231 listeners.remove(l); 232 } 233 234 public void uninitialize(WizardDescriptor wiz) { 235 if (this.typeIterator != null) 236 typeIterator.uninitialize (wiz); 237 } 238 239 public void stateChanged(ChangeEvent e) { 240 WizardDescriptor.InstantiatingIterator it; 241 if (e.getSource() == this.locationPanel) { 242 it = locationPanel.getInstallerIterator(); 243 } 244 else if (e.getSource() == this.selectorPanel) { 245 GeneralPlatformInstall installer = this.selectorPanel.getInstaller(); 246 if (installer instanceof CustomPlatformInstall) { 247 it = ((CustomPlatformInstall)installer).createIterator(); 248 } 249 else { 250 it = null; 251 this.locationPanel.setPlatformInstall ((PlatformInstall)installer); 252 } 253 } 254 else { 255 assert false : "Unknown event source"; return; 257 } 258 if (it != typeIterator) { 259 if (this.typeIterator != null) { 260 this.typeIterator.uninitialize (this.wizard); 261 } 262 typeIterator = it; 263 if (this.typeIterator != null) { 264 typeIterator.initialize (this.wizard); 265 updatePanelsList(new JComponent []{ 266 (JComponent )selectorPanel.getComponent(), 267 (JComponent )locationPanel.getComponent(), 268 (JComponent )typeIterator.current().getComponent(), 269 }); 270 } 271 else { 272 updatePanelsList(new JComponent []{ 273 (JComponent )selectorPanel.getComponent(), 274 (JComponent )locationPanel.getComponent() 275 }); 276 } 277 wizard.putProperty("WizardPanel_contentSelectedIndex", new Integer (panelNumber)); } 279 } 280 } 281 | Popular Tags |