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.core.plugin.IPluginReference; 23 import org.eclipse.pde.internal.ui.templates.IHelpContextIds; 24 import org.eclipse.pde.internal.ui.templates.PDETemplateMessages; 25 import org.eclipse.pde.internal.ui.templates.PDETemplateSection; 26 import org.eclipse.pde.internal.ui.templates.PluginReference; 27 import org.eclipse.pde.ui.IFieldData; 28 29 public class PopupMenuTemplate extends PDETemplateSection { 30 31 public static final String KEY_TARGET_OBJECT = "objectClass"; public static final String KEY_SUBMENU_LABEL = "subMenuLabel"; public static final String KEY_ACTION_LABEL = "actionLabel"; public static final String KEY_ACTION_CLASS = "actionClass"; public static final String KEY_SELECTION = "selection"; 37 40 public PopupMenuTemplate() { 41 setPageCount(1); 42 createOptions(); 43 } 44 45 public void addPages(Wizard wizard) { 46 WizardPage page = createPage(0, IHelpContextIds.TEMPLATE_POPUP_MENU); 47 page.setTitle(PDETemplateMessages.PopupMenuTemplate_title); 48 page.setDescription(PDETemplateMessages.PopupMenuTemplate_desc); 49 wizard.addPage(page); 50 markPagesAdded(); 51 } 52 53 private void createOptions() { 54 addOption( 55 KEY_TARGET_OBJECT, 56 PDETemplateMessages.PopupMenuTemplate_targetClass, 57 "org.eclipse.core.resources.IFile", 0); 59 addOption( 60 KEY_SUBMENU_LABEL, 61 PDETemplateMessages.PopupMenuTemplate_submenuName, 62 PDETemplateMessages.PopupMenuTemplate_defaultSubmenuName, 63 0); 64 addOption( 65 KEY_ACTION_LABEL, 66 PDETemplateMessages.PopupMenuTemplate_actionLabel, 67 PDETemplateMessages.PopupMenuTemplate_defaultActionName, 68 0); 69 addOption( 70 KEY_PACKAGE_NAME, 71 PDETemplateMessages.PopupMenuTemplate_packageName, 72 (String ) null, 73 0); 74 addOption( 75 KEY_ACTION_CLASS, 76 PDETemplateMessages.PopupMenuTemplate_actionClass, 77 PDETemplateMessages.PopupMenuTemplate_newAction, 78 0); 79 addOption( 80 KEY_SELECTION, 81 PDETemplateMessages.PopupMenuTemplate_enabledFor, 82 new String [][] { 83 { "singleSelection", PDETemplateMessages.PopupMenuTemplate_singleSelection}, { 85 "multipleSelection", PDETemplateMessages.PopupMenuTemplate_multipleSelection } 87 }, "singleSelection", 0); } 89 92 public String getSectionId() { 93 return "popupMenus"; } 95 96 public boolean isDependentOnParentWizard() { 97 return true; 98 } 99 100 protected void initializeFields(IFieldData data) { 101 String id = data.getId(); 104 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id)); 105 } 106 107 public void initializeFields(IPluginModelBase model) { 108 String pluginId = model.getPluginBase().getId(); 111 initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(pluginId)); 112 } 113 114 117 protected void updateModel(IProgressMonitor monitor) throws CoreException { 118 IPluginBase plugin = model.getPluginBase(); 119 IPluginExtension extension = createExtension(getUsedExtensionPoint(), true); 120 IPluginModelFactory factory = model.getPluginFactory(); 121 122 IPluginElement objectContributionElement = factory.createElement(extension); 123 objectContributionElement.setName("objectContribution"); objectContributionElement.setAttribute( 125 "objectClass", getStringOption(KEY_TARGET_OBJECT)); 127 objectContributionElement.setAttribute( 128 "id", model.getPluginBase().getId() + ".contribution1"); 131 IPluginElement menuElement = factory.createElement(objectContributionElement); 132 menuElement.setName("menu"); menuElement.setAttribute("label", getStringOption(KEY_SUBMENU_LABEL)); menuElement.setAttribute("path", "additions"); menuElement.setAttribute("id", model.getPluginBase().getId() + ".menu1"); 137 IPluginElement separatorElement = factory.createElement(menuElement); 138 separatorElement.setName("separator"); separatorElement.setAttribute("name", "group1"); menuElement.add(separatorElement); 141 objectContributionElement.add(menuElement); 142 143 IPluginElement actionElement = factory.createElement(objectContributionElement); 144 actionElement.setName("action"); actionElement.setAttribute("label", getStringOption(KEY_ACTION_LABEL)); actionElement.setAttribute( 147 "class", getStringOption(KEY_PACKAGE_NAME) + "." + getStringOption(KEY_ACTION_CLASS)); actionElement.setAttribute( 150 "menubarPath", model.getPluginBase().getId() + ".menu1/group1"); actionElement.setAttribute( 153 "enablesFor", getValue(KEY_SELECTION).toString().equals("singleSelection") ? "1" : "multiple"); actionElement.setAttribute("id", model.getPluginBase().getId() + ".newAction"); objectContributionElement.add(actionElement); 159 160 extension.add(objectContributionElement); 161 if (!extension.isInTheModel()) 162 plugin.add(extension); 163 } 164 165 168 public String getUsedExtensionPoint() { 169 return "org.eclipse.ui.popupMenus"; } 171 172 175 protected String getFormattedPackageName(String id) { 176 String packageName = super.getFormattedPackageName(id); 177 if (packageName.length() !=0) 178 return packageName + ".popup.actions"; return "popup.actions"; } 181 182 public IPluginReference[] getDependencies(String schemaVersion) { 183 IPluginReference[] result = new IPluginReference[2]; 184 result[0] = new PluginReference("org.eclipse.ui", null, 0); result[1] = new PluginReference("org.eclipse.core.resources", null, 0); return result; 187 } 188 189 } 190 | Popular Tags |