blob: 1e766c09f22880fd998cdc4b79f7bb1d20426326 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.ui.internal.menus;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.WorkbenchWindow;
import org.eclipse.ui.internal.services.IWorkbenchLocationService;
import org.eclipse.ui.menus.IMenuService;
import org.eclipse.ui.services.AbstractServiceFactory;
import org.eclipse.ui.services.IServiceLocator;
/**
* @since 3.4
*
*/
public class MenuServiceFactory extends AbstractServiceFactory {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.services.AbstractServiceFactory#create(java.lang.Class,
* org.eclipse.ui.services.IServiceLocator,
* org.eclipse.ui.services.IServiceLocator)
*/
public Object create(Class serviceInterface, IServiceLocator parentLocator,
IServiceLocator locator) {
if (!IMenuService.class.equals(serviceInterface)) {
return null;
}
IWorkbenchLocationService wls = (IWorkbenchLocationService) locator
.getService(IWorkbenchLocationService.class);
final IWorkbench wb = wls.getWorkbench();
if (wb == null) {
return null;
}
Object parent = parentLocator.getService(serviceInterface);
if (parent == null) {
// we are registering the global services in the Workbench
return null;
}
final IWorkbenchWindow window = wls.getWorkbenchWindow();
return new SlaveMenuService((InternalMenuService) parent, locator,
((WorkbenchWindow)window).getMenuRestrictions());
}
}