Search in sources :

Example 1 with MArea

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

the class ModelServiceImpl method resetPerspectiveModel.

private void resetPerspectiveModel(MPerspective persp, MWindow window, boolean removeSharedPlaceholders) {
    if (persp == null) {
        return;
    }
    if (removeSharedPlaceholders) {
        // Remove any views (Placeholders) from the shared area
        EPartService ps = window.getContext().get(EPartService.class);
        List<MArea> areas = findElements(window, null, MArea.class, null);
        if (areas.size() == 1) {
            MArea area = areas.get(0);
            // Strip out the placeholders in visible stacks
            List<MPlaceholder> phList = findElements(area, null, MPlaceholder.class, null);
            for (MPlaceholder ph : phList) {
                ps.hidePart((MPart) ph.getRef());
                ph.getParent().getChildren().remove(ph);
            }
            // Prevent shared stacks ids from clashing with the ones in the perspective
            List<MPartStack> stacks = findElements(area, null, MPartStack.class, null);
            for (MPartStack stack : stacks) {
                // $NON-NLS-1$
                String generatedId = "PartStack@" + Integer.toHexString(stack.hashCode());
                stack.setElementId(generatedId);
            }
            // Also remove any min/max tags on the area (or its placeholder)
            MUIElement areaPresentation = area;
            if (area.getCurSharedRef() != null) {
                areaPresentation = area.getCurSharedRef();
            }
            areaPresentation.getTags().remove(IPresentationEngine.MAXIMIZED);
            areaPresentation.getTags().remove(IPresentationEngine.MINIMIZED);
            areaPresentation.getTags().remove(IPresentationEngine.MINIMIZED_BY_ZOOM);
        }
    }
    // Remove any minimized stacks for this perspective
    // $NON-NLS-1$ //$NON-NLS-2$
    String perspectiveSuffix = "(" + persp.getElementId() + ")";
    List<MTrimBar> bars = findElements(window, null, MTrimBar.class, null);
    List<MToolControl> toRemove = new ArrayList<>();
    for (MTrimBar bar : bars) {
        for (MUIElement barKid : bar.getChildren()) {
            if (!(barKid instanceof MToolControl)) {
                continue;
            }
            String id = barKid.getElementId();
            if (id != null && id.contains(perspectiveSuffix)) {
                toRemove.add((MToolControl) barKid);
            }
        }
    }
    for (MToolControl toolControl : toRemove) {
        // Close any open fast view
        toolControl.setToBeRendered(false);
        toolControl.getParent().getChildren().remove(toolControl);
    }
}
Also used : MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) ArrayList(java.util.ArrayList) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) MToolControl(org.eclipse.e4.ui.model.application.ui.menu.MToolControl) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement)

Example 2 with MArea

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

the class ModelServiceImpl method isLastEditorStack.

@Override
public boolean isLastEditorStack(MUIElement stack) {
    if (!(stack instanceof MPartStack)) {
        return false;
    }
    // is it in the shared area?
    MUIElement parent = stack.getParent();
    while (parent != null && !(parent instanceof MArea)) {
        parent = parent.getParent();
    }
    if (parent == null) {
        return false;
    }
    // OK, it's in the area, is it the last TBR one ?
    MArea area = (MArea) parent;
    List<MPartStack> stacks = findElements(area, null, MPartStack.class, null);
    int count = 0;
    for (MPartStack aStack : stacks) {
        if (aStack.isToBeRendered()) {
            count++;
        }
    }
    return count < 2 && stack.isToBeRendered();
}
Also used : MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement)

Example 3 with MArea

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

the class ModelServiceImpl method getElementLocation.

@Override
public int getElementLocation(MUIElement element) {
    if (element == null) {
        return NOT_IN_UI;
    }
    // If the element is shared then use its current placeholder
    if (element.getCurSharedRef() != null) {
        element = element.getCurSharedRef();
    }
    int location = NOT_IN_UI;
    MUIElement curElement = element;
    while (curElement != null) {
        Object container = ((EObject) curElement).eContainer();
        if (!(container instanceof MUIElement))
            return NOT_IN_UI;
        if (container instanceof MApplication) {
            if (location != NOT_IN_UI)
                return location;
            return OUTSIDE_PERSPECTIVE;
        } else if (container instanceof MPerspective) {
            MPerspective perspective = (MPerspective) container;
            MUIElement perspParent = perspective.getParent();
            if (perspParent == null) {
                location = NOT_IN_UI;
            } else if (perspective.getParent().getSelectedElement() == perspective) {
                location |= IN_ACTIVE_PERSPECTIVE;
            } else {
                location |= IN_ANY_PERSPECTIVE;
            }
        } else if (container instanceof MTrimBar) {
            location = IN_TRIM;
        } else if (container instanceof MArea) {
            location = IN_SHARED_AREA;
        }
        curElement = (MUIElement) container;
    }
    return NOT_IN_UI;
}
Also used : MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) EObject(org.eclipse.emf.ecore.EObject) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) EObject(org.eclipse.emf.ecore.EObject) MTrimBar(org.eclipse.e4.ui.model.application.ui.basic.MTrimBar) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 4 with MArea

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

