Search in sources :

Example 1 with AbstractPartRenderer

use of org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer in project eclipse.platform.ui by eclipse-platform.

the class MenuService method registerMenu.

public static Menu registerMenu(final Control parentControl, final MPopupMenu mmenu, IEclipseContext context) {
    if (mmenu.getWidget() != null) {
        return (Menu) mmenu.getWidget();
    }
    // we need to delegate to the renderer so that it "processes" the
    // MenuManager correctly
    IRendererFactory rendererFactory = context.get(IRendererFactory.class);
    AbstractPartRenderer renderer = rendererFactory.getRenderer(mmenu, parentControl);
    mmenu.setRenderer(renderer);
    IEclipseContext popupContext = context.createChild("popup:" + mmenu.getElementId());
    mmenu.setContext(popupContext);
    if (mmenu.getParent() == null) {
        mmenu.getTransientData().put(IPresentationEngine.RENDERING_PARENT_KEY, parentControl);
    }
    Object widget = renderer.createWidget(mmenu, parentControl);
    if (!(widget instanceof Menu)) {
        mmenu.getTransientData().remove(IPresentationEngine.RENDERING_PARENT_KEY);
        return null;
    }
    renderer.bindWidget(mmenu, widget);
    renderer.hookControllerLogic(mmenu);
    // Process its internal structure through the renderer that created
    // it
    Object castObject = mmenu;
    @SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) castObject;
    renderer.processContents(container);
    // Allow a final chance to set up
    renderer.postProcess(mmenu);
    // Now that we have a widget let the parent (if any) know
    MElementContainer<MUIElement> parentElement = mmenu.getParent();
    if (parentElement != null) {
        AbstractPartRenderer parentRenderer = rendererFactory.getRenderer(parentElement, null);
        if (parentRenderer != null) {
            parentRenderer.childRendered(parentElement, mmenu);
        }
    }
    return (Menu) widget;
}
Also used : IRendererFactory(org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MPopupMenu(org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) Menu(org.eclipse.swt.widgets.Menu) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer)

Example 2 with AbstractPartRenderer

use of org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer 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 3 with AbstractPartRenderer

use of org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer in project eclipse.platform.ui by eclipse-platform.

the class PartRenderingEngine method safeCreateGui.

private Object safeCreateGui(MUIElement element) {
    // Obtain the necessary parent widget
    Object parent = null;
    MUIElement parentME = element.getParent();
    if (parentME == null)
        parentME = (MUIElement) ((EObject) element).eContainer();
    if (parentME != null) {
        AbstractPartRenderer renderer = getRendererFor(parentME);
        if (renderer != null) {
            if (!element.isVisible()) {
                parent = getLimboShell();
            } else {
                parent = renderer.getUIContainer(element);
            }
        }
    }
    // Obtain the necessary parent context
    IEclipseContext parentContext = null;
    if (element.getCurSharedRef() != null) {
        MPlaceholder ph = element.getCurSharedRef();
        parentContext = getContext(ph.getParent());
    } else if (parentContext == null && element.getParent() != null) {
        parentContext = getContext(element.getParent());
    } else if (parentContext == null && element.getParent() == null) {
        parentContext = getContext((MUIElement) ((EObject) element).eContainer());
    }
    return safeCreateGui(element, parent, parentContext);
}
Also used : MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement)

Example 4 with AbstractPartRenderer

use of org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer in project eclipse.platform.ui by eclipse-platform.

the class PartRenderingEngine method subscribeChildrenHandler.

