Search in sources :

Example 1 with MContribution

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

the class DirectContributionItem method executeItem.

@Override
protected void executeItem(Event trigger) {
    final IEclipseContext lclContext = getContext(getModel());
    if (!checkContribution(lclContext)) {
        return;
    }
    MContribution contrib = (MContribution) getModel();
    IEclipseContext staticContext = getStaticContext(trigger);
    Object result = ContextInjectionFactory.invoke(contrib.getObject(), Execute.class, getExecutionContext(lclContext), staticContext, missingExecute);
    if (result == missingExecute && logger != null) {
        // $NON-NLS-1$
        logger.error("Contribution is missing @Execute: " + contrib.getContributionURI());
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MContribution(org.eclipse.e4.ui.model.application.MContribution)

Example 2 with MContribution

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

the class PartRenderingEngine method safeRemoveGui.

private void safeRemoveGui(MUIElement element) {
    if (removeRoot == null)
        removeRoot = element;
    // We call 'hideChild' *before* checking if the actual element
    // has been rendered in order to pick up cases of 'lazy loading'
    MUIElement parent = element.getParent();
    AbstractPartRenderer parentRenderer = parent != null ? getRendererFor(parent) : null;
    if (parentRenderer != null) {
        parentRenderer.hideChild(element.getParent(), element);
    }
    AbstractPartRenderer renderer = getRendererFor(element);
    // If the element hasn't been rendered then this is a NO-OP
    if (renderer != null) {
        if (element instanceof MElementContainer<?>) {
            @SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) element;
            MUIElement selectedElement = container.getSelectedElement();
            List<MUIElement> children = container.getChildren();
            // Bug 458460: Operate on a copy in case child nulls out parent
            for (MUIElement child : new ArrayList<>(children)) {
                // remove stuff in the "back" first
                if (child != selectedElement) {
                    removeGui(child);
                }
            }
            if (selectedElement != null && children.contains(selectedElement)) {
                // now remove the selected element
                removeGui(selectedElement);
            }
        }
        if (element instanceof MPerspective) {
            MPerspective perspective = (MPerspective) element;
            for (MWindow subWindow : perspective.getWindows()) {
                removeGui(subWindow);
            }
        } else if (element instanceof MWindow) {
            MWindow window = (MWindow) element;
            for (MWindow subWindow : window.getWindows()) {
                removeGui(subWindow);
            }
            if (window instanceof MTrimmedWindow) {
                MTrimmedWindow trimmedWindow = (MTrimmedWindow) window;
                for (MUIElement trimBar : trimmedWindow.getTrimBars()) {
                    removeGui(trimBar);
                }
            }
        }
        if (element instanceof MContribution) {
            MContribution contribution = (MContribution) element;
            Object client = contribution.getObject();
            IEclipseContext parentContext = renderer.getContext(element);
            if (parentContext != null && client != null) {
                try {
                    ContextInjectionFactory.invoke(client, PersistState.class, parentContext, null);
                } catch (Exception e) {
                    if (logger != null) {
                        logger.error(e);
                    }
                }
            }
        }
        renderer.disposeWidget(element);
        // unset the client object
        if (element instanceof MContribution) {
            MContribution contribution = (MContribution) element;
            Object client = contribution.getObject();
            IEclipseContext parentContext = renderer.getContext(element);
            if (parentContext != null && client != null) {
                try {
                    ContextInjectionFactory.uninject(client, parentContext);
                } catch (Exception e) {
                    if (logger != null) {
                        logger.error(e);
                    }
                }
            }
            contribution.setObject(null);
        }
        // dispose the context
        if (element instanceof MContext) {
            clearContext((MContext) element);
        }
    }
    if (element instanceof MPlaceholder) {
        MPlaceholder ph = (MPlaceholder) element;
        if (ph.getRef() != null && ph.getRef().getCurSharedRef() == ph) {
            ph.getRef().setCurSharedRef(null);
        }
    }
    if (removeRoot == element)
        removeRoot = null;
}
Also used : MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) ArrayList(java.util.ArrayList) MContext(org.eclipse.e4.ui.model.application.ui.MContext) MContribution(org.eclipse.e4.ui.model.application.MContribution) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) IOException(java.io.IOException) InjectionException(org.eclipse.e4.core.di.InjectionException) InvalidRegistryObjectException(org.eclipse.core.runtime.InvalidRegistryObjectException) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) MTrimmedWindow(org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject)

