summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorWojciech Sudol2013-11-20 05:17:01 (EST)
committer Gerrit Code Review @ Eclipse.org2013-11-20 10:23:33 (EST)
commit51d39d22cb1e715774a3254e8ac30dabab796956 (patch)
tree00df0cd8188478ab67cd212f8c8c06bffe66af93
parent24fa07639e8d8ba20176a1e1d1eb36d4b3727f9f (diff)
downloadeclipse.platform.ui-51d39d22cb1e715774a3254e8ac30dabab796956.zip
eclipse.platform.ui-51d39d22cb1e715774a3254e8ac30dabab796956.tar.gz
eclipse.platform.ui-51d39d22cb1e715774a3254e8ac30dabab796956.tar.bz2
Bug 415499 - Maintain activation through DnD gesturesrefs/changes/07/18607/2
Change-Id: I3834633b186257d2daa480d96bd532044b7fb489 Signed-off-by: Wojciech Sudol <wojciech.sudol@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DetachedDropAgent.java4
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DropAgent.java40
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent.java1
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java34
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java11
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java44
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java95
7 files changed, 128 insertions, 101 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DetachedDropAgent.java b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DetachedDropAgent.java
index 6dd4503..1521576 100644
--- a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DetachedDropAgent.java
+++ b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DetachedDropAgent.java
@@ -59,6 +59,10 @@ public class DetachedDropAgent extends DropAgent {
modelService.detach((MPartSashContainerElement) dragElement, curRect.x, curRect.y,
curRect.width, curRect.height);
+
+ // Fully re-activate the part since its location has changed
+ reactivatePart(dragElement);
+
return true;
}
diff --git a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DropAgent.java b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DropAgent.java
index 58d1397..e741550 100644
--- a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DropAgent.java
+++ b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DropAgent.java
@@ -11,7 +11,12 @@
package org.eclipse.e4.ui.workbench.addons.dndaddon;
+import org.eclipse.e4.core.contexts.IEclipseContext;
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.MPart;
+import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Rectangle;
@@ -30,6 +35,41 @@ abstract class DropAgent {
dndManager = manager;
}
+ public void reactivatePart(MUIElement dragElement) {
+ IEclipseContext context = dndManager.getModelService().getContainingContext(dragElement);
+ if (context == null)
+ return;
+
+ EPartService ps = context.get(EPartService.class);
+ if (ps == null)
+ return;
+
+ MPart partToActivate = null;
+ if (dragElement instanceof MPart) {
+ partToActivate = (MPart) dragElement;
+ } else if (dragElement instanceof MPlaceholder) {
+ MPlaceholder ph = (MPlaceholder) dragElement;
+ if (ph.getRef() instanceof MPart) {
+ partToActivate = (MPart) ph.getRef();
+ }
+ } else if (dragElement instanceof MPartStack) {
+ MPartStack stack = (MPartStack) dragElement;
+ if (stack.getSelectedElement() instanceof MPart) {
+ partToActivate = (MPart) stack.getSelectedElement();
+ } else if (stack.getSelectedElement() instanceof MPlaceholder) {
+ MPlaceholder ph = (MPlaceholder) stack.getSelectedElement();
+ if (ph.getRef() instanceof MPart) {
+ partToActivate = (MPart) ph.getRef();
+ }
+ }
+ }
+
+ if (partToActivate != null) {
+ ps.activate(null);
+ ps.activate(partToActivate);
+ }
+ }
+
public abstract boolean canDrop(MUIElement dragElement, DnDInfo info);
public abstract boolean drop(MUIElement dragElement, DnDInfo info);
diff --git a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent.java b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent.java
index b278fb4..0f6ed5d 100644
--- a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent.java
+++ b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/SplitDropAgent.java
@@ -170,6 +170,7 @@ public class SplitDropAgent extends DropAgent {
public boolean drop(MUIElement dragElement, DnDInfo info) {
if (dndManager.getFeedbackStyle() != DnDManager.HOSTED && curDockLocation != NOWHERE) {
dock(dragElement, curDockLocation);
+ reactivatePart(dragElement);
}
clearFeedback();
return true;
diff --git a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java
index 1710251..2a101eb 100644
--- a/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java
+++ b/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java
@@ -255,14 +255,34 @@ public class StackDropAgent extends DropAgent {
MPartStack stack = (MPartStack) dragElement;
MStackElement curSel = stack.getSelectedElement();
List<MStackElement> kids = stack.getChildren();
- while (kids.size() > 0) {
- MStackElement lastChild = kids.remove(kids.size() - 1);
+
+ // First move over all *non-selected* elements
+ int selIndex = kids.indexOf(curSel);
+ boolean curSelProcessed = false;
+ while (kids.size() > 1) {
+ // Offset the 'get' to account for skipping 'curSel'
+ MStackElement kid = curSelProcessed ? kids.get(kids.size() - 2) : kids.get(kids
+ .size() - 1);
+ if (kid == curSel) {
+ curSelProcessed = true;
+ continue;
+ }
+
+ kids.remove(kid);
if (dropIndex >= 0 && dropIndex < dropStack.getChildren().size())
- dropStack.getChildren().add(dropIndex, lastChild);
+ dropStack.getChildren().add(dropIndex, kid);
else
- dropStack.getChildren().add(lastChild);
+ dropStack.getChildren().add(kid);
}
+ // Finally, move over the selected element
+ kids.remove(curSel);
+ dropIndex = dropIndex + selIndex;
+ if (dropIndex >= 0 && dropIndex < dropStack.getChildren().size())
+ dropStack.getChildren().add(dropIndex, curSel);
+ else
+ dropStack.getChildren().add(curSel);
+
// (Re)active the element being dropped
dropStack.setSelectedElement(curSel);
}
@@ -294,8 +314,12 @@ public class StackDropAgent extends DropAgent {
public boolean drop(MUIElement dragElement, DnDInfo info) {
if (dndManager.getFeedbackStyle() != DnDManager.HOSTED) {
int dropIndex = getDropIndex(info);
- if (dropIndex != -1)
+ if (dropIndex != -1) {
+ MUIElement toActivate = dragElement instanceof MPartStack ? ((MPartStack) dragElement)
+ .getSelectedElement() : dragElement;
dock(dragElement, dropIndex);
+ reactivatePart(toActivate);
+ }
}
return true;
}
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java
index 12cc41d..c4b2823 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java
@@ -18,6 +18,7 @@ import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.MUILabel;
@@ -63,6 +64,16 @@ public abstract class SWTPartRenderer extends AbstractPartRenderer {
}
}
+ public void styleElement(MUIElement element, boolean active) {
+ if (!active)
+ element.getTags().remove(CSSConstants.CSS_ACTIVE_CLASS);
+ else
+ element.getTags().add(CSSConstants.CSS_ACTIVE_CLASS);
+
+ if (element.getWidget() != null)
+ setCSSInfo(element, element.getWidget());
+ }
+
public void setCSSInfo(MUIElement me, Object widget) {
// Set up the CSS Styling parameters; id & class
IEclipseContext ctxt = getContext(me);
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
index dc58a6a..8d59326 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
@@ -150,9 +150,11 @@ public class StackRenderer extends LazyStackRenderer {
* toolbar has been changed.
*/
private EventHandler childrenHandler;
-
private EventHandler tabStateHandler;
+ // Manages CSS styling based on active part changes
+ private EventHandler stylingHandler;
+
private boolean ignoreTabSelChanges = false;
// private ToolBar menuTB;
@@ -384,6 +386,45 @@ public class StackRenderer extends LazyStackRenderer {
eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN,
childrenHandler);
+ stylingHandler = new EventHandler() {
+ public void handleEvent(Event event) {
+ MUIElement changed = (MUIElement) event
+ .getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(changed instanceof MPart))
+ return;
+
+ MPart newActivePart = (MPart) changed;
+ MUIElement partParent = newActivePart.getParent();
+ if (partParent == null
+ && newActivePart.getCurSharedRef() != null)
+ partParent = newActivePart.getCurSharedRef().getParent();
+
+ MPartStack pStack = (MPartStack) (partParent instanceof MPartStack ? partParent
+ : null);
+
+ EModelService ms = newActivePart.getContext().get(
+ EModelService.class);
+ List<String> tags = new ArrayList<String>();
+ tags.add(CSSConstants.CSS_ACTIVE_CLASS);
+ List<MUIElement> activeElements = ms.findElements(
+ ms.getTopLevelWindowFor(newActivePart), null,
+ MUIElement.class, tags);
+ for (MUIElement element : activeElements) {
+ if (element instanceof MPartStack && element != pStack) {
+ styleElement(element, false);
+ } else if (element instanceof MPart
+ && element != newActivePart) {
+ styleElement(element, false);
+ }
+ }
+
+ if (pStack != null)
+ styleElement(pStack, true);
+ styleElement(newActivePart, true);
+ }
+ };
+ eventBroker.subscribe(UIEvents.UILifeCycle.ACTIVATE, stylingHandler);
+
tabStateHandler = new TabStateHandler();
eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS,
tabStateHandler);
@@ -447,6 +488,7 @@ public class StackRenderer extends LazyStackRenderer {
eventBroker.unsubscribe(dirtyUpdater);
eventBroker.unsubscribe(viewMenuUpdater);
eventBroker.unsubscribe(childrenHandler);
+ eventBroker.unsubscribe(stylingHandler);
eventBroker.unsubscribe(tabStateHandler);
}
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java
index 8bc4477..f538a51 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java
@@ -18,24 +18,17 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
-import javax.inject.Named;
import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.log.Logger;
-import org.eclipse.e4.ui.internal.workbench.Activator;
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
import org.eclipse.e4.ui.internal.workbench.PartServiceSaveHandler;
-import org.eclipse.e4.ui.internal.workbench.Policy;
-import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
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.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
-import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
import org.eclipse.e4.ui.model.application.ui.basic.MTrimmedWindow;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
@@ -122,63 +115,11 @@ public class WBWRenderer extends SWTPartRenderer {
private EventHandler shellUpdater;
private EventHandler visibilityHandler;
private EventHandler sizeHandler;
- private EventHandler childHandler;
public WBWRenderer() {
super();
}
- MPart activePart = null;
-
- @Inject
- void trackActivePart(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart p) {
- if (activePart == p) {
- return;
- }
-
- if (activePart != null) {
- activePart.getTags().remove(CSSConstants.CSS_ACTIVE_CLASS);
-
- MUIElement parent = activePart.getParent();
- if (parent == null && activePart.getCurSharedRef() != null) {
- MPlaceholder ph = activePart.getCurSharedRef();
- parent = ph.getParent();
- }
- if (parent instanceof MPartStack) {
- styleStack((MPartStack) parent, false);
- } else {
- if (activePart.getWidget() != null)
- setCSSInfo(activePart, activePart.getWidget());
- }
- }
-
- activePart = p;
-
- if (activePart != null) {
- activePart.getTags().add(CSSConstants.CSS_ACTIVE_CLASS);
- MUIElement parent = activePart.getParent();
- if (parent == null && activePart.getCurSharedRef() != null) {
- MPlaceholder ph = activePart.getCurSharedRef();
- parent = ph.getParent();
- }
- if (parent instanceof MPartStack && parent.getWidget() != null) {
- styleStack((MPartStack) parent, true);
- } else if (activePart.getWidget() != null) {
- setCSSInfo(activePart, activePart.getWidget());
- }
- }
- }
-
- private void styleStack(MPartStack stack, boolean active) {
- if (!active)
- stack.getTags().remove(CSSConstants.CSS_ACTIVE_CLASS);
- else
- stack.getTags().add(CSSConstants.CSS_ACTIVE_CLASS);
-
- if (stack.getWidget() != null)
- setCSSInfo(stack, stack.getWidget());
- }
-
/**
* Closes the provided detached window.
*
@@ -349,41 +290,6 @@ public class WBWRenderer extends SWTPartRenderer {
};
eventBroker.subscribe(UIEvents.Window.TOPIC_ALL, sizeHandler);
-
- childHandler = new EventHandler() {
- public void handleEvent(Event event) {
- // Track additions/removals of the active part and keep its
- // stack styled correctly
- Object changedObj = event
- .getProperty(UIEvents.EventTags.ELEMENT);
- if (!(changedObj instanceof MPartStack))
- return;
- MPartStack stack = (MPartStack) changedObj;
-
- if (UIEvents.isADD(event)) {
- for (Object o : UIEvents.asIterable(event,
- UIEvents.EventTags.NEW_VALUE)) {
- MUIElement added = (MUIElement) o;
- if (added == activePart) {
- styleStack(stack, true);
- }
- }
- } else if (UIEvents.isREMOVE(event)) {
- Activator.trace(Policy.DEBUG_RENDERER,
- "Child Removed", null); //$NON-NLS-1$
- for (Object o : UIEvents.asIterable(event,
- UIEvents.EventTags.OLD_VALUE)) {
- MUIElement removed = (MUIElement) o;
- if (removed == activePart) {
- styleStack(stack, false);
- }
- }
- }
- }
- };
-
- eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN,
- childHandler);
}
@PreDestroy
@@ -392,7 +298,6 @@ public class WBWRenderer extends SWTPartRenderer {
eventBroker.unsubscribe(shellUpdater);
eventBroker.unsubscribe(visibilityHandler);
eventBroker.unsubscribe(sizeHandler);
- eventBroker.unsubscribe(childHandler);
}
public Object createWidget(MUIElement element, Object parent) {