1 11 package org.eclipse.pde.internal.ui.templates.rcp; 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.ui.templates.IHelpContextIds; 23 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 24 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 25 import org.eclipse.pde.internal.ui.templates.PluginReference; 26 import org.eclipse.pde.ui.IFieldData; 27 28 29 public class MailTemplate extends PDETemplateSection { 30 31 public static final String KEY_WORKBENCH_ADVISOR = "advisor"; public static final String KEY_APPLICATION_CLASS = "applicationClass"; 34 public MailTemplate() { 35 setPageCount(1); 36 createOptions(); 37 } 38 39 public void addPages(Wizard wizard) { 40 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL); 41 page.setTitle(PDETemplateMessages.MailTemplate_title); 42 page.setDescription(PDETemplateMessages.MailTemplate_desc); 43 wizard.addPage(page); 44 markPagesAdded(); 45 } 46 47 48 private void createOptions() { 49 addOption(KEY_PRODUCT_NAME, PDETemplateMessages.MailTemplate_productName, VALUE_PRODUCT_NAME, 0); 50 51 addOption(KEY_PACKAGE_NAME, PDETemplateMessages.MailTemplate_packageName, (String ) null, 0); 53 addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.MailTemplate_appClass, "Application", 0); } 55 56 protected void initializeFields(IFieldData data) { 57 String packageName = getFormattedPackageName(data.getId()); 60 initializeOption(KEY_PACKAGE_NAME, packageName); 61 } 62 63 public void initializeFields(IPluginModelBase model) { 64 String packageName = getFormattedPackageName(model.getPluginBase().getId()); 65 initializeOption(KEY_PACKAGE_NAME, packageName); 66 } 67 68 73 public String getSectionId() { 74 return "mail"; } 76 77 80 protected void updateModel(IProgressMonitor monitor) throws CoreException { 81 createApplicationExtension(); 82 createPerspectiveExtension(); 83 createViewExtension(); 84 if (getTargetVersion() >= 3.1) { 85 createCommandExtension(false); 86 createBindingsExtension(); 87 } else { 88 createCommandExtension(true); 89 } 90 createProductExtension(); 91 } 92 93 private void createApplicationExtension() throws CoreException { 94 IPluginBase plugin = model.getPluginBase(); 95 96 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(VALUE_APPLICATION_ID); 98 99 IPluginElement element = model.getPluginFactory().createElement(extension); 100 element.setName("application"); extension.add(element); 102 103 IPluginElement run = model.getPluginFactory().createElement(element); 104 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 107 108 if (!extension.isInTheModel()) 109 plugin.add(extension); 110 } 111 112 113 private void createPerspectiveExtension() throws CoreException { 114 IPluginBase plugin = model.getPluginBase(); 115 116 IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement element = model.getPluginFactory().createElement(extension); 118 element.setName("perspective"); element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); element.setAttribute("name", VALUE_PERSPECTIVE_NAME); element.setAttribute("id", plugin.getId() + ".perspective"); extension.add(element); 123 124 if (!extension.isInTheModel()) 125 plugin.add(extension); 126 } 127 128 private void createViewExtension() throws CoreException { 129 IPluginBase plugin = model.getPluginBase(); 130 String id = plugin.getId(); 131 IPluginExtension extension = createExtension("org.eclipse.ui.views", true); 133 IPluginElement view = model.getPluginFactory().createElement(extension); 134 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); 141 142 view = model.getPluginFactory().createElement(extension); 143 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); 150 151 if (!extension.isInTheModel()) 152 plugin.add(extension); 153 } 154 155 private void createCommandExtension(boolean generateKeyBindings) throws CoreException { 156 IPluginBase plugin = model.getPluginBase(); 157 String id = plugin.getId(); 158 IPluginExtension extension = createExtension("org.eclipse.ui.commands", true); 160 IPluginElement element = model.getPluginFactory().createElement(extension); 161 element.setName("category"); element.setAttribute("id", id + ".category"); element.setAttribute("name", "Mail"); extension.add(element); 165 166 element = model.getPluginFactory().createElement(extension); 167 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); 173 174 element = model.getPluginFactory().createElement(extension); 175 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); 181 182 if(generateKeyBindings){ 183 element = model.getPluginFactory().createElement(extension); 184 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); 189 190 element = model.getPluginFactory().createElement(extension); 191 element.setName("keyBinding"); element.setAttribute("commandId", id + ".open"); element.setAttribute("keySequence", "CTRL+2"); element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 196 197 element = model.getPluginFactory().createElement(extension); 198 element.setName("keyBinding"); element.setAttribute("commandId", id + ".openMessage"); element.setAttribute("keySequence", "CTRL+3"); element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 203 204 element = model.getPluginFactory().createElement(extension); 205 element.setName("keyBinding"); element.setAttribute("commandId", "org.eclipse.ui.file.exit"); element.setAttribute("keySequence", "CTRL+Q"); element.setAttribute("keyConfigurationId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 210 } 211 212 if (!extension.isInTheModel()) 213 plugin.add(extension); 214 } 215 216 private void createBindingsExtension() throws CoreException { 217 IPluginBase plugin = model.getPluginBase(); 218 String id = plugin.getId(); 219 IPluginExtension extension = createExtension("org.eclipse.ui.bindings", true); 221 IPluginElement element = model.getPluginFactory().createElement(extension); 222 element.setName("key"); element.setAttribute("commandId", id + ".open"); element.setAttribute("sequence", "CTRL+2"); element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 227 228 element = model.getPluginFactory().createElement(extension); 229 element.setName("key"); element.setAttribute("commandId", id + ".openMessage"); element.setAttribute("sequence", "CTRL+3"); element.setAttribute("schemeId", "org.eclipse.ui.defaultAcceleratorConfiguration"); extension.add(element); 234 235 element = model.getPluginFactory().createElement(extension); 236 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); 241 242 if (!extension.isInTheModel()) 243 plugin.add(extension); 244 } 245 246 private void createProductExtension() throws CoreException { 247 IPluginBase plugin = model.getPluginBase(); 248 IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); extension.setId(VALUE_PRODUCT_ID); 250 251 IPluginElement element = model.getFactory().createElement(extension); 252 element.setName("product"); element.setAttribute("name", getStringOption(KEY_PRODUCT_NAME)); element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); 256 IPluginElement property = model.getFactory().createElement(element); 257 property.setName("property"); property.setAttribute("name", "aboutText"); property.setAttribute("value", "RCP Mail template created by PDE"); element.add(property); 261 262 property = model.getFactory().createElement(element); 263 property.setName("property"); property.setAttribute("name", "windowImages"); property.setAttribute("value", "icons/sample2.gif"); element.add(property); 267 268 property = model.getFactory().createElement(element); 269 property.setName("property"); property.setAttribute("name", "aboutImage"); property.setAttribute("value", "product_lg.gif"); element.add(property); 273 274 extension.add(element); 275 276 if (!extension.isInTheModel()) { 277 plugin.add(extension); 278 } 279 280 } 281 282 285 public String getUsedExtensionPoint() { 286 return null; 287 } 288 289 292 public boolean isDependentOnParentWizard() { 293 return true; 294 } 295 296 299 public int getNumberOfWorkUnits() { 300 return super.getNumberOfWorkUnits() + 1; 301 } 302 303 306 public IPluginReference[] getDependencies(String schemaVersion) { 307 IPluginReference[] dep = new IPluginReference[2]; 308 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); return dep; 311 } 312 313 316 public String [] getNewFiles() { 317 return new String [] {"icons/", "product_lg.gif", "splash.bmp"}; } 319 320 323 protected boolean copyBrandingDirectory() { 324 return true; 325 } 326 327 } 328 | Popular Tags |