1 11 package org.eclipse.pde.ui.templates; 12 import java.util.Hashtable ; 13 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.pde.core.plugin.IPluginModelBase; 18 import org.eclipse.pde.ui.IFieldData; 19 20 34 35 public abstract class BaseOptionTemplateSection extends AbstractTemplateSection { 36 private Hashtable options = new Hashtable (); 37 38 52 protected TemplateOption addOption(String name, String label, 53 boolean value, int pageIndex) { 54 BooleanOption option = new BooleanOption(this, name, label); 55 registerOption(option, value ? Boolean.TRUE : Boolean.FALSE, pageIndex); 56 return option; 57 } 58 59 73 protected TemplateOption addOption(String name, String label, String value, 74 int pageIndex) { 75 StringOption option = new StringOption(this, name, label); 76 registerOption(option, value, pageIndex); 77 return option; 78 } 79 99 protected TemplateOption addOption(String name, String label, 100 String [][] choices, String value, int pageIndex) { 101 AbstractChoiceOption option; 102 if (choices.length == 2) 103 option = new RadioChoiceOption(this, name, label, choices); 104 else 105 option = new ComboChoiceOption(this, name, label, choices); 106 registerOption(option, value, pageIndex); 107 return option; 108 } 109 110 120 protected ComboChoiceOption addComboChoiceOption(String name, String label, 121 String [][] choices, String value, int pageIndex) { 122 ComboChoiceOption option = new ComboChoiceOption(this, name, label, choices); 123 registerOption(option, value, pageIndex); 124 return option; 125 } 126 127 134 protected TemplateOption addBlankField(int pageIndex) { 135 BlankField field = new BlankField(this); 136 registerOption(field, "", pageIndex); return field; 138 } 139 148 protected TemplateOption addBlankField(int height, int pageIndex) { 149 BlankField field = new BlankField(this, height); 150 registerOption(field, "", pageIndex); return field; 152 } 153 162 protected void initializeOption(String name, Object value) { 163 TemplateOption option = getOption(name); 164 if (option != null) { 165 if (option.getValue() == null) 167 option.setValue(value); 168 } 169 } 170 180 public String getStringOption(String name) { 181 TemplateOption option = (TemplateOption) options.get(name); 182 if (option != null) { 183 if (option instanceof StringOption) 184 return ((StringOption) option).getText(); 185 else if (option instanceof ComboChoiceOption) { 186 ComboChoiceOption ccoption = (ComboChoiceOption)option; 190 Object value = ccoption.getValue(); 191 if (value!=null && value instanceof String ) 192 return (String )value; 193 } 194 } 195 return null; 196 } 197 207 public boolean getBooleanOption(String key) { 208 TemplateOption option = (TemplateOption) options.get(key); 209 if (option != null && option instanceof BooleanOption) { 210 return ((BooleanOption) option).isSelected(); 211 } 212 return false; 213 } 214 225 public void setOptionEnabled(String name, boolean enabled) { 226 TemplateOption option = (TemplateOption) options.get(name); 227 if (option != null) 228 option.setEnabled(enabled); 229 } 230 239 public Object getValue(String name) { 240 TemplateOption option = (TemplateOption) options.get(name); 241 if (option != null) 242 return option.getValue(); 243 return super.getValue(name); 244 } 245 261 public boolean isDependentOnParentWizard() { 262 return false; 263 } 264 278 protected void initializeFields(IFieldData data) { 279 } 280 295 public void initializeFields(IPluginModelBase model) { 296 } 297 306 public abstract void validateOptions(TemplateOption changed); 307 313 public String getReplacementString(String fileName, String key) { 314 String value = getStringOption(key); 315 if (value != null) 316 return value; 317 return super.getReplacementString(fileName, key); 318 } 319 325 public void execute(IProject project, IPluginModelBase model, 326 IProgressMonitor monitor) throws CoreException { 327 initializeFields(model); 328 super.execute(project, model, monitor); 329 } 330 340 protected void registerOption(TemplateOption option, Object value, 341 int pageIndex) { 342 option.setValue(value); 343 options.put(option.getName(), option); 344 } 345 346 private TemplateOption getOption(String key) { 347 return (TemplateOption) options.get(key); 348 } 349 } 350 | Popular Tags |