Search in sources :

Example 1 with IContributionFactory

use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.

the class ContributionsAnalyzer method isImperativeExpressionVisible.

private static boolean isImperativeExpressionVisible(MImperativeExpression exp, final ExpressionContext eContext) {
    Object imperativeExpressionObject = exp.getObject();
    if (imperativeExpressionObject == null) {
        IContributionFactory contributionFactory = eContext.eclipseContext.get(IContributionFactory.class);
        Object newImperativeExpression = contributionFactory.create(exp.getContributionURI(), eContext.eclipseContext);
        exp.setObject(newImperativeExpression);
        imperativeExpressionObject = newImperativeExpression;
    }
    if (imperativeExpressionObject == null) {
        return false;
    }
    Object result = null;
    // $NON-NLS-1$
    IEclipseContext staticContext = EclipseContextFactory.create("Evaluation-Static");
    staticContext.set(MImperativeExpression.class, exp);
    try {
        if (exp.isTracking()) {
            result = invoke(imperativeExpressionObject, Evaluate.class, eContext.eclipseContext, staticContext, missingEvaluate);
        } else {
            result = ContextInjectionFactory.invoke(imperativeExpressionObject, Evaluate.class, eContext.eclipseContext, staticContext, missingEvaluate);
        }
    } finally {
        staticContext.dispose();
    }
    if (result == missingEvaluate) {
        // $NON-NLS-1$
        String className = "null";
        if (imperativeExpressionObject != null) {
            className = imperativeExpressionObject.getClass().getName();
        }
        throw new IllegalStateException(// $NON-NLS-1$ //$NON-NLS-2$
        "There is no method annotated with @Evaluate in the " + className + " imperative expression class ");
    }
    return (boolean) result;
}
Also used : Evaluate(org.eclipse.e4.core.di.annotations.Evaluate) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) EObject(org.eclipse.emf.ecore.EObject) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 2 with IContributionFactory

use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.

the class E4Workbench method instantiateRenderer.

/**
 */
public void instantiateRenderer() {
    renderer = appContext.get(IPresentationEngine.class);
    if (renderer == null) {
        String presentationURI = (String) appContext.get(IWorkbench.PRESENTATION_URI_ARG);
        if (presentationURI != null) {
            IContributionFactory factory = appContext.get(IContributionFactory.class);
            renderer = (IPresentationEngine) factory.create(presentationURI, appContext);
            appContext.set(IPresentationEngine.class, renderer);
        }
        if (renderer == null) {
            Logger logger = appContext.get(Logger.class);
            // $NON-NLS-1$
            logger.error("Failed to create the presentation engine for URI: " + presentationURI);
        }
    }
}
Also used : Logger(org.eclipse.e4.core.services.log.Logger) IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 3 with IContributionFactory

use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.

the class PartRenderingEngine method getRenderer.

private AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
    // Is there a custom renderer defined ?
    String customURI = uiElement.getPersistedState().get(IPresentationEngine.CUSTOM_RENDERER_KEY);
    if (customURI != null) {
        AbstractPartRenderer abstractPartRenderer = customRendererMap.get(customURI);
        if (abstractPartRenderer != null) {
            return abstractPartRenderer;
        }
        IEclipseContext owningContext = modelService.getContainingContext(uiElement);
        IContributionFactory contributionFactory = owningContext.get(IContributionFactory.class);
        Object customRenderer = contributionFactory.create(customURI, owningContext);
        if (customRenderer instanceof AbstractPartRenderer) {
            customRendererMap.put(customURI, (AbstractPartRenderer) customRenderer);
            return (AbstractPartRenderer) customRenderer;
        }
    }
    // If not then use the default renderer
    return curFactory.getRenderer(uiElement, parent);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 4 with IContributionFactory

use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.

the class PartRenderingEngine method createThemeEngine.

private static IThemeEngine createThemeEngine(Display display, IEclipseContext appContext) {
    // Store the app context
    IContributionFactory contribution = appContext.get(IContributionFactory.class);
    IEclipseContext cssContext = EclipseContextFactory.create();
    cssContext.set(IContributionFactory.class, contribution);
    // $NON-NLS-1$
    display.setData("org.eclipse.e4.ui.css.context", cssContext);
    IThemeManager mgr = appContext.get(IThemeManager.class);
    IThemeEngine themeEngine = mgr.getEngineForDisplay(display);
    appContext.set(IThemeEngine.class, themeEngine);
    return themeEngine;
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine) IThemeManager(org.eclipse.e4.ui.css.swt.theme.IThemeManager) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 5 with IContributionFactory

use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.

the class E4Application method createE4Workbench.

