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 HelloRCPTemplate extends PDETemplateSection { 30 31 public static final String KEY_APPLICATION_CLASS = "applicationClass"; public static final String KEY_WINDOW_TITLE = "windowTitle"; 34 public HelloRCPTemplate() { 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.HelloRCPTemplate_title); 42 page.setDescription(PDETemplateMessages.HelloRCPTemplate_desc); 43 wizard.addPage(page); 44 markPagesAdded(); 45 } 46 47 48 private void createOptions() { 49 addOption(KEY_WINDOW_TITLE, PDETemplateMessages.HelloRCPTemplate_windowTitle, "Hello RCP", 0); 51 addOption(KEY_PACKAGE_NAME, PDETemplateMessages.MailTemplate_packageName, (String ) null, 0); 52 53 addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.HelloRCPTemplate_appClass, "Application", 0); 55 createBrandingOptions(); 56 } 57 58 protected void initializeFields(IFieldData data) { 59 String packageName = getFormattedPackageName(data.getId()); 62 initializeOption(KEY_PACKAGE_NAME, packageName); 63 } 64 65 public void initializeFields(IPluginModelBase model) { 66 String packageName = getFormattedPackageName(model.getPluginBase().getId()); 67 initializeOption(KEY_PACKAGE_NAME, packageName); 68 } 69 70 75 public String getSectionId() { 76 return "helloRCP"; } 78 79 82 protected void updateModel(IProgressMonitor monitor) throws CoreException { 83 createApplicationExtension(); 84 createPerspectiveExtension(); 85 if (getBooleanOption(KEY_PRODUCT_BRANDING)) 86 createProductExtension(); 87 } 88 89 private void createApplicationExtension() throws CoreException { 90 IPluginBase plugin = model.getPluginBase(); 91 92 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(VALUE_APPLICATION_ID); 94 95 IPluginElement element = model.getPluginFactory().createElement(extension); 96 element.setName("application"); extension.add(element); 98 99 IPluginElement run = model.getPluginFactory().createElement(element); 100 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 103 104 if (!extension.isInTheModel()) 105 plugin.add(extension); 106 } 107 108 private void createPerspectiveExtension() throws CoreException { 109 IPluginBase plugin = model.getPluginBase(); 110 111 IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement element = model.getPluginFactory().createElement(extension); 113 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); 118 119 if (!extension.isInTheModel()) 120 plugin.add(extension); 121 } 122 123 private void createProductExtension() throws CoreException { 124 IPluginBase plugin = model.getPluginBase(); 125 IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); extension.setId(VALUE_PRODUCT_ID); 127 128 IPluginElement element = model.getFactory().createElement(extension); 129 element.setName("product"); element.setAttribute("name", getStringOption(KEY_WINDOW_TITLE)); element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); 133 IPluginElement property = model.getFactory().createElement(element); 134 135 property = model.getFactory().createElement(element); 136 property.setName("property"); property.setAttribute("name", "windowImages"); property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); element.add(property); 140 141 extension.add(element); 142 143 if (!extension.isInTheModel()) 144 plugin.add(extension); 145 } 146 147 150 public String getUsedExtensionPoint() { 151 return null; 152 } 153 154 157 public boolean isDependentOnParentWizard() { 158 return true; 159 } 160 161 164 public int getNumberOfWorkUnits() { 165 return super.getNumberOfWorkUnits() + 1; 166 } 167 168 171 public IPluginReference[] getDependencies(String schemaVersion) { 172 IPluginReference[] dep = new IPluginReference[2]; 173 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); return dep; 176 } 177 178 181 public String [] getNewFiles() { 182 if (copyBrandingDirectory()) 183 return new String [] { "icons/", "splash.bmp" }; return super.getNewFiles(); 185 } 186 } 187 | Popular Tags |