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.IPluginModelFactory; 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 public class HelloWorldTemplate extends PDETemplateSection { 28 public static final String KEY_CLASS_NAME = "className"; public static final String KEY_MESSAGE = "message"; public static final String CLASS_NAME = "SampleAction"; 32 35 public HelloWorldTemplate() { 36 setPageCount(1); 37 createOptions(); 38 } 39 40 public String getSectionId() { 41 return "helloWorld"; } 43 46 public int getNumberOfWorkUnits() { 47 return super.getNumberOfWorkUnits() + 1; 48 } 49 50 private void createOptions() { 51 addOption( 52 KEY_PACKAGE_NAME, 53 PDEUIMessages.HelloWorldTemplate_packageName, 54 (String ) null, 55 0); 56 addOption( 57 KEY_CLASS_NAME, 58 PDEUIMessages.HelloWorldTemplate_className, 59 CLASS_NAME, 60 0); 61 addOption( 62 KEY_MESSAGE, 63 PDEUIMessages.HelloWorldTemplate_messageText, 64 PDEUIMessages.HelloWorldTemplate_defaultMessage, 65 0); 66 } 67 68 public void addPages(Wizard wizard) { 69 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_HELLO_WORLD); 70 page.setTitle(PDEUIMessages.HelloWorldTemplate_title); 71 page.setDescription(PDEUIMessages.HelloWorldTemplate_desc); 72 wizard.addPage(page); 73 markPagesAdded(); 74 } 75 76 public void validateOptions(TemplateOption source) { 77 if (source.isRequired() && source.isEmpty()) { 78 flagMissingRequiredOption(source); 79 } else { 80 validateContainerPage(source); 81 } 82 } 83 84 private void validateContainerPage(TemplateOption source) { 85 TemplateOption[] allPageOptions = getOptions(0); 86 for (int i = 0; i < allPageOptions.length; i++) { 87 TemplateOption nextOption = allPageOptions[i]; 88 if (nextOption.isRequired() && nextOption.isEmpty()) { 89 flagMissingRequiredOption(nextOption); 90 return; 91 } 92 } 93 resetPageState(); 94 } 95 96 97 public boolean isDependentOnParentWizard() { 98 return true; 99 } 100 101 protected void initializeFields(IFieldData data) { 102 String id = data.getId(); 105 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 106 } 107 public void initializeFields(IPluginModelBase model) { 108 String pluginId = model.getPluginBase().getId(); 111 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 112 } 113 114 public String getUsedExtensionPoint() { 115 return "org.eclipse.ui.actionSets"; } 117 118 protected void updateModel(IProgressMonitor monitor) throws CoreException { 119 IPluginBase plugin = model.getPluginBase(); 120 IPluginExtension extension = createExtension("org.eclipse.ui.actionSets", true); IPluginModelFactory factory = model.getPluginFactory(); 122 123 IPluginElement setElement = factory.createElement(extension); 124 setElement.setName("actionSet"); setElement.setAttribute("id", plugin.getId() + ".actionSet"); setElement.setAttribute("label", PDEUIMessages.HelloWorldTemplate_sampleActionSet); setElement.setAttribute("visible", "true"); 129 IPluginElement menuElement = factory.createElement(setElement); 130 menuElement.setName("menu"); menuElement.setAttribute("label", PDEUIMessages.HelloWorldTemplate_sampleMenu); menuElement.setAttribute("id", "sampleMenu"); 134 IPluginElement groupElement = factory.createElement(menuElement); 135 groupElement.setName("separator"); groupElement.setAttribute("name", "sampleGroup"); menuElement.add(groupElement); 138 setElement.add(menuElement); 139 140 String fullClassName = 141 getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASS_NAME); 143 IPluginElement actionElement = factory.createElement(setElement); 144 actionElement.setName("action"); actionElement.setAttribute("id", fullClassName); actionElement.setAttribute("label", PDEUIMessages.HelloWorldTemplate_sampleAction); actionElement.setAttribute("menubarPath", "sampleMenu/sampleGroup"); actionElement.setAttribute("toolbarPath", "sampleGroup"); actionElement.setAttribute("icon", "icons/sample.gif"); actionElement.setAttribute("tooltip", PDEUIMessages.HelloWorldTemplate_defaultMessage); actionElement.setAttribute("class", fullClassName); setElement.add(actionElement); 153 extension.add(setElement); 154 if (!extension.isInTheModel()) 155 plugin.add(extension); 156 } 157 158 161 public String [] getNewFiles() { 162 return new String [] {"icons/"}; } 164 165 168 protected String getFormattedPackageName(String id) { 169 String packageName = super.getFormattedPackageName(id); 170 if (packageName.length() != 0) 171 return packageName + ".actions"; return "actions"; } 174 } 175 | Popular Tags |