the class PartActivationHistory method getNextActivationCandidate.

MPart getNextActivationCandidate(Collection<MPart> validParts, MPart part) {
    MArea area = isInArea(part);
    if (area != null) {
        // focus should stay in the area if possible
        MPart candidate = getSiblingActivationCandidate(part);
        if (candidate != null) {
            return candidate;
        }
        // no sibling candidate, find another part in the area to activate
        candidate = findActivationCandidate(modelService.findElements(area, null, MPart.class), part);
        if (candidate != null) {
            return candidate;
        }
    }
    // check activation history, since the history is global, we need to filter it down first
    Collection<MPart> validCandidates = new ArrayList<>();
    for (MPart validPart : generalActivationHistory) {
        if (validParts.contains(validPart)) {
            validCandidates.add(validPart);
        }
    }
    MPart candidate = findActivationCandidate(validCandidates, part);
    return candidate == null ? getActivationCandidate(part) : candidate;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) ArrayList(java.util.ArrayList)

Example 5 with MArea

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

the class PlaceholderResolver method resolvePlaceholderRef.

@Override
public void resolvePlaceholderRef(MPlaceholder ph, MWindow refWin) {
    if (ph.getRef() != null)
        return;
    // Must give us the window that you are resolving for...
    Assert.isLegal(refWin != null);
    // ..and it must be a 'top level' window
    MUIElement refParent = refWin.getParent();
    Assert.isLegal(refParent instanceof MApplication);
    // So we already have a matching shared element ?
    List<MUIElement> sharedElements = refWin.getSharedElements();
    for (MUIElement se : sharedElements) {
        if (ph.getElementId().equals(se.getElementId())) {
            ph.setRef(se);
            return;
        }
    }
    // Hack to make the 3.x compatibility layer work
    if (ph.getElementId().equals("org.eclipse.ui.editorss")) {
        // $NON-NLS-1$
        // This code is for the eclipse compatibility layer...
        MArea sharedArea = AdvancedFactoryImpl.eINSTANCE.createArea();
        // sharedArea.setLabel("Editor Area"); //$NON-NLS-1$
        MPartStack editorStack = BasicFactoryImpl.eINSTANCE.createPartStack();
        // $NON-NLS-1$
        editorStack.getTags().add("org.eclipse.e4.primaryDataStack");
        // $NON-NLS-1$
        editorStack.getTags().add("EditorStack");
        // $NON-NLS-1$
        editorStack.setElementId("org.eclipse.e4.primaryDataStack");
        sharedArea.getChildren().add(editorStack);
        sharedArea.setElementId(ph.getElementId());
        refWin.getSharedElements().add(sharedArea);
        ph.setRef(sharedArea);
        return;
    }
    // Assume that the placeholder is to a shared 'part'
    EPartService ps = refWin.getContext().get(EPartService.class);
    MPart newReferencedPart = ps.createPart(ph.getElementId());
    if (newReferencedPart != null) {
        refWin.getSharedElements().add(newReferencedPart);
        ph.setRef(newReferencedPart);
        return;
    }
// SHould we log / show an exception here ?
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Aggregations

MArea (org.eclipse.e4.ui.model.application.ui.advanced.MArea)40 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)30 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)26 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)21 MPerspective (org.eclipse.e4.ui.model.application.ui.advanced.MPerspective)18 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)18 Test (org.junit.Test)18 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)17 MPerspectiveStack (org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack)15 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)12 MApplication (org.eclipse.e4.ui.model.application.MApplication)10 MPartSashContainer (org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer)8 CTabFolder (org.eclipse.swt.custom.CTabFolder)7 Composite (org.eclipse.swt.widgets.Composite)5 MTrimBar (org.eclipse.e4.ui.model.application.ui.basic.MTrimBar)4 ArrayList (java.util.ArrayList)3 MElementContainer (org.eclipse.e4.ui.model.application.ui.MElementContainer)3 MTrimmedWindow (org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow)3 EObject (org.eclipse.emf.ecore.EObject)3 MalformedURLException (java.net.MalformedURLException)2