Search in sources :

Example 6 with IContributionFactory

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

the class HeadlessApplicationTest method createPresentationEngine.

protected IPresentationEngine createPresentationEngine(String renderingEngineURI) throws Exception {
    IContributionFactory contributionFactory = rule.getApplicationContext().get(IContributionFactory.class);
    Object newEngine = contributionFactory.create(renderingEngineURI, rule.getApplicationContext());
    return (IPresentationEngine) newEngine;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory) IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine)

Example 7 with IContributionFactory

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

the class Bug320857Test method getEngine.

private IPresentationEngine getEngine() {
    if (engine == null) {
        IContributionFactory contributionFactory = applicationContext.get(IContributionFactory.class);
        Object newEngine = contributionFactory.create(getEngineURI(), applicationContext);
        assertTrue(newEngine instanceof IPresentationEngine);
        applicationContext.set(IPresentationEngine.class.getName(), newEngine);
        engine = (IPresentationEngine) newEngine;
    }
    return engine;
}
Also used : IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory) IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine)

Example 8 with IContributionFactory

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

the class MenuManagerRendererFilter method updateElementVisibility.

/**
 * @param menuModel
 * @param renderer
 * @param menuManager
 * @param evalContext
 */
public static void updateElementVisibility(final MMenu menuModel, MenuManagerRenderer renderer, MenuManager menuManager, final IEclipseContext evalContext, final int recurseLevel, boolean updateEnablement) {
    final ExpressionContext exprContext = new ExpressionContext(evalContext);
    HashSet<ContributionRecord> records = new HashSet<>();
    for (MMenuElement element : menuModel.getChildren()) {
        ContributionRecord record = renderer.getContributionRecord(element);
        if (record != null) {
            if (records.add(record)) {
                record.updateVisibility(evalContext);
            }
        } else {
            MenuManagerRenderer.updateVisibility(menuManager, element, exprContext);
        }
        if (recurseLevel > 0 && element.isVisible() && element instanceof MMenu) {
            MMenu childMenu = (MMenu) element;
            MenuManager childManager = renderer.getManager(childMenu);
            if (childManager != null) {
                updateElementVisibility(childMenu, renderer, childManager, evalContext, recurseLevel - 1, false);
            }
        }
        if (updateEnablement && element instanceof MHandledMenuItem) {
            ParameterizedCommand cmd = ((MHandledMenuItem) element).getWbCommand();
            EHandlerService handlerService = evalContext.get(EHandlerService.class);
            if (cmd != null && handlerService != null) {
                MHandledMenuItem item = (MHandledMenuItem) element;
                final IEclipseContext staticContext = EclipseContextFactory.create(MMRF_STATIC_CONTEXT);
                ContributionsAnalyzer.populateModelInterfaces(item, staticContext, item.getClass().getInterfaces());
                try {
                    ((MHandledMenuItem) element).setEnabled(handlerService.canExecute(cmd, staticContext));
                } finally {
                    staticContext.dispose();
                }
            }
        } else if (updateEnablement && OpaqueElementUtil.isOpaqueMenuItem(element)) {
            Object obj = OpaqueElementUtil.getOpaqueItem(element);
            if (obj instanceof IContributionItem) {
                IContributionItem ici = (IContributionItem) obj;
                ici.update();
                // Update the model to reflect changes
                ((MItem) element).setEnabled(ici.isEnabled());
            }
        } else if (updateEnablement && element instanceof MDirectMenuItem) {
            MDirectMenuItem contrib = (MDirectMenuItem) element;
            if (contrib.getObject() == null) {
                IContributionFactory icf = evalContext.get(IContributionFactory.class);
                contrib.setObject(icf.create(contrib.getContributionURI(), evalContext, EclipseContextFactory.create()));
            }
            if (contrib.getObject() == null) {
                contrib.setEnabled(false);
                continue;
            }
            MDirectMenuItem item = (MDirectMenuItem) element;
            IEclipseContext staticContext = EclipseContextFactory.create(MMRF_STATIC_CONTEXT);
            ContributionsAnalyzer.populateModelInterfaces(item, staticContext, item.getClass().getInterfaces());
            try {
                Object rc = ContextInjectionFactory.invoke(contrib.getObject(), CanExecute.class, evalContext, staticContext, Boolean.TRUE);
                if (rc instanceof Boolean) {
                    contrib.setEnabled((Boolean) rc);
                }
            } finally {
                staticContext.dispose();
            }
        }
    }
}
Also used : EHandlerService(org.eclipse.e4.core.commands.EHandlerService) IContributionItem(org.eclipse.jface.action.IContributionItem) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MMenuElement(org.eclipse.e4.ui.model.application.ui.menu.MMenuElement) ExpressionContext(org.eclipse.e4.core.commands.ExpressionContext) MDirectMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem) MenuManager(org.eclipse.jface.action.MenuManager) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory) HashSet(java.util.HashSet)

