001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.menus;
011:
012: import java.util.List;
013:
014: import org.eclipse.core.expressions.Expression;
015: import org.eclipse.core.expressions.IEvaluationContext;
016: import org.eclipse.jface.action.ContributionManager;
017: import org.eclipse.jface.action.IContributionItem;
018: import org.eclipse.ui.ISourceProvider;
019: import org.eclipse.ui.IWorkbenchWindow;
020: import org.eclipse.ui.internal.expressions.WorkbenchWindowExpression;
021: import org.eclipse.ui.menus.AbstractContributionFactory;
022: import org.eclipse.ui.menus.IMenuService;
023: import org.eclipse.ui.services.IServiceLocator;
024:
025: /**
026: * <p>
027: * Provides services related to contributing menu elements to a workbench
028: * window. Visibility and showing are tracked at the workbench window level.
029: * </p>
030: * <p>
031: * This class is only intended for internal use within the
032: * <code>org.eclipse.ui.workbench</code> plug-in.
033: * </p>
034: *
035: * @since 3.2
036: */
037: public final class WindowMenuService extends InternalMenuService {
038:
039: /**
040: * The parent menu service for this window. This parent must track menu
041: * definitions and the regsitry. Must not be <code>null</code>
042: */
043: private final WorkbenchMenuService parent;
044: private IServiceLocator serviceLocator;
045: private Expression restrictionExpression;
046:
047: /**
048: * Constructs a new instance of <code>MenuService</code> using a menu
049: * manager.
050: *
051: * @param parent
052: * The parent menu service for this window. This parent must
053: * track menu definitions and the regsitry. Must not be
054: * <code>null</code>
055: */
056: public WindowMenuService(final IServiceLocator serviceLocator) {
057: IMenuService menuService = (IMenuService) serviceLocator
058: .getService(IMenuService.class);
059: if (menuService == null
060: || !(menuService instanceof WorkbenchMenuService)) {
061: throw new NullPointerException(
062: "The parent service must not be null"); //$NON-NLS-1$
063: }
064: IWorkbenchWindow window = (IWorkbenchWindow) serviceLocator
065: .getService(IWorkbenchWindow.class);
066: if (window == null)
067: throw new NullPointerException("Window cannot be null"); //$NON-NLS-1$
068:
069: restrictionExpression = new WorkbenchWindowExpression(window);
070:
071: this .parent = (WorkbenchMenuService) menuService;
072: this .serviceLocator = serviceLocator;
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see org.eclipse.ui.internal.menus.IMenuService#populateMenu(org.eclipse.jface.action.MenuManager,
079: * org.eclipse.ui.internal.menus.MenuLocationURI)
080: */
081: public void populateContributionManager(ContributionManager mgr,
082: String uri) {
083: parent.populateContributionManager(serviceLocator,
084: restrictionExpression, mgr, uri, true);
085: }
086:
087: public void populateContributionManager(ContributionManager mgr,
088: String uri, boolean recurse) {
089: parent.populateContributionManager(serviceLocator,
090: restrictionExpression, mgr, uri, recurse);
091: }
092:
093: /*
094: * (non-Javadoc)
095: *
096: * @see org.eclipse.ui.internal.menus.IMenuService#getCurrentState()
097: */
098: public IEvaluationContext getCurrentState() {
099: return parent.getCurrentState();
100: }
101:
102: /*
103: * (non-Javadoc)
104: *
105: * @see org.eclipse.ui.internal.menus.IMenuService#addCacheForURI(org.eclipse.ui.internal.menus.MenuLocationURI,
106: * org.eclipse.ui.internal.menus.MenuCacheEntry)
107: */
108: public void addContributionFactory(AbstractContributionFactory cache) {
109: parent.addContributionFactory(cache);
110: }
111:
112: /*
113: * (non-Javadoc)
114: *
115: * @see org.eclipse.ui.internal.menus.IMenuService#releaseMenu(org.eclipse.jface.action.ContributionManager)
116: */
117: public void releaseContributions(ContributionManager mgr) {
118: parent.releaseContributions(mgr);
119: }
120:
121: /*
122: * (non-Javadoc)
123: *
124: * @see org.eclipse.ui.menus.IMenuService#removeContributionFactory(org.eclipse.ui.menus.AbstractContributionFactory)
125: */
126: public void removeContributionFactory(
127: 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("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("removeSourceProvider"); //$NON-NLS-1$
155: }
156:
157: public List 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 identifierID) {
164: parent.registerVisibleWhen(item, visibleWhen, restriction,
165: identifierID);
166: }
167:
168: public void unregisterVisibleWhen(IContributionItem item) {
169: parent.unregisterVisibleWhen(item);
170: }
171: }
|