Search in sources :

Example 1 with MAddon

use of org.eclipse.e4.ui.model.application.MAddon 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)

Example 2 with MAddon

use of org.eclipse.e4.ui.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.

the class MinMaxProcessor method addMinMaxAddon.

@Execute
void addMinMaxAddon(MApplication app, EModelService modelService) {
    List<MAddon> addons = app.getAddons();
    // prevent multiple copies
    for (MAddon addon : addons) {
        if (addon.getContributionURI().contains("ui.workbench.addons.minmax.MinMaxAddon")) {
            // $NON-NLS-1$
            return;
        }
    }
    // add the add-on to the application model
    MAddon minMaxAddon = modelService.createModelElement(MAddon.class);
    // $NON-NLS-1$
    minMaxAddon.setElementId("MinMaxAddon");
    minMaxAddon.setContributionURI(// $NON-NLS-1$
    "bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon");
    app.getAddons().add(minMaxAddon);
}
Also used : MAddon(org.eclipse.e4.ui.model.application.MAddon) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 3 with MAddon

use of org.eclipse.e4.ui.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.

the class SplitterProcessor method addSplitterAddon.

@Execute
void addSplitterAddon(MApplication app, EModelService modelService) {
    List<MAddon> addons = app.getAddons();
    // prevent multiple copies
    for (MAddon addon : addons) {
        if (addon.getContributionURI().contains("ui.workbench.addons.splitteraddon.SplitterAddon")) {
            // $NON-NLS-1$
            return;
        }
    }
    // adds the add-on to the application model
    MAddon splitterAddon = modelService.createModelElement(MAddon.class);
    // $NON-NLS-1$
    splitterAddon.setElementId("SplitterAddon");
    splitterAddon.setContributionURI(// $NON-NLS-1$
    "bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.splitteraddon.SplitterAddon");
    app.getAddons().add(splitterAddon);
}
Also used : MAddon(org.eclipse.e4.ui.model.application.MAddon) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 4 with MAddon

use of org.eclipse.e4.ui.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.

the class CocoaUIProcessor method installAddon.

/**
 * Install the addon.
 */
public void installAddon() {
    String addonId = CocoaUIHandler.class.getName();
    for (MAddon addon : app.getAddons()) {
        if (addonId.equals(addon.getElementId())) {
            return;
        }
    }
    MAddon addon = MApplicationFactory.INSTANCE.createAddon();
    addon.setContributionURI(getClassURI(CocoaUIHandler.class));
    addon.setElementId(addonId);
    app.getAddons().add(addon);
}
Also used : MAddon(org.eclipse.e4.ui.model.application.MAddon)

Example 5 with MAddon

use of org.eclipse.e4.ui.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.

the class MaximizableChildrenTag method prepareApplicationModel.

