KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 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 java.util.List JavaDoc;
15
16 import org.eclipse.core.expressions.Expression;
17 import org.eclipse.core.expressions.IEvaluationContext;
18 import org.eclipse.jface.action.ContributionManager;
19 import org.eclipse.jface.action.IContributionItem;
20 import org.eclipse.ui.ISourceProvider;
21 import org.eclipse.ui.IWorkbenchWindow;
22 import org.eclipse.ui.internal.expressions.WorkbenchWindowExpression;
23 import org.eclipse.ui.menus.AbstractContributionFactory;
24 import org.eclipse.ui.menus.IMenuService;
25 import org.eclipse.ui.services.IServiceLocator;
26
27 /**
28  * <p>
29  * Provides services related to contributing menu elements to a workbench
30  * window. Visibility and showing are tracked at the workbench window level.
31  * </p>
32  * <p>
33  * This class is only intended for internal use within the
34  * <code>org.eclipse.ui.workbench</code> plug-in.
35  * </p>
36  *
37  * @since 3.2
38  */

39 public final class WindowMenuService extends InternalMenuService {
40
41     /**
42      * The parent menu service for this window. This parent must track menu
43      * definitions and the regsitry. Must not be <code>null</code>
44      */

45     private final WorkbenchMenuService parent;
46     private IServiceLocator serviceLocator;
47     private Expression restrictionExpression;
48
49     /**
50      * Constructs a new instance of <code>MenuService</code> using a menu
51      * manager.
52      *
53      * @param parent
54      * The parent menu service for this window. This parent must
55      * track menu definitions and the regsitry. Must not be
56      * <code>null</code>
57      */

58     public WindowMenuService(final IServiceLocator serviceLocator) {
59         IMenuService menuService = (IMenuService) serviceLocator
60                 .getService(IMenuService.class);
61         if (menuService == null
62                 || !(menuService instanceof WorkbenchMenuService)) {
63             throw new NullPointerException JavaDoc(
64                     "The parent service must not be null"); //$NON-NLS-1$
65
}
66         IWorkbenchWindow window = (IWorkbenchWindow) serviceLocator
67                 .getService(IWorkbenchWindow.class);
68         if (window == null)
69             throw new NullPointerException JavaDoc("Window cannot be null"); //$NON-NLS-1$
70

71         restrictionExpression = new WorkbenchWindowExpression(window);
72
73         this.parent = (WorkbenchMenuService) menuService;
74         this.serviceLocator = serviceLocator;
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see org.eclipse.ui.internal.menus.IMenuService#populateMenu(org.eclipse.jface.action.MenuManager,
81      * org.eclipse.ui.internal.menus.MenuLocationURI)
82      */

83     public void populateContributionManager(ContributionManager mgr, String JavaDoc uri) {
84         parent.populateContributionManager(serviceLocator,
85                 restrictionExpression, mgr, uri, true);
86     }
87
88     public void populateContributionManager(ContributionManager mgr,
89             String JavaDoc uri, boolean recurse) {
90         parent.populateContributionManager(serviceLocator,
91                 restrictionExpression, mgr, uri, recurse);
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.eclipse.ui.internal.menus.IMenuService#getCurrentState()
98      */

99     public IEvaluationContext getCurrentState() {
100         return parent.getCurrentState();
101     }
102
103     /*
104      * (non-Javadoc)
105      *
106      * @see org.eclipse.ui.internal.menus.IMenuService#addCacheForURI(org.eclipse.ui.internal.menus.MenuLocationURI,
107      * org.eclipse.ui.internal.menus.MenuCacheEntry)
108      */

109     public void addContributionFactory(AbstractContributionFactory cache) {
110         parent.addContributionFactory(cache);
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.eclipse.ui.internal.menus.IMenuService#releaseMenu(org.eclipse.jface.action.ContributionManager)
117      */

118     public void releaseContributions(ContributionManager mgr) {
119         parent.releaseContributions(mgr);
120     }
121
122     /*
123      * (non-Javadoc)
124      *
125      * @see org.eclipse.ui.menus.IMenuService#removeContributionFactory(org.eclipse.ui.menus.AbstractContributionFactory)
126      */

127     public void removeContributionFactory(AbstractContributionFactory factory) {
128         parent.removeContributionFactory(factory);
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see org.eclipse.ui.services.IDisposable#dispose()
135      */

136     public void dispose() {
137     }
138
139     /*
140      * (non-Javadoc)
141      *
142      * @see org.eclipse.ui.services.IServiceWithSources#addSourceProvider(org.eclipse.ui.ISourceProvider)
143      */

144     public void addSourceProvider(ISourceProvider provider) {
145         throw new RuntimeException JavaDoc("addSourceProvider"); //$NON-NLS-1$
146
}
147
148     /*
149      * (non-Javadoc)
150      *
151      * @see org.eclipse.ui.services.IServiceWithSources#removeSourceProvider(org.eclipse.ui.ISourceProvider)
152      */

153     public void removeSourceProvider(ISourceProvider provider) {
154         throw new RuntimeException JavaDoc("removeSourceProvider"); //$NON-NLS-1$
155
}
156
157     public List JavaDoc getAdditionsForURI(MenuLocationURI uri) {
158         return parent.getAdditionsForURI(uri);
159     }
160
161     public void registerVisibleWhen(final IContributionItem item,
162             final Expression visibleWhen, final Expression restriction,
163             String JavaDoc identifierID) {
164         parent
165                 .registerVisibleWhen(item, visibleWhen, restriction,
166                         identifierID);
167     }
168
169     public void unregisterVisibleWhen(IContributionItem item) {
170         parent.unregisterVisibleWhen(item);
171     }
172 }
173
Popular Tags