01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 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.ui.internal;
11:
12: import org.eclipse.jface.action.IContributionItem;
13: import org.eclipse.jface.action.IMenuManager;
14: import org.eclipse.jface.action.SubContributionItem;
15: import org.eclipse.jface.action.SubMenuManager;
16:
17: /**
18: * An <code>EditorMenuManager</code> is used to sort the contributions
19: * made by an editor so that they always appear after the action sets.
20: */
21: public class ActionSetMenuManager extends SubMenuManager {
22: private String actionSetId;
23:
24: /**
25: * Constructs a new editor manager.
26: */
27: public ActionSetMenuManager(IMenuManager mgr, String actionSetId) {
28: super (mgr);
29: this .actionSetId = actionSetId;
30: }
31:
32: /* (non-Javadoc)
33: * Method declared on IContributionManager.
34: *
35: * Returns the item passed to us, not the wrapper.
36: * In the case of menu's not added by this manager,
37: * ensure that we return a wrapper for the menu.
38: */
39: public IContributionItem find(String id) {
40: IContributionItem item = getParentMenuManager().find(id);
41: if (item instanceof SubContributionItem) {
42: // Return the item passed to us, not the wrapper.
43: item = unwrap(item);
44: }
45:
46: if (item instanceof IMenuManager) {
47: // if it is a menu manager wrap it before returning
48: IMenuManager menu = (IMenuManager) item;
49: if (menu instanceof SubMenuManager) {
50: // it it is already wrapped then remover the wrapper and
51: // rewrap. We have a table of wrappers so we reuse wrappers
52: // we create.
53: menu = (IMenuManager) ((SubMenuManager) menu)
54: .getParent();
55: }
56: item = getWrapper(menu);
57: }
58:
59: return item;
60: }
61:
62: /* (non-Javadoc)
63: * Method declared on IContributionManager.
64: */
65: public IContributionItem[] getItems() {
66: return getParentMenuManager().getItems();
67: }
68:
69: /* (non-Javadoc)
70: * Method declared on SubContributionManager.
71: */
72: protected SubContributionItem wrap(IContributionItem item) {
73: return new ActionSetContributionItem(item, actionSetId);
74: }
75:
76: /* (non-Javadoc)
77: * Method declared on SubMenuManager.
78: */
79: protected SubMenuManager wrapMenu(IMenuManager menu) {
80: return new ActionSetMenuManager(menu, actionSetId);
81: }
82: }
|