@Inject
@Optional
private void subscribeChildrenHandler(@EventTopic(UIEvents.ElementContainer.TOPIC_CHILDREN) Event event) {
    Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
    if (!(changedObj instanceof MElementContainer<?>)) {
        return;
    }
    @SuppressWarnings("unchecked") MElementContainer<MUIElement> changedElement = (MElementContainer<MUIElement>) changedObj;
    boolean isApplication = changedObj instanceof MApplication;
    boolean menuChild = changedObj instanceof MMenu;
    // If the parent isn't in the UI then who cares?
    AbstractPartRenderer renderer = getRendererFor(changedElement);
    if ((!isApplication && renderer == null) || menuChild) {
        return;
    }
    if (UIEvents.isADD(event)) {
        if (Policy.DEBUG_RENDERER) {
            // $NON-NLS-1$
            WorkbenchSWTActivator.trace(Policy.DEBUG_RENDERER_FLAG, "Child Added", null);
        }
        for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.NEW_VALUE)) {
            MUIElement added = (MUIElement) o;
            // OK, we have a new -visible- part we either have to create
            // it or host it under the correct parent. Note that we
            // explicitly do *not* render non-selected elements in
            // stacks (to support lazy loading).
            boolean isStack = changedObj instanceof MGenericStack<?>;
            boolean hasWidget = added.getWidget() != null;
            boolean isSelected = added == changedElement.getSelectedElement();
            boolean renderIt = !isStack || hasWidget || isSelected;
            if (renderIt) {
                // NOTE: createGui will call 'childAdded' if successful
                Object w = createGui(added);
                if (w instanceof Control && !(w instanceof Shell)) {
                    final Control ctrl = (Control) w;
                    fixZOrder(added);
                    if (!ctrl.isDisposed()) {
                        ctrl.requestLayout();
                    }
                }
            } else if (renderer != null && added.isToBeRendered()) {
                renderer.childRendered(changedElement, added);
            }
            // If the element being added is a placeholder, check to see if it's 'globally
            // visible' and, if so, remove all other 'local' placeholders referencing the
            // same element.
            int newLocation = modelService.getElementLocation(added);
            if (added instanceof MPlaceholder && (newLocation == EModelService.IN_SHARED_AREA || newLocation == EModelService.OUTSIDE_PERSPECTIVE)) {
                MWindow topWin = modelService.getTopLevelWindowFor(added);
                modelService.hideLocalPlaceholders(topWin, null);
            }
        }
    } else if (UIEvents.isREMOVE(event)) {
        if (Policy.DEBUG_RENDERER) {
            // $NON-NLS-1$
            WorkbenchSWTActivator.trace(Policy.DEBUG_RENDERER_FLAG, "Child Removed", null);
        }
        for (Object o : UIEvents.asIterable(event, UIEvents.EventTags.OLD_VALUE)) {
            MUIElement removed = (MUIElement) o;
            // renderer is concerned
            if (!removed.isToBeRendered()) {
                continue;
            }
            if (removed.getWidget() instanceof Control) {
                Control ctrl = (Control) removed.getWidget();
                ctrl.setLayoutData(null);
                ctrl.requestLayout();
            }
            // selected element
            if (changedElement.getSelectedElement() == removed) {
                changedElement.setSelectedElement(null);
            }
            if (renderer != null) {
                renderer.hideChild(changedElement, removed);
            }
        }
    }
}
Also used : MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) Control(org.eclipse.swt.widgets.Control) Shell(org.eclipse.swt.widgets.Shell) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MGenericStack(org.eclipse.e4.ui.model.application.ui.MGenericStack) MApplication(org.eclipse.e4.ui.model.application.MApplication) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 5 with AbstractPartRenderer

use of org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer in project eclipse.platform.ui by eclipse-platform.

the class PartRenderingEngine method safeCreateGui.

