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 ViewRCPTemplate extends PDETemplateSection { 30 31 public static final String KEY_APPLICATION_CLASS = "applicationClass"; public static final String KEY_WINDOW_TITLE = "windowTitle"; 34 public ViewRCPTemplate() { 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.ViewRCPTemplate_title); 42 page.setDescription(PDETemplateMessages.ViewRCPTemplate_desc); 43 wizard.addPage(page); 44 markPagesAdded(); 45 } 46 47 48 private void createOptions() { 49 addOption(KEY_WINDOW_TITLE, PDETemplateMessages.ViewRCPTemplate_windowTitle, "RCP Application", 0); 51 addOption(KEY_PACKAGE_NAME, PDETemplateMessages.ViewRCPTemplate_packageName, (String ) null, 0); 52 53 addOption(KEY_APPLICATION_CLASS, PDETemplateMessages.ViewRCPTemplate_appClass, "Application", 0); 55 createBrandingOptions(); 56 } 57 58 protected void initializeFields(IFieldData data) { 59 String id = data.getId(); 62 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 63 } 64 65 public void initializeFields(IPluginModelBase model) { 66 String pluginId = model.getPluginBase().getId(); 69 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 70 } 71 72 77 public String getSectionId() { 78 return "viewRCP"; } 80 81 84 protected void updateModel(IProgressMonitor monitor) throws CoreException { 85 createApplicationExtension(); 86 createPerspectiveExtension(); 87 createViewExtension(); 88 if (getBooleanOption(KEY_PRODUCT_BRANDING)) 89 createProductExtension(); 90 } 91 92 private void createApplicationExtension() throws CoreException { 93 IPluginBase plugin = model.getPluginBase(); 94 95 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(VALUE_APPLICATION_ID); 97 98 IPluginElement element = model.getPluginFactory().createElement(extension); 99 element.setName("application"); extension.add(element); 101 102 IPluginElement run = model.getPluginFactory().createElement(element); 103 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 106 107 if (!extension.isInTheModel()) 108 plugin.add(extension); 109 } 110 111 private void createPerspectiveExtension() throws CoreException { 112 IPluginBase plugin = model.getPluginBase(); 113 114 IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement element = model.getPluginFactory().createElement(extension); 116 element.setName("perspective"); element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); element.setAttribute("name", "Perspective"); element.setAttribute("id", plugin.getId() + ".perspective"); extension.add(element); 121 122 if (!extension.isInTheModel()) 123 plugin.add(extension); 124 } 125 126 private void createViewExtension() throws CoreException { 127 IPluginBase plugin = model.getPluginBase(); 128 String id = plugin.getId(); 129 IPluginExtension extension = createExtension("org.eclipse.ui.views", true); 131 IPluginElement view = model.getPluginFactory().createElement(extension); 132 view.setName("view"); view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); view.setAttribute("name", "View"); view.setAttribute("id", id + ".view"); extension.add(view); 137 138 if (!extension.isInTheModel()) 139 plugin.add(extension); 140 } 141 142 private void createProductExtension() throws CoreException { 143 IPluginBase plugin = model.getPluginBase(); 144 IPluginExtension extension = createExtension("org.eclipse.core.runtime.products", true); extension.setId(VALUE_PRODUCT_ID); 146 147 IPluginElement element = model.getFactory().createElement(extension); 148 element.setName("product"); element.setAttribute("name", getStringOption(KEY_WINDOW_TITLE)); element.setAttribute("application", plugin.getId() + "." + VALUE_APPLICATION_ID); 152 IPluginElement property = model.getFactory().createElement(element); 153 154 property = model.getFactory().createElement(element); 155 property.setName("property"); property.setAttribute("name", "windowImages"); property.setAttribute("value", "icons/alt_window_16.gif,icons/alt_window_32.gif"); element.add(property); 159 160 extension.add(element); 161 162 if (!extension.isInTheModel()) 163 plugin.add(extension); 164 } 165 166 171 public String getUsedExtensionPoint() { 172 return null; 173 } 174 175 178 public boolean isDependentOnParentWizard() { 179 return true; 180 } 181 182 185 public int getNumberOfWorkUnits() { 186 return super.getNumberOfWorkUnits() + 1; 187 } 188 189 192 public IPluginReference[] getDependencies(String schemaVersion) { 193 IPluginReference[] dep = new IPluginReference[2]; 194 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); return dep; 197 } 198 199 202 public String [] getNewFiles() { 203 if (copyBrandingDirectory()) 204 return new String [] { "icons/", "splash.bmp" }; return super.getNewFiles(); 206 } 207 } 208 | Popular Tags |