KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > menus > MenuContribution


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.ui.internal.menus;
13
14 import org.eclipse.core.expressions.Expression;
15 import org.eclipse.ui.ISources;
16 import org.eclipse.ui.internal.services.EvaluationResultCache;
17
18 /**
19  * <p>
20  * A token representing the contribution of a menu element. This token can later
21  * be used to cancel that contribution. Without this token, then menu element
22  * will only become inactive if the component in which the handler was
23  * contributed is destroyed.
24  * </p>
25  * <p>
26  * This caches the menu element, so that they can later be identified.
27  * </p>
28  * <p>
29  * This class is not intended for use outside of the
30  * <code>org.eclipse.ui.workbench</code> plug-in.
31  * </p>
32  *
33  * @since 3.2
34  */

35 final class MenuContribution extends EvaluationResultCache implements
36         IMenuContribution {
37
38     /**
39      * The menu element that has been contributed. This value may be
40      * <code>null</code>.
41      */

42     private final MenuElement menuElement;
43
44     /**
45      * The menu service from which this menu contribution was request. This
46      * value is never <code>null</code>.
47      */

48     private final IMenuService menuService;
49
50     /**
51      * Constructs a new instance of <code>MenuContribution</code>.
52      *
53      * @param menuElement
54      * The menu element that has been contributed. This value may be
55      * <code>null</code>.
56      * @param expression
57      * The expression that must evaluate to <code>true</code>
58      * before this menu contribution is visible. This value may be
59      * <code>null</code> if it is always active.
60      * @param menuService
61      * The menu service from which the contribution was requested;
62      * must not be <code>null</code>.
63      * @see ISources
64      */

65     public MenuContribution(final MenuElement menuElement,
66             final Expression expression, final IMenuService menuService) {
67         super(expression);
68
69         if (menuElement == null) {
70             throw new NullPointerException JavaDoc(
71                     "The menu element for a contribution cannot be null"); //$NON-NLS-1$
72
}
73
74         if (menuService == null) {
75             throw new NullPointerException JavaDoc(
76                     "The menu service for a contribution cannot be null"); //$NON-NLS-1$
77
}
78
79         this.menuElement = menuElement;
80         this.menuService = menuService;
81     }
82
83     public final MenuElement getMenuElement() {
84         return menuElement;
85     }
86
87     public final IMenuService getMenuService() {
88         return menuService;
89     }
90
91     public final String JavaDoc toString() {
92         final StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
93
94         buffer.append("MenuContribution(menuElement="); //$NON-NLS-1$
95
buffer.append(menuElement);
96         buffer.append(",menuService="); //$NON-NLS-1$
97
buffer.append(menuService);
98         buffer.append(",sourcePriority="); //$NON-NLS-1$
99
buffer.append(getSourcePriority());
100         buffer.append(')');
101
102         return buffer.toString();
103     }
104 }
105
Popular Tags