public Object safeCreateGui(MUIElement element, Object parentWidget, IEclipseContext parentContext) {
    if (!element.isToBeRendered())
        return null;
    // no creates while processing a remove
    if (removeRoot != null) {
        return null;
    }
    Object currentWidget = element.getWidget();
    if (currentWidget != null) {
        if (currentWidget instanceof Control) {
            Control control = (Control) currentWidget;
            // make sure the control is visible
            MUIElement elementParent = element.getParent();
            if (!(element instanceof MPlaceholder) || !(elementParent instanceof MPartStack))
                control.setVisible(true);
            if (parentWidget instanceof Composite) {
                Composite currentParent = control.getParent();
                if (currentParent != parentWidget) {
                    // check if the original parent was a tab folder
                    if (currentParent instanceof CTabFolder) {
                        CTabFolder folder = (CTabFolder) currentParent;
                        // control, unset it
                        if (folder.getTopRight() == control) {
                            folder.setTopRight(null);
                        }
                    }
                    // the parents are different so we should reparent it
                    control.setParent((Composite) parentWidget);
                }
            }
        }
        // Reparent the context (or the kid's context)
        if (element instanceof MContext) {
            IEclipseContext ctxt = ((MContext) element).getContext();
            if (ctxt != null)
                ctxt.setParent(parentContext);
        } else {
            List<MContext> childContexts = modelService.findElements(element, null, MContext.class, null);
            for (MContext c : childContexts) {
                // Ensure that we only reset the context of our direct
                // children
                MUIElement kid = (MUIElement) c;
                MUIElement parent = kid.getParent();
                if (parent == null && kid.getCurSharedRef() != null)
                    parent = kid.getCurSharedRef().getParent();
                if (!(element instanceof MPlaceholder) && parent != element)
                    continue;
                if (c.getContext() != null && c.getContext().getParent() != parentContext) {
                    c.getContext().setParent(parentContext);
                }
            }
        }
        // Now that we have a widget let the parent (if any) know
        MElementContainer<MUIElement> parentElement = element.getParent();
        if (parentElement != null) {
            AbstractPartRenderer parentRenderer = getRendererFor(parentElement);
            if (parentRenderer != null) {
                parentRenderer.childRendered(parentElement, element);
            }
        }
        return element.getWidget();
    }
    if (element instanceof MContext) {
        MContext ctxt = (MContext) element;
        // "Before rendering Context should be null");
        if (ctxt.getContext() == null) {
            IEclipseContext lclContext = parentContext.createChild(getContextName(element));
            populateModelInterfaces(ctxt, lclContext, element.getClass().getInterfaces());
            ctxt.setContext(lclContext);
            // been defined in the model
            for (String variable : ctxt.getVariables()) {
                lclContext.declareModifiable(variable);
            }
            Map<String, String> props = ctxt.getProperties();
            for (Entry<String, String> entry : props.entrySet()) {
                lclContext.set(entry.getKey(), entry.getValue());
            }
        }
    }
    // See Bug 417399
    if (element.getWidget() != null) {
        return safeCreateGui(element, parentWidget, parentContext);
    }
    // Create a control appropriate to the part
    Object newWidget = createWidget(element, parentWidget);
    // Remember that we've created the control
    if (newWidget != null) {
        AbstractPartRenderer renderer = getRendererFor(element);
        // Have the renderer hook up any widget specific listeners
        renderer.hookControllerLogic(element);
        // it
        if (element instanceof MElementContainer) {
            @SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) element;
            renderer.processContents(container);
        }
        // Allow a final chance to set up
        renderer.postProcess(element);
        // Now that we have a widget let the parent (if any) know
        MElementContainer<MUIElement> parentElement = element.getParent();
        if (parentElement != null) {
            AbstractPartRenderer parentRenderer = getRendererFor(parentElement);
            if (parentRenderer != null) {
                parentRenderer.childRendered(parentElement, element);
            }
        }
    } else // failed to create the widget, dispose its context if necessary
    if (element instanceof MContext) {
        MContext ctxt = (MContext) element;
        IEclipseContext lclContext = ctxt.getContext();
        if (lclContext != null) {
            lclContext.dispose();
            ctxt.setContext(null);
        }
    }
    return newWidget;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) Composite(org.eclipse.swt.widgets.Composite) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) MContext(org.eclipse.e4.ui.model.application.ui.MContext) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) Control(org.eclipse.swt.widgets.Control) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement)

Aggregations

AbstractPartRenderer (org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer)20 IRendererFactory (org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory)16 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)14 MenuManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer)12 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)10 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)10 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)9 EObject (org.eclipse.emf.ecore.EObject)8 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)7 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)6 ToolBarManagerRenderer (org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer)6 MenuManager (org.eclipse.jface.action.MenuManager)5 ToolBarManager (org.eclipse.jface.action.ToolBarManager)5 Composite (org.eclipse.swt.widgets.Composite)5 Control (org.eclipse.swt.widgets.Control)5 TestableObject (org.eclipse.ui.testing.TestableObject)5 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)4 Shell (org.eclipse.swt.widgets.Shell)4 ArrayList (java.util.ArrayList)3 Inject (javax.inject.Inject)3