001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.templates.ide;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IProgressMonitor;
014: import org.eclipse.jface.wizard.Wizard;
015: import org.eclipse.jface.wizard.WizardPage;
016: import org.eclipse.pde.core.plugin.IPluginBase;
017: import org.eclipse.pde.core.plugin.IPluginElement;
018: import org.eclipse.pde.core.plugin.IPluginExtension;
019: import org.eclipse.pde.core.plugin.IPluginModelBase;
020: import org.eclipse.pde.core.plugin.IPluginModelFactory;
021: import org.eclipse.pde.core.plugin.IPluginReference;
022: import org.eclipse.pde.internal.ui.templates.IHelpContextIds;
023: import org.eclipse.pde.internal.ui.templates.PDETemplateMessages;
024: import org.eclipse.pde.internal.ui.templates.PDETemplateSection;
025: import org.eclipse.pde.internal.ui.templates.PluginReference;
026: import org.eclipse.pde.ui.IFieldData;
027:
028: public class PopupMenuTemplate extends PDETemplateSection {
029:
030: public static final String KEY_TARGET_OBJECT = "objectClass"; //$NON-NLS-1$
031: public static final String KEY_SUBMENU_LABEL = "subMenuLabel"; //$NON-NLS-1$
032: public static final String KEY_ACTION_LABEL = "actionLabel"; //$NON-NLS-1$
033: public static final String KEY_ACTION_CLASS = "actionClass"; //$NON-NLS-1$
034: public static final String KEY_SELECTION = "selection"; //$NON-NLS-1$
035:
036: /**
037: * Constructor for PropertyPageTemplate.
038: */
039: public PopupMenuTemplate() {
040: setPageCount(1);
041: createOptions();
042: }
043:
044: public void addPages(Wizard wizard) {
045: WizardPage page = createPage(0,
046: IHelpContextIds.TEMPLATE_POPUP_MENU);
047: page.setTitle(PDETemplateMessages.PopupMenuTemplate_title);
048: page.setDescription(PDETemplateMessages.PopupMenuTemplate_desc);
049: wizard.addPage(page);
050: markPagesAdded();
051: }
052:
053: private void createOptions() {
054: addOption(KEY_TARGET_OBJECT,
055: PDETemplateMessages.PopupMenuTemplate_targetClass,
056: "org.eclipse.core.resources.IFile", //$NON-NLS-1$
057: 0);
058: addOption(
059: KEY_SUBMENU_LABEL,
060: PDETemplateMessages.PopupMenuTemplate_submenuName,
061: PDETemplateMessages.PopupMenuTemplate_defaultSubmenuName,
062: 0);
063: addOption(
064: KEY_ACTION_LABEL,
065: PDETemplateMessages.PopupMenuTemplate_actionLabel,
066: PDETemplateMessages.PopupMenuTemplate_defaultActionName,
067: 0);
068: addOption(KEY_PACKAGE_NAME,
069: PDETemplateMessages.PopupMenuTemplate_packageName,
070: (String) null, 0);
071: addOption(KEY_ACTION_CLASS,
072: PDETemplateMessages.PopupMenuTemplate_actionClass,
073: PDETemplateMessages.PopupMenuTemplate_newAction, 0);
074: addOption(
075: KEY_SELECTION,
076: PDETemplateMessages.PopupMenuTemplate_enabledFor,
077: new String[][] {
078: {
079: "singleSelection", PDETemplateMessages.PopupMenuTemplate_singleSelection }, //$NON-NLS-1$
080: {
081: "multipleSelection", PDETemplateMessages.PopupMenuTemplate_multipleSelection //$NON-NLS-1$
082: } }, "singleSelection", 0); //$NON-NLS-1$
083: }
084:
085: /**
086: * @see PDETemplateSection#getSectionId()
087: */
088: public String getSectionId() {
089: return "popupMenus"; //$NON-NLS-1$
090: }
091:
092: public boolean isDependentOnParentWizard() {
093: return true;
094: }
095:
096: protected void initializeFields(IFieldData data) {
097: // In a new project wizard, we don't know this yet - the
098: // model has not been created
099: String id = data.getId();
100: initializeOption(KEY_PACKAGE_NAME, getFormattedPackageName(id));
101: }
102:
103: public void initializeFields(IPluginModelBase model) {
104: // In the new extension wizard, the model exists so
105: // we can initialize directly from it
106: String pluginId = model.getPluginBase().getId();
107: initializeOption(KEY_PACKAGE_NAME,
108: getFormattedPackageName(pluginId));
109: }
110:
111: /**
112: * @see AbstractTemplateSection#updateModel(IProgressMonitor)
113: */
114: protected void updateModel(IProgressMonitor monitor)
115: throws CoreException {
116: IPluginBase plugin = model.getPluginBase();
117: IPluginExtension extension = createExtension(
118: getUsedExtensionPoint(), true);
119: IPluginModelFactory factory = model.getPluginFactory();
120:
121: IPluginElement objectContributionElement = factory
122: .createElement(extension);
123: objectContributionElement.setName("objectContribution"); //$NON-NLS-1$
124: objectContributionElement.setAttribute("objectClass", //$NON-NLS-1$
125: getStringOption(KEY_TARGET_OBJECT));
126: objectContributionElement.setAttribute("id", //$NON-NLS-1$
127: model.getPluginBase().getId() + ".contribution1"); //$NON-NLS-1$
128:
129: IPluginElement menuElement = factory
130: .createElement(objectContributionElement);
131: menuElement.setName("menu"); //$NON-NLS-1$
132: menuElement.setAttribute(
133: "label", getStringOption(KEY_SUBMENU_LABEL)); //$NON-NLS-1$
134: menuElement.setAttribute("path", "additions"); //$NON-NLS-1$ //$NON-NLS-2$
135: menuElement.setAttribute(
136: "id", model.getPluginBase().getId() + ".menu1"); //$NON-NLS-1$ //$NON-NLS-2$
137:
138: IPluginElement separatorElement = factory
139: .createElement(menuElement);
140: separatorElement.setName("separator"); //$NON-NLS-1$
141: separatorElement.setAttribute("name", "group1"); //$NON-NLS-1$ //$NON-NLS-2$
142: menuElement.add(separatorElement);
143: objectContributionElement.add(menuElement);
144:
145: IPluginElement actionElement = factory
146: .createElement(objectContributionElement);
147: actionElement.setName("action"); //$NON-NLS-1$
148: actionElement.setAttribute(
149: "label", getStringOption(KEY_ACTION_LABEL)); //$NON-NLS-1$
150: actionElement.setAttribute("class", //$NON-NLS-1$
151: getStringOption(KEY_PACKAGE_NAME)
152: + "." + getStringOption(KEY_ACTION_CLASS)); //$NON-NLS-1$
153: actionElement.setAttribute("menubarPath", //$NON-NLS-1$
154: model.getPluginBase().getId() + ".menu1/group1"); //$NON-NLS-1$
155: actionElement.setAttribute("enablesFor", //$NON-NLS-1$
156: getValue(KEY_SELECTION).toString().equals(
157: "singleSelection") //$NON-NLS-1$
158: ? "1" //$NON-NLS-1$
159: : "multiple"); //$NON-NLS-1$
160: actionElement.setAttribute(
161: "id", model.getPluginBase().getId() + ".newAction"); //$NON-NLS-1$ //$NON-NLS-2$
162: objectContributionElement.add(actionElement);
163:
164: extension.add(objectContributionElement);
165: if (!extension.isInTheModel())
166: plugin.add(extension);
167: }
168:
169: /**
170: * @see ITemplateSection#getUsedExtensionPoint()
171: */
172: public String getUsedExtensionPoint() {
173: return "org.eclipse.ui.popupMenus"; //$NON-NLS-1$
174: }
175:
176: /* (non-Javadoc)
177: * @see org.eclipse.pde.internal.ui.wizards.templates.PDETemplateSection#formatPackageName(java.lang.String)
178: */
179: protected String getFormattedPackageName(String id) {
180: String packageName = super .getFormattedPackageName(id);
181: if (packageName.length() != 0)
182: return packageName + ".popup.actions"; //$NON-NLS-1$
183: return "popup.actions"; //$NON-NLS-1$
184: }
185:
186: public IPluginReference[] getDependencies(String schemaVersion) {
187: IPluginReference[] result = new IPluginReference[2];
188: result[0] = new PluginReference("org.eclipse.ui", null, 0); //$NON-NLS-1$
189: result[1] = new PluginReference(
190: "org.eclipse.core.resources", null, 0); //$NON-NLS-1$
191: return result;
192: }
193:
194: }
|