ongoing work for Bug 284610 - Implement shared parts (fix EA handling).
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/LazyStackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/LazyStackRenderer.java
index 5b74b2c..9a4b911 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/LazyStackRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/workbench/ui/renderers/swt/LazyStackRenderer.java
@@ -135,7 +135,7 @@
List<MUIElement> becomingVisible = new ArrayList<MUIElement>();
MUIElement curSel = element.getParent().getSelectedElement();
if (curSel != null) {
- showElementRecursive(curSel, becomingVisible);
+ showElementRecursive(curSel, becomingVisible, null);
}
}
@@ -180,19 +180,14 @@
}
private void showElementRecursive(MUIElement element,
- List<MUIElement> becomingVisible) {
+ List<MUIElement> becomingVisible, IEclipseContext phParentContext) {
if (!element.isToBeRendered())
return;
if (element instanceof MPlaceholder && element.getWidget() != null) {
MPlaceholder ph = (MPlaceholder) element;
MUIElement ref = ph.getRef();
- if (ref instanceof MContext) {
- IEclipseContext context = ((MContext) ref).getContext();
- IEclipseContext newParentContext = getContext(ph);
- if (context.getParent() != newParentContext)
- context.setParent(newParentContext);
- }
+ phParentContext = getContext(ph);
Composite phComp = (Composite) ph.getWidget();
Control refCtrl = (Control) ph.getRef().getWidget();
@@ -202,6 +197,13 @@
element = ref;
}
+ if (element instanceof MContext && phParentContext != null) {
+ IEclipseContext context = ((MContext) element).getContext();
+ if (context.getParent() != phParentContext)
+ context.setParent(phParentContext);
+ phParentContext = null;
+ }
+
// Show any floating windows
if (element instanceof MWindow && element.getWidget() != null) {
element.setVisible(true);
@@ -216,23 +218,24 @@
if (curSel == null && container.getChildren().size() > 0)
curSel = container.getChildren().get(0);
if (curSel != null)
- showElementRecursive(curSel, becomingVisible);
+ showElementRecursive(curSel, becomingVisible, phParentContext);
} else if (element instanceof MElementContainer<?>) {
MElementContainer<?> container = (MElementContainer<?>) element;
List<MUIElement> kids = new ArrayList<MUIElement>(
container.getChildren());
for (MUIElement childElement : kids) {
- showElementRecursive(childElement, becomingVisible);
+ showElementRecursive(childElement, becomingVisible,
+ phParentContext);
}
// OK, now process detached windows
if (element instanceof MWindow) {
for (MWindow w : ((MWindow) element).getWindows()) {
- showElementRecursive(w, becomingVisible);
+ showElementRecursive(w, becomingVisible, phParentContext);
}
} else if (element instanceof MPerspective) {
for (MWindow w : ((MPerspective) element).getWindows()) {
- showElementRecursive(w, becomingVisible);
+ showElementRecursive(w, becomingVisible, phParentContext);
}
}
}
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/modeling/EModelService.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/modeling/EModelService.java
index 6008fc3..186ed60 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/modeling/EModelService.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/modeling/EModelService.java
@@ -17,6 +17,7 @@
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
/**
* @since 1.0
@@ -80,6 +81,28 @@
public IEclipseContext getContainingContext(MUIElement element);
/**
+ * Ensures that the given element is visible in the UI
+ *
+ * @param window
+ * The containing MWindow
+ * @param element
+ * The element to bring to the top
+ */
+ public void bringToTop(MWindow window, MUIElement element);
+
+ /**
+ * Given a containing MWindow find the MPlaceholder that is currently being used to host the
+ * given element (if any)
+ *
+ * @param window
+ * The containing window
+ * @param element
+ * The element to find the MPlaceholder for
+ * @return the MPlaceholder or null if none is found
+ */
+ public MPlaceholder findPlaceholderFor(MWindow window, MUIElement element);
+
+ /**
* Move the element to a new location. The element will be placed at the end of the new parent's
* list of children.
*
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ModelServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ModelServiceImpl.java
index a036193..36494c3 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ModelServiceImpl.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/ModelServiceImpl.java
@@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.List;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MGenericStack;
@@ -21,6 +22,7 @@
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MAdvancedFactory;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement;
@@ -34,9 +36,6 @@
/**
*
*/
-/**
- *
- */
public class ModelServiceImpl implements EModelService {
/**
* Determine if the element passes the matching test for all non-null parameters.
@@ -165,6 +164,60 @@
* (non-Javadoc)
*
* @see
+ * org.eclipse.e4.workbench.modeling.EModelService#bringToTop(org.eclipse.e4.ui.model.application
+ * .ui.basic.MWindow, org.eclipse.e4.ui.model.application.ui.MUIElement)
+ */
+ public void bringToTop(MWindow window, MUIElement element) {
+ if (element instanceof MApplication)
+ return;
+
+ MUIElement parent = element.getParent();
+ if (parent == null) {
+ MPlaceholder ph = findPlaceholderFor(window, element);
+ if (ph != null) {
+ element = ph;
+ parent = element.getParent();
+ }
+ }
+
+ if (parent != null) {
+ // Force the element to be rendered
+ if (!element.isToBeRendered())
+ element.setToBeRendered(true);
+
+ ((MElementContainer<MUIElement>) parent).setSelectedElement(element);
+ bringToTop(window, parent);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.e4.workbench.modeling.EModelService#findPlaceholderFor(org.eclipse.e4.ui.model
+ * .application.ui.basic.MWindow, org.eclipse.e4.ui.model.application.ui.MUIElement)
+ */
+ public MPlaceholder findPlaceholderFor(MWindow window, MUIElement element) {
+ List<MPerspectiveStack> psList = findElements(window, null, MPerspectiveStack.class, null);
+ if (psList.size() != 1)
+ return null;
+ MPerspectiveStack pStack = psList.get(0);
+ MPerspective persp = pStack.getSelectedElement();
+ if (persp == null)
+ return null;
+
+ List<MPlaceholder> phList = findElements(persp, null, MPlaceholder.class, null);
+ for (MPlaceholder ph : phList) {
+ if (ph.getRef() == element)
+ return ph;
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
* org.eclipse.e4.workbench.modeling.EModelService#move(org.eclipse.e4.ui.model.application.
* MUIElement, org.eclipse.e4.ui.model.application.MElementContainer)
*/
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java
index 1ee64d4..802564d 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/PartServiceImpl.java
@@ -298,34 +298,20 @@
return;
}
- IEclipseContext curContext = part.getContext();
- MContext pwc = getParentWithContext(part);
- MUIElement curElement = part;
- while (pwc != null) {
- // Ensure that the UI model has the part 'on top'
- while (curElement != pwc) {
- MElementContainer<MUIElement> parent = curElement.getParent();
- curElement.setToBeRendered(true);
- if (parent.getSelectedElement() != curElement) {
- parent.setSelectedElement(curElement);
- }
- curElement = parent;
- }
-
- if (curContext == null) {
- curContext = part.getContext();
- }
-
- IEclipseContext parentContext = pwc.getContext();
- if (parentContext != null) {
- parentContext.set(IContextConstants.ACTIVE_CHILD, curContext);
- curContext = parentContext;
- }
-
- pwc = getParentWithContext((MUIElement) pwc);
+ modelService.bringToTop(window, part);
+ IEclipseContext context = part.getContext();
+ IEclipseContext parent = context.getParent();
+ while (parent != null) {
+ parent.set(IContextConstants.ACTIVE_CHILD, context);
+ context = parent;
+ parent = parent.getParent();
}
}
+ @Inject
+ @Optional
+ MWindow window;
+
/*
* (non-Javadoc)
*
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java
index 113b0af..825d585 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java
@@ -224,7 +224,7 @@
}
public void setEditorAreaVisible(boolean showEditorArea) {
- editorStack.setToBeRendered(showEditorArea);
+ // editorStack.setToBeRendered(showEditorArea);
}
public void setEditorReuseThreshold(int openEditors) {