Search in sources :

Example 1 with MContext

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

the class PartServiceImpl method getParentWithContext.

private MContext getParentWithContext(MUIElement part) {
    MElementContainer<MUIElement> parent = part.getParent();
    MUIElement intermediate = parent;
    if (intermediate == null) {
        intermediate = part;
    } else {
        while (parent != null) {
            if (parent instanceof MContext) {
                if (((MContext) parent).getContext() != null)
                    return (MContext) parent;
            }
            intermediate = parent;
            parent = parent.getParent();
        }
    }
    MPlaceholder placeholder = modelService.findPlaceholderFor(getWindow(), intermediate);
    parent = placeholder.getParent();
    while (parent != null) {
        if (parent instanceof MContext) {
            if (((MContext) parent).getContext() != null)
                return (MContext) parent;
        }
        parent = parent.getParent();
    }
    return null;
}
Also used : MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) MContext(org.eclipse.e4.ui.model.application.ui.MContext) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement)

Example 2 with MContext

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

the class HandlerProcessingAddon method handleHandlerEvent.

/**
 * Responds to the coming and goings of handlers in the application model by activating and
 * deactivating them accordingly.
 *
 * @param event
 *            The event thrown in the event bus
 */
@Inject
@Optional
public void handleHandlerEvent(@EventTopic(UIEvents.HandlerContainer.TOPIC_HANDLERS) Event event) {
    if ((event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MHandlerContainer) && (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MContext)) {
        MHandlerContainer handlerContainer = (MHandlerContainer) event.getProperty(UIEvents.EventTags.ELEMENT);
        if (UIEvents.EventTypes.ADD.equals(event.getProperty(UIEvents.EventTags.TYPE))) {
            if (event.getProperty(UIEvents.EventTags.NEW_VALUE) instanceof MHandler) {
                MHandler handler = (MHandler) event.getProperty(UIEvents.EventTags.NEW_VALUE);
                MContext mContext = (MContext) handlerContainer;
                IEclipseContext context = mContext.getContext();
                if (context != null) {
                    processActiveHandler(handler, context);
                }
            }
        } else if (UIEvents.EventTypes.REMOVE.equals(event.getProperty(UIEvents.EventTags.TYPE))) {
            if (event.getProperty(UIEvents.EventTags.OLD_VALUE) instanceof MHandler) {
                MHandler handler = (MHandler) event.getProperty(UIEvents.EventTags.OLD_VALUE);
                MContext mContext = (MContext) handlerContainer;
                IEclipseContext context = mContext.getContext();
                if (context != null) {
                    MCommand command = handler.getCommand();
                    if (command != null) {
                        String commandId = command.getElementId();
                        EHandlerService handlerService = context.get(EHandlerService.class);
                        handlerService.deactivateHandler(commandId, handler.getObject());
                    }
                }
            }
        }
    }
}
Also used : EHandlerService(org.eclipse.e4.core.commands.EHandlerService) MHandler(org.eclipse.e4.ui.model.application.commands.MHandler) MHandlerContainer(org.eclipse.e4.ui.model.application.commands.MHandlerContainer) MCommand(org.eclipse.e4.ui.model.application.commands.MCommand) MContext(org.eclipse.e4.ui.model.application.ui.MContext) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 3 with MContext

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

the class HandlerProcessingAddon method postConstruct.

/**
 * Do initial check of handlers and their context upon creation
 *
 * @param application
 * @param modelService
 */
@PostConstruct
public void postConstruct(MApplication application, EModelService modelService) {
    List<MHandlerContainer> findElements = modelService.findElements(application, null, MHandlerContainer.class);
    for (MHandlerContainer mHandlerContainer : findElements) {
        if (mHandlerContainer instanceof MContext) {
            MContext mContext = (MContext) mHandlerContainer;
            IEclipseContext context = mContext.getContext();
            if (context != null) {
                for (MHandler mHandler : mHandlerContainer.getHandlers()) {
                    processActiveHandler(mHandler, context);
                }
            }
        }
    }
}
Also used : MHandler(org.eclipse.e4.ui.model.application.commands.MHandler) MHandlerContainer(org.eclipse.e4.ui.model.application.commands.MHandlerContainer) MContext(org.eclipse.e4.ui.model.application.ui.MContext) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) PostConstruct(javax.annotation.PostConstruct)

Example 4 with MContext

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

the class ElementReferenceRenderer method disposeWidget.

