1 11 package org.eclipse.pde.internal.ui.wizards.templates; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.jface.wizard.Wizard; 16 import org.eclipse.jface.wizard.WizardPage; 17 import org.eclipse.pde.core.plugin.IPluginBase; 18 import org.eclipse.pde.core.plugin.IPluginElement; 19 import org.eclipse.pde.core.plugin.IPluginExtension; 20 import org.eclipse.pde.core.plugin.IPluginModelBase; 21 import org.eclipse.pde.core.plugin.IPluginReference; 22 import org.eclipse.pde.internal.core.plugin.PluginBase; 23 import org.eclipse.pde.internal.ui.IHelpContextIds; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 import org.eclipse.pde.ui.IFieldData; 26 import org.eclipse.pde.ui.templates.TemplateOption; 27 28 29 public class MailTemplate extends PDETemplateSection { 30 31 public static final String KEY_PRODUCT_NAME = "productName"; public static final String KEY_PRODUCT_ID = "productID"; public static final String KEY_PERSPECTIVE_NAME = "perspectiveName"; public static final String KEY_WORKBENCH_ADVISOR = "advisor"; public static final String KEY_APPLICATION_CLASS = "applicationClass"; public static final String KEY_APPLICATION_ID = "applicationID"; 38 public MailTemplate() { 39 setPageCount(1); 40 createOptions(); 41 } 42 43 public void addPages(Wizard wizard) { 44 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL); 45 page.setTitle(PDEUIMessages.MailTemplate_title); 46 page.setDescription(PDEUIMessages.MailTemplate_desc); 47 wizard.addPage(page); 48 markPagesAdded(); 49 } 50 51 52 private void createOptions() { 53 addOption(KEY_PRODUCT_NAME, PDEUIMessages.MailTemplate_productName, "RCP Product", 0); 55 addOption(KEY_PRODUCT_ID, PDEUIMessages.MailTemplate_productID, "product", 0); 57 addOption(KEY_APPLICATION_ID, PDEUIMessages.MailTemplate_appId, "application", 0); 59 addOption(KEY_PERSPECTIVE_NAME, PDEUIMessages.MailTemplate_perspectiveName, (String )null, 0); 61 addOption(KEY_PACKAGE_NAME, PDEUIMessages.MailTemplate_packageName, (String ) null, 0); 63 addOption(KEY_APPLICATION_CLASS, PDEUIMessages.MailTemplate_appClass, "Application", 0); } 65 66 protected void initializeFields(IFieldData data) { 67 String packageName = getFormattedPackageName(data.getId()); 70 initializeOption(KEY_PACKAGE_NAME, packageName); 71 72 int index = packageName.lastIndexOf('.'); 73 String name = packageName.substring(index + 1) + " Perspective"; initializeOption(KEY_PERSPECTIVE_NAME, Character.toUpperCase(name.charAt(0)) + name.substring(1)); 75 } 76 77 public void initializeFields(IPluginModelBase model) { 78 String packageName = getFormattedPackageName(model.getPluginBase().getId()); 79 initializeOption(KEY_PACKAGE_NAME, packageName); 80 81 int index = packageName.lastIndexOf('.'); 82 String name = packageName.substring(index + 1) + " Perspective"; initializeOption(KEY_PERSPECTIVE_NAME, Character.toUpperCase(name.charAt(0)) + name.substring(1)); 84 } 85 86 91 public String getSectionId() { 92 return "mail"; } 94 95 98 public void validateOptions(TemplateOption source) { 99 if (source.isRequired() && source.isEmpty()) { 100 flagMissingRequiredOption(source); 101 } else { 102 validateContainerPage(source); 103 } 104 } 105 106 private void validateContainerPage(TemplateOption source) { 107 TemplateOption[] allPageOptions = getOptions(0); 108 for (int i = 0; i < allPageOptions.length; i++) { 109 TemplateOption nextOption = allPageOptions[i]; 110 if (nextOption.isRequired() && nextOption.isEmpty()) { 111 flagMissingRequiredOption(nextOption); 112 return; 113 } 114 } 115 resetPageState(); 116 } 117 118 121 protected void updateModel(IProgressMonitor monitor) throws CoreException { 122 createApplicationExtension(); 123 createPerspectiveExtension(); 124 createViewExtension(); 125 if ("3.1".compareTo(((PluginBase) model.getPluginBase()).getTargetVersion()) <= 0) { createCommandExtension(false); 127 createBindingsExtension(); 128 } else { 129 createCommandExtension(true); 130 } 131 createProductExtension(); 132 } 133 134 private void createApplicationExtension() throws CoreException { 135 IPluginBase plugin = model.getPluginBase(); 136 137 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(getStringOption(KEY_APPLICATION_ID)); 139 140 IPluginElement element = model.getPluginFactory().createElement(extension); 141 element.setName("application"); extension.add(element); 143 144 IPluginElement run = model.getPluginFactory().createElement(element); 145 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 148 149 if (!extension.isInTheModel()) 150 plugin.add(extension); 151 } 152 153 154 private void createPerspectiveExtension() throws CoreException { 155 IPluginBase plugin = model.getPluginBase(); 156 157 IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement element = model.getPluginFactory().createElement(extension); 159 element.setName("perspective"); element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); element.setAttribute("name", getStringOption(KEY_PERSPECTIVE_NAME)); element.setAttribute("id", plugin.getId() + ".perspective"); extension.add(element); 164 165 if (!extension.isInTheModel()) 166 plugin.add(extension); 167 } 168 169 private void createViewExtension() throws CoreException { 170 IPluginBase plugin = model.getPluginBase(); 171 String id = plugin.getId(); 172 IPluginExtension extension = createExtension("org.eclipse.ui.views", true); 174 IPluginElement view = model.getPluginFactory().createElement(extension); 175 view.setName("view"); view.setAttribute("allowMultiple", "true"); view.setAttribute("icon", "icons/sample2.gif"); view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); view.setAttribute("name", "Message"); view.setAttribute("id", id + ".view"); extension.add(view); 182 183 view = model.getPluginFactory().createElement(extension); 184 view.setName("view"); view.setAttribute("allowMultiple", "true"); view.setAttribute("icon", "icons/sample3.gif"); view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".NavigationView" ); view.setAttribute("name", "Mailboxes"); view.setAttribute("id", id + ".navigationView"); extension.add(view); 191 192 if (!extension.isInTheModel()) 193 plugin.add(extension); 194 } 195 196 private void createCommandExtension(boolean generateKeyBindings) throws CoreException { 197 IPluginBase plugin = model.getPluginBase(); 198 String id = plugin.getId(); 199 IPluginExtension extension = createExtension("org.eclipse.ui.commands", true); 201 IPluginElement element = model.getPluginFactory().createElement(extension); 202 element.setName("category"); element.setAttribute("id", id + ".category"); element.setAttribute("name", "Mail"); extension.add(element); 206 207 element = model.getPluginFactory().createElement(extension); 208 element.setName("command"); element.setAttribute("description", "Opens a mailbox"); element.setAttribute("name", "Open Mailbox"); element.setAttribute("id", id + ".open"); element.setAttribute("categoryId", id + ".category"); extension.add(element); 214 215 element = model.getPluginFactory().createElement(extension); 216 element.setName("command"); element.setAttribute("description", "Open a message dialog"); element.setAttribute("name", "Open Message Dialog"); element.setAttribute("id", id + ".openMessage"); element.setAttribute("categoryId", id + ".category"); extension.add(element); 222 223 if(generateKeyBindings){ 224 element = model.getPluginFactory().createElement(extension); 225 element.setName("keyConfiguration"); element.setAttribute("description", "The key configuration for this sample"); element.setAttribute("name", id + ".keyConfiguration"); element.setAttribute("id", id + ".keyConfiguration"); extension.add(element); 230 231 element = model.getPluginFactory().createElement(extension); 232 element.setName("keyBinding"); element.setAttribute("commandId", id + ".open"); element.setAttribute("keySequence", "CTRL+2"); element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 237 238 element = model.getPluginFactory().createElement(extension); 239 element.setName("keyBinding"); element.setAttribute("commandId", id + ".openMessage"); element.setAttribute("keySequence", "CTRL+3"); element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 244 245 element = model.getPluginFactory().createElement(extension); 246 element.setName("keyBinding"); element.setAttribute("commandId", "org.eclipse.ui.file.exit"); element.setAttribute("keySequence", "CTRL+X"); element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 251 } 252 253 if (!extension.isInTheModel()) 254 plugin.add(extension); 255 } 256 257 private void createBindingsExtension() throws CoreException { 258 IPluginBase plugin = model.getPluginBase(); 259 String id = plugin.getId(); 260 IPluginExtension extension = createExtension("org.eclipse.ui.bindings", true); 262 IPluginElement element = model.getPluginFactory().createElement(extension); 263 element.setName("key"); element.setAttribute("commandId", id + ".open"); element.setAttribute("sequence", "CTRL+2"); element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 268 269 element = model.getPluginFactory().createElement(extension); 270 element.setName("key"); element.setAttribute("commandId", id + ".openMessage"); element.setAttribute("sequence", "CTRL+3"); element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 275 276 element = model.getPluginFactory().createElement(extension); 277 element.setName("key"); element.setAttribute("commandId", "org.eclipse.ui.file.exit"); element.setAttribute("sequence", "CTRL+X"); element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 282 283 if (!extension.isInTheModel()) 284 plugin.add(extension); 285 } 286 287 private void createProductExtension() throws CoreException { 288 IPluginBase plugin = model.getPluginBase(); 289 IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); extension.setId(getStringOption(KEY_PRODUCT_ID)); 291 292 IPluginElement element = model.getFactory().createElement(extension); 293 element.setName("product"); element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); element.setAttribute("application", plugin.getId() + "." + getStringOption(KEY_APPLICATION_ID)); 297 IPluginElement property = model.getFactory().createElement(element); 298 property.setName("property"); property.setAttribute("name", "aboutText"); property.setAttribute("value", "%aboutText"); element.add(property); 302 303 property = model.getFactory().createElement(element); 304 property.setName("property"); property.setAttribute("name", "windowImages"); property.setAttribute("value", "icons/sample2.gif"); element.add(property); 308 309 property = model.getFactory().createElement(element); 310 property.setName("property"); property.setAttribute("name", "aboutImage"); property.setAttribute("value", "product_lg.gif"); element.add(property); 314 315 extension.add(element); 316 317 if (!extension.isInTheModel()) { 318 plugin.add(extension); 319 } 320 321 } 322 323 326 public String getUsedExtensionPoint() { 327 return null; 328 } 329 330 333 public boolean isDependentOnParentWizard() { 334 return true; 335 } 336 337 340 public int getNumberOfWorkUnits() { 341 return super.getNumberOfWorkUnits() + 1; 342 } 343 344 347 public IPluginReference[] getDependencies(String schemaVersion) { 348 IPluginReference[] dep = new IPluginReference[2]; 349 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); return dep; 352 } 353 354 357 public String [] getNewFiles() { 358 return new String [] {"icons/", "plugin.properties", "product_lg.gif", "splash.bmp"}; } 360 361 } 362 | Popular Tags |