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 HelloRCPTemplate extends PDETemplateSection { 29 30 public static final String KEY_PERSPECTIVE_NAME = "perspectiveName"; public static final String KEY_APPLICATION_CLASS = "applicationClass"; public static final String KEY_APPLICATION_ID = "applicationID"; public static final String KEY_WINDOW_TITLE = "windowTitle"; 35 public HelloRCPTemplate() { 36 setPageCount(1); 37 createOptions(); 38 } 39 40 public void addPages(Wizard wizard) { 41 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL); 42 page.setTitle(PDEUIMessages.HelloRCPTemplate_title); 43 page.setDescription(PDEUIMessages.HelloRCPTemplate_desc); 44 wizard.addPage(page); 45 markPagesAdded(); 46 } 47 48 49 private void createOptions() { 50 addOption(KEY_WINDOW_TITLE, PDEUIMessages.HelloRCPTemplate_windowTitle, "Hello RCP", 0); 52 addOption(KEY_APPLICATION_ID, PDEUIMessages.HelloRCPTemplate_appId, "application", 0); 54 addOption(KEY_PACKAGE_NAME, PDEUIMessages.MailTemplate_packageName, (String ) null, 0); 55 56 addOption(KEY_APPLICATION_CLASS, PDEUIMessages.HelloRCPTemplate_appClass, "Application", 0); 58 addOption(KEY_PERSPECTIVE_NAME, PDEUIMessages.HelloRCPTemplate_perspective, (String ) null, 0); 59 } 60 61 protected void initializeFields(IFieldData data) { 62 String packageName = getFormattedPackageName(data.getId()); 65 initializeOption(KEY_PACKAGE_NAME, packageName); 66 67 int index = packageName.lastIndexOf('.'); 68 String name = packageName.substring(index + 1) + " Perspective"; initializeOption(KEY_PERSPECTIVE_NAME, Character.toUpperCase(name.charAt(0)) + name.substring(1)); 70 } 71 72 public void initializeFields(IPluginModelBase model) { 73 String packageName = getFormattedPackageName(model.getPluginBase().getId()); 74 initializeOption(KEY_PACKAGE_NAME, packageName); 75 76 int index = packageName.lastIndexOf('.'); 77 String name = packageName.substring(index + 1) + " Perspective"; initializeOption(KEY_PERSPECTIVE_NAME, Character.toUpperCase(name.charAt(0)) + name.substring(1)); 79 } 80 81 86 public String getSectionId() { 87 return "helloRCP"; } 89 90 93 public void validateOptions(TemplateOption source) { 94 if (source.isRequired() && source.isEmpty()) { 95 flagMissingRequiredOption(source); 96 } else { 97 validateContainerPage(source); 98 } 99 } 100 101 private void validateContainerPage(TemplateOption source) { 102 TemplateOption[] allPageOptions = getOptions(0); 103 for (int i = 0; i < allPageOptions.length; i++) { 104 TemplateOption nextOption = allPageOptions[i]; 105 if (nextOption.isRequired() && nextOption.isEmpty()) { 106 flagMissingRequiredOption(nextOption); 107 return; 108 } 109 } 110 resetPageState(); 111 } 112 113 116 protected void updateModel(IProgressMonitor monitor) throws CoreException { 117 createApplicationExtension(); 118 createPerspectiveExtension(); 119 } 120 121 private void createApplicationExtension() throws CoreException { 122 IPluginBase plugin = model.getPluginBase(); 123 124 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId(getStringOption(KEY_APPLICATION_ID)); 126 127 IPluginElement element = model.getPluginFactory().createElement(extension); 128 element.setName("application"); extension.add(element); 130 131 IPluginElement run = model.getPluginFactory().createElement(element); 132 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 135 136 if (!extension.isInTheModel()) 137 plugin.add(extension); 138 } 139 140 private void createPerspectiveExtension() throws CoreException { 141 IPluginBase plugin = model.getPluginBase(); 142 143 IPluginExtension extension = createExtension("org.eclipse.ui.perspectives", true); IPluginElement element = model.getPluginFactory().createElement(extension); 145 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); 150 151 if (!extension.isInTheModel()) 152 plugin.add(extension); 153 } 154 155 158 public String getUsedExtensionPoint() { 159 return null; 160 } 161 162 165 public boolean isDependentOnParentWizard() { 166 return true; 167 } 168 169 172 public int getNumberOfWorkUnits() { 173 return super.getNumberOfWorkUnits() + 1; 174 } 175 176 179 public IPluginReference[] getDependencies(String schemaVersion) { 180 IPluginReference[] dep = new IPluginReference[2]; 181 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); dep[1] = new PluginReference("org.eclipse.ui", null, 0); return dep; 184 } 185 186 } 187 | Popular Tags |