public E4Workbench createE4Workbench(IApplicationContext applicationContext, final Display display) {
    args = (String[]) applicationContext.getArguments().get(IApplicationContext.APPLICATION_ARGS);
    IEclipseContext appContext = createDefaultContext();
    appContext.set(Display.class, display);
    appContext.set(Realm.class, DisplayRealm.getRealm(display));
    appContext.set(UISynchronize.class, new DisplayUISynchronize(display));
    appContext.set(IApplicationContext.class, applicationContext);
    // This context will be used by the injector for its
    // extended data suppliers
    ContextInjectionFactory.setDefault(appContext);
    // Get the factory to create DI instances with
    IContributionFactory factory = appContext.get(IContributionFactory.class);
    // Install the life-cycle manager for this session if there's one
    // defined
    Optional<String> lifeCycleURI = getArgValue(IWorkbench.LIFE_CYCLE_URI_ARG, applicationContext, false);
    lifeCycleURI.ifPresent(lifeCycleURIValue -> {
        lcManager = factory.create(lifeCycleURIValue, appContext);
        if (lcManager != null) {
            // Let the manager manipulate the appContext if desired
            ContextInjectionFactory.invoke(lcManager, PostContextCreate.class, appContext, null);
        }
    });
    Optional<String> forcedPerspectiveId = getArgValue(PERSPECTIVE_ARG_NAME, applicationContext, false);
    forcedPerspectiveId.ifPresent(forcedPerspectiveIdValue -> appContext.set(E4Workbench.FORCED_PERSPECTIVE_ID, forcedPerspectiveIdValue));
    String showLocation = getLocationFromCommandLine();
    if (showLocation != null) {
        appContext.set(E4Workbench.FORCED_SHOW_LOCATION, showLocation);
    }
    // Create the app model and its context
    MApplication appModel = loadApplicationModel(applicationContext, appContext);
    appModel.setContext(appContext);
    boolean isRtl = ((Window.getDefaultOrientation() & SWT.RIGHT_TO_LEFT) != 0);
    appModel.getTransientData().put(E4Workbench.RTL_MODE, isRtl);
    // context (see Workbench#getInstance())
    if (!E4Workbench.getServiceContext().containsKey(MApplication.class)) {
        // first one wins.
        E4Workbench.getServiceContext().set(MApplication.class, appModel);
    }
    // Set the app's context after adding itself
    appContext.set(MApplication.class, appModel);
    // adds basic services to the contexts
    initializeServices(appModel);
    // let the life cycle manager add to the model
    if (lcManager != null) {
        ContextInjectionFactory.invoke(lcManager, ProcessAdditions.class, appContext, null);
        ContextInjectionFactory.invoke(lcManager, ProcessRemovals.class, appContext, null);
    }
    // Create the addons
    IEclipseContext addonStaticContext = EclipseContextFactory.create();
    for (MAddon addon : appModel.getAddons()) {
        addonStaticContext.set(MAddon.class, addon);
        Object obj = factory.create(addon.getContributionURI(), appContext, addonStaticContext);
        addon.setObject(obj);
    }
    // Parse out parameters from both the command line and/or the product
    // definition (if any) and put them in the context
    Optional<String> xmiURI = getArgValue(IWorkbench.XMI_URI_ARG, applicationContext, false);
    xmiURI.ifPresent(xmiURIValue -> {
        appContext.set(IWorkbench.XMI_URI_ARG, xmiURIValue);
    });
    setCSSContextVariables(applicationContext, appContext);
    Optional<String> rendererFactoryURI = getArgValue(E4Workbench.RENDERER_FACTORY_URI, applicationContext, false);
    rendererFactoryURI.ifPresent(rendererFactoryURIValue -> {
        appContext.set(E4Workbench.RENDERER_FACTORY_URI, rendererFactoryURIValue);
    });
    // This is a default arg, if missing we use the default rendering engine
    Optional<String> presentationURI = getArgValue(IWorkbench.PRESENTATION_URI_ARG, applicationContext, false);
    appContext.set(IWorkbench.PRESENTATION_URI_ARG, presentationURI.orElse(PartRenderingEngine.engineURI));
    // 'running' the UI (if any)...
    return workbench = new E4Workbench(appModel, appContext);
}
Also used : E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) DisplayUISynchronize(org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) EObject(org.eclipse.emf.ecore.EObject) MAddon(org.eclipse.e4.ui.model.application.MAddon) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Aggregations

IContributionFactory (org.eclipse.e4.core.services.contributions.IContributionFactory)16 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)9 IPresentationEngine (org.eclipse.e4.ui.workbench.IPresentationEngine)5 EObject (org.eclipse.emf.ecore.EObject)5 EHandlerService (org.eclipse.e4.core.commands.EHandlerService)3 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)2 MApplication (org.eclipse.e4.ui.model.application.MApplication)2 MDirectMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem)2 MHandledMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem)2 IRendererFactory (org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory)2 Composite (org.eclipse.swt.widgets.Composite)2 Widget (org.eclipse.swt.widgets.Widget)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 PostConstruct (javax.annotation.PostConstruct)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IStatus (org.eclipse.core.runtime.IStatus)1 InvalidRegistryObjectException (org.eclipse.core.runtime.InvalidRegistryObjectException)1 Status (org.eclipse.core.runtime.Status)1 ExpressionContext (org.eclipse.e4.core.commands.ExpressionContext)1