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 HelloNonUIRCPTemplate extends PDETemplateSection { 29 30 public static final String KEY_APPLICATION_CLASS = "applicationClass"; public static final String KEY_APPLICATION_MESSAGE = "message"; 33 public HelloNonUIRCPTemplate() { 34 setPageCount(1); 35 createOptions(); 36 } 37 38 public void addPages(Wizard wizard) { 39 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_RCP_MAIL); 40 page.setTitle(PDEUIMessages.HelloNonUIRCPTemplate_title); 41 page.setDescription(PDEUIMessages.HelloNonUIRCPTemplate_desc); 42 wizard.addPage(page); 43 markPagesAdded(); 44 } 45 46 47 private void createOptions() { 48 addOption(KEY_PACKAGE_NAME, 49 PDEUIMessages.MailTemplate_packageName, 50 (String ) null, 0); 51 52 addOption(KEY_APPLICATION_CLASS, 53 PDEUIMessages.HelloNonUIRCPTemplate_appClass, 54 "Application", 0); 56 addOption(KEY_APPLICATION_MESSAGE, 57 PDEUIMessages.HelloNonUIRCPTemplate_messageText, 58 PDEUIMessages.HelloNonUIRCPTemplate_defaultMessage, 0); 59 } 60 61 protected void initializeFields(IFieldData data) { 62 String packageName = getFormattedPackageName(data.getId()); 65 initializeOption(KEY_PACKAGE_NAME, packageName); 66 } 67 68 public void initializeFields(IPluginModelBase model) { 69 String packageName = getFormattedPackageName(model.getPluginBase().getId()); 70 initializeOption(KEY_PACKAGE_NAME, packageName); 71 } 72 73 78 public String getSectionId() { 79 return "helloNonUIRCP"; } 81 82 85 public void validateOptions(TemplateOption source) { 86 if (source.isRequired() && source.isEmpty()) { 87 flagMissingRequiredOption(source); 88 } else { 89 validateContainerPage(source); 90 } 91 } 92 93 private void validateContainerPage(TemplateOption source) { 94 TemplateOption[] allPageOptions = getOptions(0); 95 for (int i = 0; i < allPageOptions.length; i++) { 96 TemplateOption nextOption = allPageOptions[i]; 97 if (nextOption.isRequired() && nextOption.isEmpty()) { 98 flagMissingRequiredOption(nextOption); 99 return; 100 } 101 } 102 resetPageState(); 103 } 104 105 108 protected void updateModel(IProgressMonitor monitor) throws CoreException { 109 createApplicationExtension(); 110 } 111 112 private void createApplicationExtension() throws CoreException { 113 IPluginBase plugin = model.getPluginBase(); 114 115 IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); extension.setId("application"); 118 IPluginElement element = model.getPluginFactory().createElement(extension); 119 element.setName("application"); extension.add(element); 121 122 IPluginElement run = model.getPluginFactory().createElement(element); 123 run.setName("run"); run.setAttribute("class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_APPLICATION_CLASS)); element.add(run); 126 127 if (!extension.isInTheModel()) 128 plugin.add(extension); 129 } 130 131 134 public String getUsedExtensionPoint() { 135 return null; 136 } 137 138 141 public boolean isDependentOnParentWizard() { 142 return true; 143 } 144 145 148 public int getNumberOfWorkUnits() { 149 return super.getNumberOfWorkUnits() + 1; 150 } 151 152 155 public IPluginReference[] getDependencies(String schemaVersion) { 156 IPluginReference[] dep = new IPluginReference[1]; 157 dep[0] = new PluginReference("org.eclipse.core.runtime", null, 0); return dep; 159 } 160 161 } 162 | Popular Tags |