KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ActionSetMenuManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal;
12
13 import org.eclipse.jface.action.IContributionItem;
14 import org.eclipse.jface.action.IMenuManager;
15 import org.eclipse.jface.action.SubContributionItem;
16 import org.eclipse.jface.action.SubMenuManager;
17
18 /**
19  * An <code>EditorMenuManager</code> is used to sort the contributions
20  * made by an editor so that they always appear after the action sets.
21  */

22 public class ActionSetMenuManager extends SubMenuManager {
23     private String JavaDoc actionSetId;
24
25     /**
26      * Constructs a new editor manager.
27      */

28     public ActionSetMenuManager(IMenuManager mgr, String JavaDoc actionSetId) {
29         super(mgr);
30         this.actionSetId = actionSetId;
31     }
32
33     /* (non-Javadoc)
34      * Method declared on IContributionManager.
35      *
36      * Returns the item passed to us, not the wrapper.
37      * In the case of menu's not added by this manager,
38      * ensure that we return a wrapper for the menu.
39      */

40     public IContributionItem find(String JavaDoc id) {
41         IContributionItem item = getParentMenuManager().find(id);
42         if (item instanceof SubContributionItem) {
43             // Return the item passed to us, not the wrapper.
44
item = unwrap(item);
45         }
46
47         if (item instanceof IMenuManager) {
48             // if it is a menu manager wrap it before returning
49
IMenuManager menu = (IMenuManager) item;
50             if (menu instanceof SubMenuManager) {
51                 // it it is already wrapped then remover the wrapper and
52
// rewrap. We have a table of wrappers so we reuse wrappers
53
// we create.
54
menu = (IMenuManager) ((SubMenuManager) menu).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 }
83
Popular Tags