1 11 12 package org.eclipse.pde.internal.ui.templates.ide; 13 14 import java.io.File ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.wizard.Wizard; 19 import org.eclipse.jface.wizard.WizardPage; 20 import org.eclipse.pde.core.plugin.IPluginModelBase; 21 import org.eclipse.pde.core.plugin.IPluginReference; 22 import org.eclipse.pde.core.plugin.TargetPlatform; 23 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 24 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 25 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 26 import org.eclipse.pde.internal.ui.templates.PluginReference; 27 import org.eclipse.pde.internal.ui.wizards.product.ISplashHandlerConstants; 28 import org.eclipse.pde.internal.ui.wizards.product.UpdateSplashHandlerAction; 29 import org.eclipse.pde.ui.IFieldData; 30 import org.eclipse.pde.ui.templates.ComboChoiceOption; 31 import org.eclipse.pde.ui.templates.StringOption; 32 import org.eclipse.pde.ui.templates.TemplateOption; 33 34 38 public class SplashHandlersTemplate extends PDETemplateSection { 39 40 private final static int F_PAGE_INDEX = 0; 41 42 private final static String F_DEFAULT_PRODUCT = "org.eclipse.sdk.ide"; 44 private final static String F_FIELD_TEMPLATE = "fieldTemplate"; 46 private final static String F_FIELD_PRODUCTS = "fieldProducts"; 48 private final static String F_FIELD_CLASS = "fieldClass"; 50 private final static String F_FIELD_SPLASH = "fieldSplash"; 52 private final static String F_SPLASH_SCREEN_FILE = "splash.bmp"; 54 private WizardPage fPage; 55 56 private TemplateOption fFieldTemplate; 57 58 private ComboChoiceOption fFieldProducts; 59 60 private TemplateOption fFieldPackage; 61 62 private StringOption fFieldClass; 63 64 private TemplateOption fFieldSplash; 65 66 69 public SplashHandlersTemplate() { 70 initialize(); 71 } 72 73 76 private void initialize() { 77 fFieldTemplate = null; 79 fFieldProducts = null; 80 fFieldPackage = null; 81 fFieldClass = null; 82 fFieldSplash = null; 83 setPageCount(1); 85 createUI(); 87 } 88 89 92 public void addPages(Wizard wizard) { 93 fPage = createPage(0, IHelpContextIds.TEMPLATE_SPLASH_HANDLERS); 95 fPage.setTitle(PDETemplateMessages.SplashHandlersTemplate_titleSplashHandlerOptions); 96 fPage.setDescription(PDETemplateMessages.SplashHandlersTemplate_descSplashHandlerOptions); 97 wizard.addPage(fPage); 99 markPagesAdded(); 101 } 102 103 106 protected String getFormattedPackageName(String id) { 107 String packageName = super.getFormattedPackageName(id); 110 if (packageName.length() == 0) { 112 return ISplashHandlerConstants.F_UNQUALIFIED_EXTENSION_ID; 113 } 114 return packageName + '.' + ISplashHandlerConstants.F_UNQUALIFIED_EXTENSION_ID; 116 } 117 118 121 public String [] getNewFiles() { 122 if (isSplashFieldSelected()) { 126 return new String [] { F_SPLASH_SCREEN_FILE }; 127 } 128 return super.getNewFiles(); 130 } 131 132 135 private boolean isSplashFieldSelected() { 136 if ((Boolean )fFieldSplash.getValue() == Boolean.TRUE) { 137 return true; 138 } 139 return false; 140 } 141 142 145 public int getNumberOfWorkUnits() { 146 return super.getNumberOfWorkUnits() + 1; 147 } 148 149 152 protected void initializeFields(IFieldData data) { 153 String id = data.getId(); 154 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 155 } 156 157 160 public void initializeFields(IPluginModelBase model) { 161 String pluginId = model.getPluginBase().getId(); 162 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 163 } 164 165 168 public boolean isDependentOnParentWizard() { 169 return true; 170 } 171 172 175 public void validateOptions(TemplateOption source) { 176 if (source == fFieldTemplate) { 178 updateUIFieldClass(); 179 } 180 super.validateOptions(source); 181 } 182 183 186 private void updateUIFieldClass() { 187 for (int i = 0; i < ISplashHandlerConstants.F_SPLASH_SCREEN_TYPE_CHOICES.length; i++) { 189 String choice = ISplashHandlerConstants.F_SPLASH_SCREEN_TYPE_CHOICES[i][0]; 190 if (fFieldTemplate.getValue().equals(choice)) { 191 fFieldClass.setValue(ISplashHandlerConstants.F_SPLASH_SCREEN_CLASSES[i]); 192 break; 193 } 194 } 195 } 196 197 200 private void createUI() { 201 createUIFieldTemplate(); 203 createUIFieldProductID(); 205 createUIFieldPackage(); 207 createUIFieldClass(); 209 createUIFieldSplash(); 211 } 212 213 216 private void createUIFieldSplash() { 217 fFieldSplash = addOption( 218 F_FIELD_SPLASH, 219 PDETemplateMessages.SplashHandlersTemplate_fieldAddSplash, 220 false, 221 F_PAGE_INDEX); 222 } 223 224 227 private void createUIFieldClass() { 228 fFieldClass = (StringOption)addOption( 229 F_FIELD_CLASS, 230 PDETemplateMessages.SplashHandlersTemplate_fieldClassName, 231 ISplashHandlerConstants.F_SPLASH_SCREEN_CLASSES[0], 232 F_PAGE_INDEX); 233 fFieldClass.setReadOnly(true); 234 } 235 236 239 private void createUIFieldPackage() { 240 fFieldPackage = addOption( 241 KEY_PACKAGE_NAME, 242 PDETemplateMessages.SplashHandlersTemplate_fieldJavaPackage, 243 null, 244 F_PAGE_INDEX); 245 } 246 247 250 private void createUIFieldTemplate() { 251 fFieldTemplate = addOption( 252 F_FIELD_TEMPLATE, 253 PDETemplateMessages.SplashHandlersTemplate_fieldSplashScreenType, 254 ISplashHandlerConstants.F_SPLASH_SCREEN_TYPE_CHOICES, 255 ISplashHandlerConstants.F_SPLASH_SCREEN_TYPE_CHOICES[0][0], 256 F_PAGE_INDEX); 257 } 258 259 262 private void createUIFieldProductID() { 263 264 String [] products = TargetPlatform.getProducts(); 265 String [][] choices = new String [products.length][2]; 266 String initialChoice = null; 267 boolean foundInitialChoice = false; 268 for (int i = 0; i < products.length; i++) { 270 choices[i][0] = products[i]; 272 choices[i][1] = products[i]; 274 if ((foundInitialChoice == false) && 276 (products[i].equals(F_DEFAULT_PRODUCT))) { 277 foundInitialChoice = true; 278 } 279 } 280 if (foundInitialChoice) { 283 initialChoice = F_DEFAULT_PRODUCT; 284 } else { 285 initialChoice = choices[0][0]; 286 } 287 fFieldProducts = addComboChoiceOption( 289 F_FIELD_PRODUCTS, 290 PDETemplateMessages.SplashHandlersTemplate_fieldProductID, 291 choices, 292 initialChoice, 293 F_PAGE_INDEX); 294 } 295 296 299 public IPluginReference[] getDependencies(String schemaVersion) { 300 if (schemaVersion == null) { 302 return super.getDependencies(schemaVersion); 303 } 304 IPluginReference[] dependencies = new IPluginReference[4]; 306 dependencies[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dependencies[1] = new PluginReference("org.eclipse.swt", null, 0); dependencies[2] = new PluginReference("org.eclipse.jface", null, 0); dependencies[3] = new PluginReference("org.eclipse.ui.workbench", null, 0); 311 return dependencies; 312 } 313 314 317 public String getSectionId() { 318 return ISplashHandlerConstants.F_UNQUALIFIED_EXTENSION_ID; 319 } 320 321 324 protected void updateModel(IProgressMonitor monitor) throws CoreException { 325 UpdateSplashHandlerAction action = new UpdateSplashHandlerAction(); 328 String id = createAttributeValueID(); 330 action.setFieldID(id); 331 action.setFieldClass(createAttributeValueClass()); 332 action.setFieldSplashID(id); 333 action.setFieldProductID((String )fFieldProducts.getValue()); 334 action.setFieldTemplate((String )fFieldTemplate.getValue()); 335 action.setFieldPluginID(model.getPluginBase().getId()); 336 action.setModel(model); 337 action.setMonitor(monitor); 338 action.run(); 340 action.hasException(); 342 } 343 344 347 private String createAttributeValueID() { 348 return fFieldPackage.getValue() + 350 "." + fFieldTemplate.getValue(); 352 } 353 354 357 private String createAttributeValueClass() { 358 return fFieldPackage.getValue() + 360 "." + fFieldClass.getValue(); 362 } 363 364 367 public String getUsedExtensionPoint() { 368 return ISplashHandlerConstants.F_SPLASH_HANDLERS_EXTENSION; 369 } 370 371 374 protected boolean isOkToCreateFile(File sourceFile) { 375 String javaSuffix = ".java"; String targetFile = fFieldClass.getValue() + javaSuffix; 378 String copyFile = sourceFile.toString(); 379 380 if (copyFile.endsWith(javaSuffix) && 381 (copyFile.endsWith(targetFile) == false)) { 382 return false; 383 } 384 385 return true; 386 } 387 388 391 protected boolean copyBrandingDirectory() { 392 return isSplashFieldSelected(); 393 } 394 395 398 protected boolean isOkToCreateFolder(File sourceFolder) { 399 boolean extensibleTemplateSelected = 401 UpdateSplashHandlerAction.isExtensibleTemplateSelected((String )fFieldTemplate.getValue()); 402 String sourceFolderString = sourceFolder.toString(); 403 404 if ((extensibleTemplateSelected == false) && 405 sourceFolderString.endsWith("icons")) { return false; 407 } else if ((extensibleTemplateSelected == false) && 408 sourceFolderString.endsWith("schema")) { return false; 410 } 411 412 return true; 413 } 414 415 418 public String getLabel() { 419 return getPluginResourceString("wizard.name.splash.handler"); } 421 422 425 public String getDescription() { 426 return getPluginResourceString("wizard.description.splash.handler"); } 428 429 } 430 | Popular Tags |