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.ui.IHelpContextIds; 23 import org.eclipse.pde.internal.ui.PDEUIMessages; 24 import org.eclipse.pde.ui.IFieldData; 25 import org.eclipse.pde.ui.templates.TemplateOption; 26 27 28 public class ViewRCPTemplate extends PDETemplateSection { 29 30 public static final String KEY_APPLICATION_CLASS = "applicationClass"; public static final String KEY_APPLICATION_ID = "applicationID"; 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(PDEUIMessages.ViewRCPTemplate_title); 42 page.setDescription(PDEUIMessages.ViewRCPTemplate_desc); 43 wizard.addPage(page); 44 markPagesAdded(); 45 } 46 47 48 private void createOptions() { 49 addOption(KEY_WINDOW_TITLE, PDEUIMessages.ViewRCPTemplate_windowTitle, "RCP Application", 0); 51 addOption(KEY_APPLICATION_ID, PDEUIMessages.ViewRCPTemplate_appId, "application", 0); 53 addOption(KEY_PACKAGE_NAME, PDEUIMessages.ViewRCPTemplate_packageName, (String ) null, 0); 54 55 addOption(KEY_APPLICATION_CLASS, PDEUIMessages.ViewRCPTemplate_appClass, "Application", 0); } 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 public void validateOptions(TemplateOption source) { 85 if (source.isRequired() && source.isEmpty()) { 86 flagMissingRequiredOption(source); 87 } else { 88 validateContainerPage(source); 89 } 90 } 91 92 private void validateContainerPage(TemplateOption source) { 93 TemplateOption[] allPageOptions = getOptions(0); 94 for (int i = 0; i < allPageOptions.length; i++) { 95 TemplateOption nextOption = allPageOptions[i]; 96 if (nextOption.isRequired() && nextOption.isEmpty()) { 97 flagMissingRequiredOption(nextOption); 98 return; 99 } 100 } 101 resetPageState(); 102 } 103 104 107 protected void updateModel(IProgressMonitor monitor) throws CoreException { 108 createApplicationExtension(); 109 createPerspectiveExtension(); 110 createViewExtension(); 111 } 112 113 private void createApplicationExtension() throws CoreException { 114 IPluginBase plugin = model.getPluginBase(); 115 116 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(getStringOption(KEY_APPLICATION_ID)); 118 119 IPluginElement element = model.getPluginFactory().createElement(extension); 120 element.setName("application"); extension.add(element); 122 123 IPluginElement run = model.getPluginFactory().createElement(element); 124 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 127 128 if (!extension.isInTheModel()) 129 plugin.add(extension); 130 } 131 132 private void createPerspectiveExtension() throws CoreException { 133 IPluginBase plugin = model.getPluginBase(); 134 135 IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement element = model.getPluginFactory().createElement(extension); 137 element.setName("perspective"); element.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".Perspective"); element.setAttribute("name", "Perspective"); element.setAttribute("id", plugin.getId() + ".perspective"); extension.add(element); 142 143 if (!extension.isInTheModel()) 144 plugin.add(extension); 145 } 146 147 private void createViewExtension() throws CoreException { 148 IPluginBase plugin = model.getPluginBase(); 149 String id = plugin.getId(); 150 IPluginExtension extension = createExtension("org.eclipse.ui.views", true); 152 IPluginElement view = model.getPluginFactory().createElement(extension); 153 view.setName("view"); view.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + ".View" ); view.setAttribute("name", "View"); view.setAttribute("id", id + ".view"); extension.add(view); 158 159 if (!extension.isInTheModel()) 160 plugin.add(extension); 161 } 162 163 166 public String getUsedExtensionPoint() { 167 return null; 168 } 169 170 173 public boolean isDependentOnParentWizard() { 174 return true; 175 } 176 177 180 public int getNumberOfWorkUnits() { 181 return super.getNumberOfWorkUnits() + 1; 182 } 183 184 187 public IPluginReference[] getDependencies(String schemaVersion) { 188 IPluginReference[] dep = new IPluginReference[2]; 189 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); return dep; 192 } 193 194 } 195 | Popular Tags |