Search in sources :

Example 1 with IWorkbenchLocationService

use of org.eclipse.ui.internal.services.IWorkbenchLocationService in project eclipse.platform.ui by eclipse-platform.

the class CommandServiceFactory method create.

@Override
public Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
    if (!ICommandService.class.equals(serviceInterface)) {
        return null;
    }
    IWorkbenchLocationService wls = 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();
    final IWorkbenchPartSite site = wls.getPartSite();
    if (site == null) {
        return new SlaveCommandService((ICommandService) parent, IServiceScopes.WINDOW_SCOPE, window);
    }
    if (parent instanceof SlaveCommandService) {
        IServiceLocator pageSite = wls.getPageSite();
        if (pageSite != null) {
            MContext context = pageSite.getService(MContext.class);
            if (context == null) {
                return new SlaveCommandService((ICommandService) parent, IServiceScopes.PAGESITE_SCOPE, pageSite);
            }
            return new SlaveCommandService((ICommandService) parent, IServiceScopes.PAGESITE_SCOPE, pageSite, context.getContext());
        }
        IServiceLocator mpepSite = wls.getMultiPageEditorSite();
        if (mpepSite != null) {
            MContext context = mpepSite.getService(MContext.class);
            if (context == null) {
                return new SlaveCommandService((ICommandService) parent, IServiceScopes.MPESITE_SCOPE, mpepSite);
            }
            return new SlaveCommandService((ICommandService) parent, IServiceScopes.MPESITE_SCOPE, mpepSite, context.getContext());
        }
    }
    return new SlaveCommandService((ICommandService) parent, IServiceScopes.PARTSITE_SCOPE, site);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService) IServiceLocator(org.eclipse.ui.services.IServiceLocator) MContext(org.eclipse.e4.ui.model.application.ui.MContext) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 2 with IWorkbenchLocationService

use of org.eclipse.ui.internal.services.IWorkbenchLocationService in project eclipse.platform.ui by eclipse-platform.

the class ContextServiceFactory method create.

@Override
public Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
    if (!IContextService.class.equals(serviceInterface)) {
        return null;
    }
    IWorkbenchLocationService wls = 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();
    final IWorkbenchPartSite site = wls.getPartSite();
    if (site == null) {
        Expression exp = new WorkbenchWindowExpression(window);
        return new SlaveContextService((IContextService) parent, exp);
    }
    if (parent instanceof SlaveContextService) {
        Expression exp = ((SlaveContextService) parent).fDefaultExpression;
        if (exp instanceof ActivePartExpression) {
            return new NestableContextService((IContextService) parent, exp);
        }
    }
    Expression exp = new ActivePartExpression(site.getPart());
    return new SlaveContextService((IContextService) parent, exp);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Expression(org.eclipse.core.expressions.Expression) ActivePartExpression(org.eclipse.ui.internal.expressions.ActivePartExpression) WorkbenchWindowExpression(org.eclipse.ui.internal.expressions.WorkbenchWindowExpression) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService) IContextService(org.eclipse.ui.contexts.IContextService) WorkbenchWindowExpression(org.eclipse.ui.internal.expressions.WorkbenchWindowExpression) ActivePartExpression(org.eclipse.ui.internal.expressions.ActivePartExpression)

Example 3 with IWorkbenchLocationService

use of org.eclipse.ui.internal.services.IWorkbenchLocationService in project eclipse.platform.ui by eclipse-platform.

the class WorkbenchMenuService method getWindow.

protected IWorkbenchWindow getWindow() {
    if (serviceLocator == null)
        return null;
    IWorkbenchLocationService wls = serviceLocator.getService(IWorkbenchLocationService.class);
    IWorkbenchWindow window = null;
    if (window == null) {
        window = wls.getWorkbenchWindow();
    }
    if (window == null) {
        IWorkbench wb = wls.getWorkbench();
        if (wb != null) {
            window = wb.getActiveWorkbenchWindow();
        }
    }
    if (window == null) {
        window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    }
    return window;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService)