private void prepareApplicationModel() {
    MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
    window = BasicFactoryImpl.eINSTANCE.createTrimmedWindow();
    window.setElementId("MainWindow");
    MPerspectiveStack perspectiveStackMain = AdvancedFactoryImpl.eINSTANCE.createPerspectiveStack();
    perspectiveStackMain.setElementId("perspectiveStackMain");
    MPerspective perspectiveMain = AdvancedFactoryImpl.eINSTANCE.createPerspective();
    perspectiveMain.setElementId("perspectiveMain");
    MPartSashContainer containerMain = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
    partStackMain = BasicFactoryImpl.eINSTANCE.createPartStack();
    partStackMain.setElementId("mainPartStack");
    MPart partMain = BasicFactoryImpl.eINSTANCE.createPart();
    partStackMain.getChildren().add(partMain);
    containerMain.getChildren().add(partStackMain);
    placeholderMain = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
    // placeholderMain.setElementId("placeholderMain");
    placeholderMain.setElementId("org.eclipse.ui.editorss");
    containerMain.getChildren().add(placeholderMain);
    perspectiveMain.getChildren().add(containerMain);
    perspectiveMain.setSelectedElement(containerMain);
    perspectiveStackMain.getChildren().add(perspectiveMain);
    perspectiveStackMain.setSelectedElement(perspectiveMain);
    window.getChildren().add(perspectiveStackMain);
    window.setSelectedElement(perspectiveStackMain);
    application.getChildren().add(window);
    application.setSelectedElement(window);
    MArea mArea = AdvancedFactoryImpl.eINSTANCE.createArea();
    mArea.getTags().add(MAXIMIZEABLE_CHILDREN);
    partStack1 = BasicFactoryImpl.eINSTANCE.createPartStack();
    MPart part1 = BasicFactoryImpl.eINSTANCE.createPart();
    partStack1.getChildren().add(part1);
    mArea.getChildren().add(partStack1);
    partStack2 = BasicFactoryImpl.eINSTANCE.createPartStack();
    MPart part2 = BasicFactoryImpl.eINSTANCE.createPart();
    partStack2.getChildren().add(part2);
    mArea.getChildren().add(partStack2);
    window.getSharedElements().add(mArea);
    placeholderMain.setRef(mArea);
    mArea.setCurSharedRef(placeholderMain);
    // instantiate addon
    MAddon minMaxAddon = ApplicationFactoryImpl.eINSTANCE.createAddon();
    // $NON-NLS-1$
    minMaxAddon.setElementId("MinMaxAddon");
    minMaxAddon.setContributionURI(// $NON-NLS-1$
    "bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon");
    appContext = E4Application.createDefaultContext();
    Display display = Display.getDefault();
    appContext.set(Display.class, display);
    appContext.set(MApplication.class.getName(), application);
    appContext.set(MWindow.class, window);
    appContext.set(UISynchronize.class, new DisplayUISynchronize(display));
    appContext.set(EModelService.class, new ModelServiceImpl(appContext));
    ContextInjectionFactory.setDefault(appContext);
    renderer = ContextInjectionFactory.make(PartRenderingEngine.class, appContext);
    appContext.set(IPresentationEngine.class, renderer);
    appContext.set(EPartService.class, ContextInjectionFactory.make(PartServiceImpl.class, appContext));
    application.setContext(appContext);
    final UIEventPublisher ep = new UIEventPublisher(appContext);
    ((Notifier) application).eAdapters().add(ep);
    appContext.set(UIEventPublisher.class, ep);
    appContext.set(MAddon.class, minMaxAddon);
    ContextInjectionFactory.setDefault(appContext);
    ContextInjectionFactory.make(MinMaxAddon.class, appContext);
    appContext.set(IResourceUtilities.class, new ISWTResourceUtilities() {

        @Override
        public ImageDescriptor imageDescriptorFromURI(URI iconPath) {
            try {
                return ImageDescriptor.createFromURL(new URL(iconPath.toString()));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public Image adornImage(Image toAdorn, Image adornment) {
            return null;
        }
    });
    appContext.set(CSSRenderingUtils.class, new CSSRenderingUtils());
    E4Application.initializeServices(application);
    shell = (Shell) renderer.createGui(window);
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MalformedURLException(java.net.MalformedURLException) PartServiceImpl(org.eclipse.e4.ui.internal.workbench.PartServiceImpl) CSSRenderingUtils(org.eclipse.e4.ui.internal.workbench.swt.CSSRenderingUtils) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) DisplayUISynchronize(org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize) PartRenderingEngine(org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine) MPerspectiveStack(org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack) Image(org.eclipse.swt.graphics.Image) URI(org.eclipse.emf.common.util.URI) URL(java.net.URL) ModelServiceImpl(org.eclipse.e4.ui.internal.workbench.ModelServiceImpl) UIEventPublisher(org.eclipse.e4.ui.internal.workbench.UIEventPublisher) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) ISWTResourceUtilities(org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MAddon(org.eclipse.e4.ui.model.application.MAddon) MPartSashContainer(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer) MApplication(org.eclipse.e4.ui.model.application.MApplication) Display(org.eclipse.swt.widgets.Display)

Aggregations

MAddon (org.eclipse.e4.ui.model.application.MAddon)10 MApplication (org.eclipse.e4.ui.model.application.MApplication)5 Execute (org.eclipse.e4.core.di.annotations.Execute)4 DisplayUISynchronize (org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 ModelServiceImpl (org.eclipse.e4.ui.internal.workbench.ModelServiceImpl)3 PartServiceImpl (org.eclipse.e4.ui.internal.workbench.PartServiceImpl)3 UIEventPublisher (org.eclipse.e4.ui.internal.workbench.UIEventPublisher)3 CSSRenderingUtils (org.eclipse.e4.ui.internal.workbench.swt.CSSRenderingUtils)3 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)3 MPerspectiveStack (org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack)3 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)3 MPartSashContainer (org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer)3 ISWTResourceUtilities (org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities)3 URI (org.eclipse.emf.common.util.URI)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)3 Image (org.eclipse.swt.graphics.Image)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 PartRenderingEngine (org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine)2