@Override
public void disposeWidget(MUIElement element) {
    MPlaceholder ph = (MPlaceholder) element;
    MUIElement refElement = ph.getRef();
    Control refCtrl = (Control) refElement.getWidget();
    // Remove the element ref from the rendered list
    Set<MPlaceholder> refs = renderedMap.get(refElement);
    refs.remove(ph);
    IEclipseContext curContext = modelService.getContainingContext(ph);
    if (refs.isEmpty()) {
        // part. See bug 347471 for details
        if (refElement instanceof MPart) {
            MPart thePart = (MPart) refElement;
            String imageURI = thePart.getIconURI();
            thePart.setIconURI(null);
            thePart.setIconURI(imageURI);
        }
        renderingEngine.removeGui(refElement);
        renderedMap.remove(refElement);
    } else // to dispose the 'real' part
    if (refCtrl != null && !refCtrl.isDisposed()) {
        MPlaceholder currentRef = refElement.getCurSharedRef();
        if (currentRef == ph) {
            // Find another *rendered* ref to pass the part on to
            for (MPlaceholder aPH : refs) {
                Composite phComp = (Composite) aPH.getWidget();
                if (phComp == null || phComp.isDisposed())
                    continue;
                // Reparent the context(s) (if any)
                IEclipseContext newParentContext = modelService.getContainingContext(aPH);
                List<MContext> allContexts = modelService.findElements(refElement, null, MContext.class);
                for (MContext ctxtElement : allContexts) {
                    IEclipseContext theContext = ctxtElement.getContext();
                    // this may be null if it hasn't been rendered yet
                    if (theContext != null) {
                        if (theContext.getParent() == curContext) {
                            // deactivate ourselves first
                            if (curContext.getActiveChild() == theContext) {
                                theContext.deactivate();
                            }
                            theContext.setParent(newParentContext);
                        }
                    }
                }
                // reset the 'cur' ref
                refElement.setCurSharedRef(aPH);
                // Reparent the widget
                refCtrl.setParent(phComp);
                break;
            }
        } else if (currentRef != null) {
            Composite phComp = (Composite) currentRef.getWidget();
            if (phComp == null || phComp.isDisposed()) {
                super.disposeWidget(element);
                return;
            }
            // Reparent the context(s) (if any)
            IEclipseContext newParentContext = modelService.getContainingContext(currentRef);
            List<MContext> allContexts = modelService.findElements(refElement, null, MContext.class);
            for (MContext ctxtElement : allContexts) {
                IEclipseContext theContext = ctxtElement.getContext();
                // this may be null if it hasn't been rendered yet
                if (theContext != null && theContext.getParent() == curContext) {
                    // ourselves first
                    if (curContext.getActiveChild() == theContext) {
                        theContext.deactivate();
                    }
                    theContext.setParent(newParentContext);
                }
            }
        }
    }
    super.disposeWidget(element);
}
Also used : Control(org.eclipse.swt.widgets.Control) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Composite(org.eclipse.swt.widgets.Composite) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MContext(org.eclipse.e4.ui.model.application.ui.MContext) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) List(java.util.List)

Example 5 with MContext

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

the class ElementReferenceRenderer method createWidget.

@Override
public Object createWidget(final MUIElement element, Object parent) {
    MPlaceholder ph = (MPlaceholder) element;
    final MUIElement ref = ph.getRef();
    ref.setCurSharedRef(ph);
    Set<MPlaceholder> renderedRefs = renderedMap.get(ref);
    if (renderedRefs == null) {
        renderedRefs = new HashSet<>();
        renderedMap.put(ref, renderedRefs);
    }
    if (!renderedRefs.contains(ph))
        renderedRefs.add(ph);
    Composite newComp = new Composite((Composite) parent, SWT.NONE);
    newComp.setLayout(new FillLayout());
    // if the placeholder is *not* in the currently active perspective
    // then don't re-parent the current view
    int phLoc = modelService.getElementLocation(ph);
    if (phLoc == EModelService.IN_ACTIVE_PERSPECTIVE || phLoc == EModelService.IN_SHARED_AREA || phLoc == EModelService.OUTSIDE_PERSPECTIVE) {
        Control refWidget = (Control) ref.getWidget();
        if (refWidget == null) {
            ref.setToBeRendered(true);
            refWidget = (Control) renderingEngine.createGui(ref, newComp, getContextForParent(ref));
        } else if (refWidget.getParent() != newComp) {
            refWidget.setParent(newComp);
        }
        if (ref instanceof MContext) {
            IEclipseContext context = ((MContext) ref).getContext();
            IEclipseContext newParentContext = getContext(ph);
            if (context.getParent() != newParentContext) {
                context.setParent(newParentContext);
            }
        }
    }
    return newComp;
}
Also used : Control(org.eclipse.swt.widgets.Control) 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) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) FillLayout(org.eclipse.swt.layout.FillLayout)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)21 MContext (org.eclipse.e4.ui.model.application.ui.MContext)21 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)14 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)9 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)8 EObject (org.eclipse.emf.ecore.EObject)6 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)5 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)5 Composite (org.eclipse.swt.widgets.Composite)5 Control (org.eclipse.swt.widgets.Control)5 MApplication (org.eclipse.e4.ui.model.application.MApplication)4 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)4 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 PostConstruct (javax.annotation.PostConstruct)3 AbstractPartRenderer (org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer)3 MGenericStack (org.eclipse.e4.ui.model.application.ui.MGenericStack)3 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)3 IRendererFactory (org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory)3