01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.actions;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.jface.action.ActionContributionItem;
14: import org.eclipse.jface.action.IMenuCreator;
15: import org.eclipse.swt.widgets.Control;
16: import org.eclipse.swt.widgets.Menu;
17:
18: public class ActionMenu extends Action implements IMenuCreator {
19:
20: Action[] fActions;
21: Menu fMenu;
22:
23: public ActionMenu(Action[] actions) {
24: fActions = actions;
25: if (fActions.length > 0) {
26: setToolTipText(fActions[0].getToolTipText());
27: setImageDescriptor(fActions[0].getImageDescriptor());
28: if (fActions.length > 1)
29: setMenuCreator(this );
30: }
31: }
32:
33: public void run() {
34: if (fActions.length > 0)
35: fActions[0].run();
36: }
37:
38: public void dispose() {
39: if (fMenu != null) {
40: fMenu.dispose();
41: fMenu = null;
42: }
43: }
44:
45: public Menu getMenu(Control parent) {
46: if (fMenu != null)
47: fMenu.dispose();
48: fMenu = new Menu(parent);
49:
50: for (int i = 0; i < fActions.length; i++) {
51: addActionToMenu(fMenu, fActions[i]);
52: }
53: return fMenu;
54: }
55:
56: public Menu getMenu(Menu parent) {
57: return null;
58: }
59:
60: protected void addActionToMenu(Menu parent, Action action) {
61: ActionContributionItem item = new ActionContributionItem(action);
62: item.fill(parent, -1);
63: }
64: }
|