Example 3 with MContribution

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

the class HeadlessContextPresentationEngine method focusGui.

@Override
public void focusGui(MUIElement element) {
    Object implementation = element instanceof MContribution ? ((MContribution) element).getObject() : null;
    if (implementation != null) {
        IEclipseContext context = getContext(element);
        Object defaultValue = new Object();
        Object returnValue = ContextInjectionFactory.invoke(implementation, Focus.class, context, defaultValue);
        if (returnValue == defaultValue) {
            System.err.println("No @Focus method");
        }
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) EObject(org.eclipse.emf.ecore.EObject) MContribution(org.eclipse.e4.ui.model.application.MContribution)

Example 4 with MContribution

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

the class DirectContributionItem method canExecuteItem.

@Override
protected boolean canExecuteItem(Event trigger) {
    final IEclipseContext lclContext = getContext(getModel());
    if (!checkContribution(lclContext)) {
        return false;
    }
    MContribution contrib = (MContribution) getModel();
    IEclipseContext staticContext = getStaticContext(trigger);
    Boolean result = ((Boolean) ContextInjectionFactory.invoke(contrib.getObject(), CanExecute.class, getExecutionContext(lclContext), staticContext, Boolean.TRUE));
    return result.booleanValue();
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MContribution(org.eclipse.e4.ui.model.application.MContribution)

Example 5 with MContribution

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

the class PartRenderingEngine method focusGui.

@Override
public void focusGui(MUIElement element) {
    AbstractPartRenderer renderer = (AbstractPartRenderer) element.getRenderer();
    if (renderer == null || element.getWidget() == null) {
        if (Policy.DEBUG_FOCUS) {
            WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Trying to focus GUI on element without renderer or widget: " + element, // $NON-NLS-1$
            new Exception());
        }
        return;
    }
    Object implementation = element instanceof MContribution ? ((MContribution) element).getObject() : null;
    // If there is no class to call @Focus on then revert to the default
    if (implementation == null) {
        renderer.forceFocus(element);
        return;
    }
    try {
        IEclipseContext context = getContext(element);
        Object defaultValue = new Object();
        Object returnValue = ContextInjectionFactory.invoke(implementation, Focus.class, context, defaultValue);
        if (returnValue == defaultValue) {
            // No @Focus method, force the focus
            renderer.forceFocus(element);
        } else if (Policy.DEBUG_FOCUS) {
            // $NON-NLS-1$
            WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Focused GUI on element: " + element, null);
        }
    } catch (InjectionException e) {
        log(// $NON-NLS-1$ //$NON-NLS-2$
        "Failed to grant focus to element", // $NON-NLS-1$ //$NON-NLS-2$
        "Failed to grant focus to element ({0})", element.getElementId(), e);
    } catch (RuntimeException e) {
        log(// $NON-NLS-1$
        "Failed to grant focus to element via DI", "Failed to grant focus via DI to element ({0})", element.getElementId(), // $NON-NLS-1$
        e);
    }
}
Also used : InjectionException(org.eclipse.e4.core.di.InjectionException) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject) MContribution(org.eclipse.e4.ui.model.application.MContribution) IOException(java.io.IOException) InjectionException(org.eclipse.e4.core.di.InjectionException) InvalidRegistryObjectException(org.eclipse.core.runtime.InvalidRegistryObjectException)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)6 MContribution (org.eclipse.e4.ui.model.application.MContribution)6 EObject (org.eclipse.emf.ecore.EObject)4 IOException (java.io.IOException)2 InvalidRegistryObjectException (org.eclipse.core.runtime.InvalidRegistryObjectException)2 InjectionException (org.eclipse.e4.core.di.InjectionException)2 MContext (org.eclipse.e4.ui.model.application.ui.MContext)2 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)2 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)2 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)2 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)2 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)2 TestableObject (org.eclipse.ui.testing.TestableObject)2 ArrayList (java.util.ArrayList)1 MApplication (org.eclipse.e4.ui.model.application.MApplication)1 MGenericStack (org.eclipse.e4.ui.model.application.ui.MGenericStack)1 MTrimmedWindow (org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow)1