Example 9 with IContributionFactory

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

the class ContributedPartRenderer method createWidget.

@Override
public Object createWidget(final MUIElement element, Object parent) {
    if (!(element instanceof MPart) || !(parent instanceof Composite)) {
        return null;
    }
    // retrieve context for this part
    final MPart part = (MPart) element;
    IEclipseContext localContext = part.getContext();
    Widget parentWidget = (Widget) parent;
    // retrieve existing Composite, e.g., for the e4 compatibility case
    Composite partComposite = localContext.getLocal(Composite.class);
    // does the part already have a composite in its contexts?
    if (partComposite == null) {
        final Composite newComposite = new Composite((Composite) parentWidget, SWT.NONE) {

            /**
             * Field to determine whether we are currently in the midst of
             * granting focus to the part.
             */
            private boolean beingFocused = false;

            @Override
            public boolean setFocus() {
                if (!beingFocused) {
                    try {
                        // we are currently asking the part to take focus
                        beingFocused = true;
                        // delegate an attempt to set the focus here to the
                        // part's implementation (if there is one)
                        Object object = part.getObject();
                        if (object != null && isEnabled()) {
                            IPresentationEngine pe = part.getContext().get(IPresentationEngine.class);
                            pe.focusGui(part);
                            return true;
                        }
                        return super.setFocus();
                    } finally {
                        // we are done, unset our flag
                        beingFocused = false;
                    }
                }
                // just return
                return true;
            }
        };
        newComposite.setLayout(new FillLayout(SWT.VERTICAL));
        partComposite = newComposite;
    }
    bindWidget(element, partComposite);
    localContext.set(Composite.class, partComposite);
    IContributionFactory contributionFactory = localContext.get(IContributionFactory.class);
    Object newPart = contributionFactory.create(part.getContributionURI(), localContext);
    part.setObject(newPart);
    return partComposite;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Composite(org.eclipse.swt.widgets.Composite) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Widget(org.eclipse.swt.widgets.Widget) FillLayout(org.eclipse.swt.layout.FillLayout) IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 10 with IContributionFactory

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

the class CocoaUIHandler method simulateMenuSelection.

private void simulateMenuSelection(MMenuItem item) {
    // FIXME: pity this code isn't available through the MMenuItem instance
    // somehow
    IEclipseContext lclContext = getContext(item);
    if (item instanceof MDirectMenuItem) {
        MDirectMenuItem dmi = (MDirectMenuItem) item;
        if (dmi.getObject() == null) {
            IContributionFactory cf = (IContributionFactory) lclContext.get(IContributionFactory.class.getName());
            dmi.setObject(cf.create(dmi.getContributionURI(), lclContext));
        }
        lclContext.set(MItem.class.getName(), item);
        ContextInjectionFactory.invoke(dmi.getObject(), Execute.class, lclContext);
        lclContext.remove(MItem.class.getName());
    } else if (item instanceof MHandledMenuItem) {
        MHandledMenuItem hmi = (MHandledMenuItem) item;
        EHandlerService service = (EHandlerService) lclContext.get(EHandlerService.class.getName());
        ParameterizedCommand cmd = hmi.getWbCommand();
        if (cmd == null) {
            cmd = generateParameterizedCommand(hmi);
        }
        lclContext.set(MItem.class.getName(), item);
        service.executeHandler(cmd);
        lclContext.remove(MItem.class.getName());
    } else {
        statusReporter.get().report(new Status(IStatus.WARNING, CocoaUIProcessor.FRAGMENT_ID, // $NON-NLS-1$ //$NON-NLS-2$
        "Unhandled menu type: " + item.getClass() + ": " + item), StatusReporter.LOG);
    }
}
Also used : MItem(org.eclipse.e4.ui.model.application.ui.menu.MItem) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) EHandlerService(org.eclipse.e4.core.commands.EHandlerService) MDirectMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MDirectMenuItem) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

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