1 19 20 package org.netbeans.modules.projectimport.j2seimport.ui; 21 22 import java.awt.Component ; 23 import java.io.IOException ; 24 import java.util.NoSuchElementException ; 25 import java.util.Set ; 26 import javax.swing.event.ChangeListener ; 27 import org.openide.WizardDescriptor; 28 import org.openide.util.HelpCtx; 29 import org.openide.util.NbBundle; 30 31 36 public abstract class BasicWizardIterator implements WizardDescriptor.InstantiatingIterator { 37 protected BasicWizardIterator.BasicDataModel data; 38 private int position = 0; 39 private BasicWizardIterator.PrivateWizardPanel[] wizardPanels; 40 41 42 protected BasicWizardIterator() { 43 } 44 45 46 protected abstract BasicWizardIterator.Panel[] createPanels(WizardDescriptor wiz); 47 48 protected abstract String getTitle(); 49 50 51 public abstract static class Panel extends BasicVisualPanel { 52 53 protected Panel(WizardDescriptor wiz) { 54 super(wiz); 55 } 56 57 62 protected abstract String getPanelName(); 63 64 70 protected abstract void storeToDataModel(); 71 72 78 protected abstract void readFromDataModel(); 79 80 protected abstract HelpCtx getHelp(); 81 82 } 83 84 85 public static class BasicDataModel { 86 } 87 88 public final void initialize(WizardDescriptor wiz) { 89 wiz.setTitleFormat(new java.text.MessageFormat ("{0}")); wiz.setTitle(getTitle()); String [] beforeSteps = null; 93 Object prop = wiz.getProperty("WizardPanel_contentData"); if (prop != null && prop instanceof String []) { 95 beforeSteps = (String [])prop; 96 } 97 position = 0; 98 BasicWizardIterator.Panel[] panels = createPanels(wiz); 99 String [] steps = BasicWizardIterator.createSteps(beforeSteps, panels); 100 wizardPanels = new BasicWizardIterator.PrivateWizardPanel[panels.length]; 101 102 for (int i = 0; i < panels.length; i++) { 103 wizardPanels[i] = new BasicWizardIterator.PrivateWizardPanel(panels[i], steps, i); 104 } 105 } 106 107 private static String [] createSteps(String [] before, BasicWizardIterator.Panel[] panels) { 109 assert panels != null; 110 int diff = 0; 112 if (before == null) { 113 before = new String [0]; 114 } else if (before.length > 0) { 115 diff = ("...".equals(before[before.length - 1])) ? 1 : 0; } 117 String [] res = new String [ (before.length - diff) + panels.length]; 118 for (int i = 0; i < res.length; i++) { 119 if (i < (before.length - diff)) { 120 res[i] = before[i]; 121 } else { 122 res[i] = panels[i - before.length + diff].getPanelName(); 123 } 124 } 125 return res; 126 } 127 128 public final void uninitialize(WizardDescriptor wiz) { 129 wizardPanels = null; 130 uninitialize(); 131 } 132 133 public void uninitialize() { 134 wizardPanels = null; 135 } 136 137 public String name() { 138 return ((BasicWizardIterator.PrivateWizardPanel) 139 current()).getPanel().getPanelName(); 140 } 141 142 public boolean hasNext() { 143 return position < (wizardPanels.length - 1); 144 } 145 146 public boolean hasPrevious() { 147 return position > 0; 148 } 149 150 public void nextPanel() { 151 if (!hasNext()) { 152 throw new NoSuchElementException (); 153 } 154 position++; 155 } 156 157 public void previousPanel() { 158 if (!hasPrevious()) { 159 throw new NoSuchElementException (); 160 } 161 position--; 162 } 163 164 public WizardDescriptor.Panel current() { 165 return wizardPanels[position]; 166 } 167 168 171 protected final String getMessage(String key) { 172 return NbBundle.getMessage(getClass(), key); 173 } 174 175 public final void addChangeListener(ChangeListener l) {} 176 public final void removeChangeListener(ChangeListener l) {} 177 178 179 180 private static final class PrivateWizardPanel extends BasicWizardPanel { 181 182 private BasicWizardIterator.Panel panel; 183 184 PrivateWizardPanel(BasicWizardIterator.Panel panel, String [] allSteps, int stepIndex) { 185 super(panel.getSettings()); 186 panel.addPropertyChangeListener(this); 187 panel.setName(panel.getPanelName()); this.panel = panel; 189 panel.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (stepIndex)); panel.putClientProperty("WizardPanel_contentData", allSteps); panel.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); panel.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); panel.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); } 196 197 private BasicWizardIterator.Panel getPanel() { 198 return panel; 199 } 200 201 public Component getComponent() { 202 return getPanel(); 203 } 204 205 public void storeSettings(Object settings) { 206 WizardDescriptor wiz = (WizardDescriptor) settings; 207 if (WizardDescriptor.NEXT_OPTION.equals(wiz.getValue()) || 208 WizardDescriptor.FINISH_OPTION.equals(wiz.getValue())) { 209 panel.storeToDataModel(); 210 } 211 } 212 213 public void readSettings(Object settings) { 214 WizardDescriptor wiz = (WizardDescriptor) settings; 215 216 if (WizardDescriptor.NEXT_OPTION.equals(wiz.getValue()) || wiz.getValue() == null) { 217 panel.readFromDataModel(); 218 } 219 } 220 221 public HelpCtx getHelp() { 222 return getPanel().getHelp(); 223 } 224 225 } 226 227 public void setData(BasicWizardIterator.BasicDataModel data) { 228 this.data = data; 229 } 230 231 public BasicWizardIterator.BasicDataModel getData() { 232 return data; 233 } 234 235 final public Set instantiate() throws IOException { 236 return null; 237 } 238 } 239 240 | Popular Tags |