1 11 package org.eclipse.pde.internal.ui.templates.ide; 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.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.ui.IFieldData; 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 PDETemplateMessages.HelloWorldTemplate_packageName, 54 (String ) null, 55 0); 56 addOption( 57 KEY_CLASS_NAME, 58 PDETemplateMessages.HelloWorldTemplate_className, 59 CLASS_NAME, 60 0); 61 addOption( 62 KEY_MESSAGE, 63 PDETemplateMessages.HelloWorldTemplate_messageText, 64 PDETemplateMessages.HelloWorldTemplate_defaultMessage, 65 0); 66 } 67 68 public void addPages(Wizard wizard) { 69 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_HELLO_WORLD); 70 page.setTitle(PDETemplateMessages.HelloWorldTemplate_title); 71 page.setDescription(PDETemplateMessages.HelloWorldTemplate_desc); 72 wizard.addPage(page); 73 markPagesAdded(); 74 } 75 76 public boolean isDependentOnParentWizard() { 77 return true; 78 } 79 80 protected void initializeFields(IFieldData data) { 81 String id = data.getId(); 84 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 85 } 86 public void initializeFields(IPluginModelBase model) { 87 String pluginId = model.getPluginBase().getId(); 90 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 91 } 92 93 public String getUsedExtensionPoint() { 94 return "org.eclipse.ui.actionSets"; } 96 97 protected void updateModel(IProgressMonitor monitor) throws CoreException { 98 IPluginBase plugin = model.getPluginBase(); 99 IPluginExtension extension = createExtension("org.eclipse.ui.actionSets", true); IPluginModelFactory factory = model.getPluginFactory(); 101 102 IPluginElement setElement = factory.createElement(extension); 103 setElement.setName("actionSet"); setElement.setAttribute("id", plugin.getId() + ".actionSet"); setElement.setAttribute("label", PDETemplateMessages.HelloWorldTemplate_sampleActionSet); setElement.setAttribute("visible", "true"); 108 IPluginElement menuElement = factory.createElement(setElement); 109 menuElement.setName("menu"); menuElement.setAttribute("label", PDETemplateMessages.HelloWorldTemplate_sampleMenu); menuElement.setAttribute("id", "sampleMenu"); 113 IPluginElement groupElement = factory.createElement(menuElement); 114 groupElement.setName("separator"); groupElement.setAttribute("name", "sampleGroup"); menuElement.add(groupElement); 117 setElement.add(menuElement); 118 119 String fullClassName = 120 getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_CLASS_NAME); 122 IPluginElement actionElement = factory.createElement(setElement); 123 actionElement.setName("action"); actionElement.setAttribute("id", fullClassName); actionElement.setAttribute("label", PDETemplateMessages.HelloWorldTemplate_sampleAction); actionElement.setAttribute("menubarPath", "sampleMenu/sampleGroup"); actionElement.setAttribute("toolbarPath", "sampleGroup"); actionElement.setAttribute("icon", "icons/sample.gif"); actionElement.setAttribute("tooltip", PDETemplateMessages.HelloWorldTemplate_defaultMessage); actionElement.setAttribute("class", fullClassName); setElement.add(actionElement); 132 extension.add(setElement); 133 if (!extension.isInTheModel()) 134 plugin.add(extension); 135 } 136 137 140 public String [] getNewFiles() { 141 return new String [] {"icons/"}; } 143 144 147 protected String getFormattedPackageName(String id) { 148 String packageName = super.getFormattedPackageName(id); 149 if (packageName.length() != 0) 150 return packageName + ".actions"; return "actions"; } 153 } 154 | Popular Tags |