Example 4 with IWorkbenchLocationService

use of org.eclipse.ui.internal.services.IWorkbenchLocationService in project eclipse.platform.ui by eclipse-platform.

the class WorkbenchSupportFactory method create.

@Override
public Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator) {
    IWorkbenchLocationService wls = locator.getService(IWorkbenchLocationService.class);
    final IWorkbench wb = wls.getWorkbench();
    if (wb == null) {
        return null;
    }
    final IWorkbenchWindow window = wls.getWorkbenchWindow();
    final IWorkbenchPartSite site = wls.getPartSite();
    Object parent = parentLocator.getService(serviceInterface);
    if (parent == null) {
        // return top level services
        if (IProgressService.class.equals(serviceInterface)) {
            return wb.getProgressService();
        }
        if (IWorkbenchSiteProgressService.class.equals(serviceInterface)) {
            if (site instanceof PartSite) {
                return ((PartSite) site).getSiteProgressService();
            }
        }
        if (IPartService.class.equals(serviceInterface)) {
            if (window != null) {
                return window.getPartService();
            }
        }
        if (IPageService.class.equals(serviceInterface)) {
            if (window != null) {
                return window;
            }
        }
        if (ISelectionService.class.equals(serviceInterface)) {
            if (window != null) {
                return window.getSelectionService();
            }
        }
        return null;
    }
    if (ISelectionService.class.equals(serviceInterface)) {
        return new SlaveSelectionService((ISelectionService) parent);
    }
    if (IProgressService.class.equals(serviceInterface)) {
        if (site instanceof PartSite) {
            return ((PartSite) site).getSiteProgressService();
        }
    }
    if (IPartService.class.equals(serviceInterface)) {
        return new SlavePartService((IPartService) parent);
    }
    if (IPageService.class.equals(serviceInterface)) {
        return new SlavePageService((IPageService) parent);
    }
    return null;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite)

Example 5 with IWorkbenchLocationService

use of org.eclipse.ui.internal.services.IWorkbenchLocationService in project eclipse.platform.ui by eclipse-platform.

the class ToggleCoolbarHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    IWorkbenchLocationService wls = element.getServiceLocator().getService(IWorkbenchLocationService.class);
    IWorkbenchWindow window = wls.getWorkbenchWindow();
    if (window == null || !(window instanceof WorkbenchWindow))
        return;
    element.setText(isCoolbarVisible((WorkbenchWindow) window) ? WorkbenchMessages.ToggleCoolbarVisibilityAction_hide_text : WorkbenchMessages.ToggleCoolbarVisibilityAction_show_text);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService)

Aggregations

IWorkbenchLocationService (org.eclipse.ui.internal.services.IWorkbenchLocationService)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)7 IWorkbench (org.eclipse.ui.IWorkbench)5 IServiceLocator (org.eclipse.ui.services.IServiceLocator)4 Test (org.junit.Test)4 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)3 Ignore (org.junit.Ignore)3 WorkbenchWindow (org.eclipse.ui.internal.WorkbenchWindow)2 IServiceLocatorCreator (org.eclipse.ui.internal.services.IServiceLocatorCreator)2 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)1 Expression (org.eclipse.core.expressions.Expression)1 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)1 MContext (org.eclipse.e4.ui.model.application.ui.MContext)1 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)1 IEditorSite (org.eclipse.ui.IEditorSite)1 ICommandService (org.eclipse.ui.commands.ICommandService)1 IContextService (org.eclipse.ui.contexts.IContextService)1 IHandlerService (org.eclipse.ui.handlers.IHandlerService)1 ActivePartExpression (org.eclipse.ui.internal.expressions.ActivePartExpression)1 WorkbenchWindowExpression (org.eclipse.ui.internal.expressions.WorkbenchWindowExpression)1