Search in sources :

Example 1 with MGenericStack

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

the class PartActivationHistory method findActivationCandidate.

/**
 * Finds and returns a part that is a valid candidate to be granted activation.
 */
private MPart findActivationCandidate(Collection<MPart> candidates, MPart currentlyActivePart) {
    candidates.remove(currentlyActivePart);
    MPlaceholder activePlaceholder = partService.getLocalPlaceholder(currentlyActivePart);
    for (MPart candidate : candidates) {
        // make sure it's rendered and visible
        if (isValid(candidate)) {
            MPlaceholder placeholder = partService.getLocalPlaceholder(candidate);
            MElementContainer<MUIElement> parent = placeholder == null ? candidate.getParent() : placeholder.getParent();
            // that's not the selected element if possible get the selected element
            if (parent instanceof MGenericStack) {
                MUIElement selection = parent.getSelectedElement();
                // if the selected element is the currently active part, the candidate is valid
                if (selection == activePlaceholder || selection == currentlyActivePart) {
                    return candidate;
                }
                // if the selected element is the current candidate, the candidate is valid
                if (selection == candidate || selection == placeholder) {
                    return candidate;
                }
            } else {
                // not in a stack, just return the candidate then
                return candidate;
            }
        }
    }
    return null;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MGenericStack(org.eclipse.e4.ui.model.application.ui.MGenericStack)

Example 2 with MGenericStack

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

the class LazyStackRenderer method postProcess.

@Override
public void postProcess(MUIElement element) {
    if (!(element instanceof MPerspectiveStack) && (!(element instanceof MGenericStack<?>) || isMinimizedStack(element))) {
        return;
    }
    @SuppressWarnings("unchecked") MGenericStack<MUIElement> stack = (MGenericStack<MUIElement>) element;
    MUIElement selPart = stack.getSelectedElement();
    if (selPart != null) {
        showTab(selPart);
    } else if (stack.getChildren().size() > 0) {
        // Set the selection to the first renderable element
        for (MUIElement kid : stack.getChildren()) {
            if (kid.isToBeRendered() && kid.isVisible()) {
                stack.setSelectedElement(kid);
                break;
            }
        }
    }
}
Also used : MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MPerspectiveStack(org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack) MGenericStack(org.eclipse.e4.ui.model.application.ui.MGenericStack)

Example 3 with MGenericStack

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

the class LazyStackRenderer method hideElementRecursive.

private void hideElementRecursive(MUIElement element) {
    if (element == null) {
        return;
    }
    // Recursively hide placeholder refs if reference is current
    if (element instanceof MPlaceholder) {
        MPlaceholder ph = (MPlaceholder) element;
        if (ph.getRef() != null && ph.getRef().getCurSharedRef() == ph) {
            hideElementRecursive(ph.getRef());
        }
    }
    // Hide any floating windows
    if (element instanceof MWindow) {
        element.setVisible(false);
    }
    if (element instanceof MPart) {
        MToolBar toolbar = ((MPart) element).getToolbar();
        if (toolbar != null) {
            toolbar.setVisible(false);
        }
    }
    if (element instanceof MGenericStack<?>) {
        // For stacks only the currently selected elements are being hidden
        MGenericStack<?> container = (MGenericStack<?>) element;
        MUIElement curSel = container.getSelectedElement();
        hideElementRecursive(curSel);
    } else if (element instanceof MElementContainer<?>) {
        MElementContainer<?> container = (MElementContainer<?>) element;
        for (MUIElement childElement : container.getChildren()) {
            hideElementRecursive(childElement);
        }
        // OK, now process detached windows
        if (element instanceof MWindow) {
            for (MWindow w : ((MWindow) element).getWindows()) {
                hideElementRecursive(w);
            }
        } else if (element instanceof MPerspective) {
            for (MWindow w : ((MPerspective) element).getWindows()) {
                hideElementRecursive(w);
            }
        }
    }
}
Also used : MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) MGenericStack(org.eclipse.e4.ui.model.application.ui.MGenericStack) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow)

Example 4 with MGenericStack

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

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

the class TrimStack method updateTrimStackItems.

private void updateTrimStackItems() {
    // Prevent exceptions on shutdown
    if (trimStackTB == null || trimStackTB.isDisposed() || minimizedElement.getWidget() == null) {
        return;
    }
    // Remove any current items except the 'restore' button
    while (trimStackTB.getItemCount() > 1) {
        trimStackTB.getItem(trimStackTB.getItemCount() - 1).dispose();
    }
    if (isEditorStack() && trimStackTB.getItemCount() == 1) {
        ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
        ti.setToolTipText(Messages.TrimStack_SharedAreaTooltip);
        ti.setImage(getLayoutImage());
        ti.addSelectionListener(toolItemSelectionListener);
    } else if (minimizedElement instanceof MPlaceholder) {
        MPlaceholder ph = (MPlaceholder) minimizedElement;
        if (ph.getRef() instanceof MPart) {
            MPart part = (MPart) ph.getRef();
            ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
            ti.setData(part);
            ti.setImage(getImage(part));
            ti.setToolTipText(getLabelText(part));
            ti.addSelectionListener(toolItemSelectionListener);
        }
    } else if (minimizedElement instanceof MGenericStack<?>) {
        // Handle *both* PartStacks and PerspectiveStacks here...
        MGenericStack<?> theStack = (MGenericStack<?>) minimizedElement;
        // check to see if this stack has any valid elements
        boolean hasRenderedElements = false;
        for (MUIElement stackElement : theStack.getChildren()) {
            if (stackElement.isToBeRendered()) {
                hasRenderedElements = true;
                break;
            }
        }
        if (hasRenderedElements) {
            for (MUIElement stackElement : theStack.getChildren()) {
                if (!stackElement.isToBeRendered()) {
                    continue;
                }
                MUILabel labelElement = getLabelElement(stackElement);
                ToolItem newItem = new ToolItem(trimStackTB, SWT.CHECK);
                newItem.setData(labelElement);
                newItem.setImage(getImage(labelElement));
                newItem.setToolTipText(getLabelText(labelElement));
                newItem.addSelectionListener(toolItemSelectionListener);
            }
        } else if (theStack.getTags().contains(IPresentationEngine.NO_AUTO_COLLAPSE)) {
            // OK to be empty and still minimized
            ToolItem ti = new ToolItem(trimStackTB, SWT.CHECK);
            ti.setToolTipText(Messages.TrimStack_EmptyStackTooltip);
            ti.setImage(getLayoutImage());
            ti.addSelectionListener(toolItemSelectionListener);
        } else {
            // doesn't have any children that's showing, place it back in the presentation
            restoreStack();
            return;
        }
    }
    trimStackTB.pack();
    trimStackTB.requestLayout();
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) MUILabel(org.eclipse.e4.ui.model.application.ui.MUILabel) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MGenericStack(org.eclipse.e4.ui.model.application.ui.MGenericStack) ToolItem(org.eclipse.swt.widgets.ToolItem)

Aggregations

MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)11 MGenericStack (org.eclipse.e4.ui.model.application.ui.MGenericStack)10 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)9 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)5 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)4 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)4 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)4 EObject (org.eclipse.emf.ecore.EObject)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 MContext (org.eclipse.e4.ui.model.application.ui.MContext)3 MApplication (org.eclipse.e4.ui.model.application.MApplication)2 MPerspectiveStack (org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack)2 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)2 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)2 Control (org.eclipse.swt.widgets.Control)2 Shell (org.eclipse.swt.widgets.Shell)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 Inject (javax.inject.Inject)1