aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-01-31 13:55:43 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-01-31 13:55:43 +0000
commitc7c9e8c2c7b52a82882ed9165f84494802211749 (patch)
tree4f48299fe7db771ea2294381a89d156671988dc0
parent9c57035c34e8228c602b61672587c30b3be2fe1f (diff)
downloadvaadin-framework-c7c9e8c2c7b52a82882ed9165f84494802211749.tar.gz
vaadin-framework-c7c9e8c2c7b52a82882ed9165f84494802211749.zip
svn changeset:11066/svn branch:6.3_dd
-rw-r--r--src/com/vaadin/event/AbstractDropHandler.java48
-rw-r--r--src/com/vaadin/event/DragRequest.java11
-rw-r--r--src/com/vaadin/event/HasDropHandler.java18
-rw-r--r--src/com/vaadin/terminal/DragSource.java (renamed from src/com/vaadin/terminal/TransferTranslator.java)14
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java6
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTree.java18
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/AbstractDropHandler.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriteria.java2
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterionImpl.java24
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/DragAndDropManager.java12
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/DragEvent.java15
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/Transferable.java8
-rw-r--r--src/com/vaadin/terminal/gwt/server/DragAndDropService.java26
-rw-r--r--src/com/vaadin/ui/DragDropPane.java58
-rw-r--r--src/com/vaadin/ui/Table.java24
-rw-r--r--src/com/vaadin/ui/Tree.java66
-rw-r--r--tests/src/com/vaadin/tests/dd/AcceptFromComponent.java4
-rw-r--r--tests/src/com/vaadin/tests/dd/CustomDDImplementation.java19
-rw-r--r--tests/src/com/vaadin/tests/dd/DDTest1.java20
-rw-r--r--tests/src/com/vaadin/tests/dd/DDTest2.java17
21 files changed, 273 insertions, 157 deletions
diff --git a/src/com/vaadin/event/AbstractDropHandler.java b/src/com/vaadin/event/AbstractDropHandler.java
index da15dc61b6..9023183f50 100644
--- a/src/com/vaadin/event/AbstractDropHandler.java
+++ b/src/com/vaadin/event/AbstractDropHandler.java
@@ -4,6 +4,8 @@ import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.DragAndDropManager.DragEventType;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Tree.Location;
+import com.vaadin.ui.Tree.TreeDropDetails;
/**
* An implementation of DropHandler interface.
@@ -19,12 +21,9 @@ public abstract class AbstractDropHandler implements DropHandler {
* Criterion that can be used create policy to accept/discard dragged
* content (presented by {@link Transferable}).
*
- * TODO figure out how this can be done partly on client at least in some
- * cases. isClientSideFilterable() tms.
- *
*/
public interface AcceptCriterion {
- public boolean accepts(Transferable transferable);
+ public boolean accepts(DragRequest request);
}
public interface ClientSideVerifiable extends AcceptCriterion {
@@ -41,7 +40,7 @@ public abstract class AbstractDropHandler implements DropHandler {
}
private static final class AcceptAll implements ClientSideVerifiable {
- public boolean accepts(Transferable transferable) {
+ public boolean accepts(DragRequest event) {
return true;
}
@@ -65,8 +64,8 @@ public abstract class AbstractDropHandler implements DropHandler {
this.f2 = f2;
}
- public boolean accepts(Transferable transferable) {
- return f1.accepts(transferable) && f2.accepts(transferable);
+ public boolean accepts(DragRequest event) {
+ return f1.accepts(event) && f2.accepts(event);
}
public boolean isClientSideVerifiable() {
@@ -95,9 +94,9 @@ public abstract class AbstractDropHandler implements DropHandler {
this.component = component;
}
- public boolean accepts(Transferable transferable) {
- if (transferable instanceof ComponentTransferrable) {
- return ((ComponentTransferrable) transferable)
+ public boolean accepts(DragRequest event) {
+ if (event.getTransferable() instanceof ComponentTransferrable) {
+ return ((ComponentTransferrable) event.getTransferable())
.getSourceComponent() == component;
} else {
return false;
@@ -117,7 +116,8 @@ public abstract class AbstractDropHandler implements DropHandler {
}
private static final class IsDataBinded implements ClientSideVerifiable {
- public boolean accepts(Transferable transferable) {
+ public boolean accepts(DragRequest event) {
+ Transferable transferable = event.getTransferable();
if (transferable instanceof DataBindedTransferrable) {
return ((DataBindedTransferrable) transferable).getItemId() != null;
}
@@ -142,8 +142,8 @@ public abstract class AbstractDropHandler implements DropHandler {
this.acceptCriterion = acceptCriterion;
}
- public boolean accepts(Transferable transferable) {
- return !acceptCriterion.accepts(transferable);
+ public boolean accepts(DragRequest event) {
+ return !acceptCriterion.accepts(event);
}
}
@@ -157,17 +157,18 @@ public abstract class AbstractDropHandler implements DropHandler {
this.f2 = f2;
}
- public boolean accepts(Transferable transferable) {
- return f1.accepts(transferable) || f2.accepts(transferable);
+ public boolean accepts(DragRequest event) {
+ return f1.accepts(event) || f2.accepts(event);
}
}
public static class OverTreeNode implements ClientSideVerifiable {
- public boolean accepts(Transferable transferable) {
+ public boolean accepts(DragRequest event) {
try {
- return transferable.getData("detail").toString().toLowerCase()
- .equals("center");
+ TreeDropDetails eventDetails = (TreeDropDetails) event
+ .getEventDetails();
+ return eventDetails.getDropLocation() == Location.MIDDLE;
} catch (Exception e) {
return false;
}
@@ -197,8 +198,8 @@ public abstract class AbstractDropHandler implements DropHandler {
* @seecom.vaadin.event.DropHandler#acceptTransferrable(com.vaadin.event.
* Transferable)
*/
- public boolean acceptTransferrable(Transferable transferable) {
- return acceptCriterion.accepts(transferable);
+ public boolean acceptTransferrable(DragRequest request) {
+ return acceptCriterion.accepts(request);
}
private boolean clientSideVerifiable() {
@@ -210,11 +211,10 @@ public abstract class AbstractDropHandler implements DropHandler {
}
public void handleDragRequest(DragRequest event) {
- boolean acceptTransferrable = acceptTransferrable(event
- .getTransferrable());
+ boolean acceptTransferrable = acceptTransferrable(event);
if (acceptTransferrable) {
if (event.getType() == DragEventType.DROP) {
- receive(event.getTransferrable());
+ receive(event.getTransferable(), event.getEventDetails());
} else {
event.setResponseParameter("accepted", true);
}
@@ -237,7 +237,7 @@ public abstract class AbstractDropHandler implements DropHandler {
*
* @see com.vaadin.event.DropHandler#receive(com.vaadin.event.Transferable)
*/
- public abstract void receive(Transferable transferable);
+ public abstract void receive(Transferable transferable, Object dropDetails);
public void setAcceptCriterion(AcceptCriterion acceptCriterion) {
this.acceptCriterion = acceptCriterion;
diff --git a/src/com/vaadin/event/DragRequest.java b/src/com/vaadin/event/DragRequest.java
index b1bd2a6316..c9a918aa23 100644
--- a/src/com/vaadin/event/DragRequest.java
+++ b/src/com/vaadin/event/DragRequest.java
@@ -10,13 +10,14 @@ public class DragRequest {
private DragEventType dragEventType;
private Transferable transferable;
private Map<String, Object> responseData;
+ private Object eventDetails;
public DragRequest(DragEventType dragEventType, Transferable transferable) {
this.dragEventType = dragEventType;
this.transferable = transferable;
}
- public Transferable getTransferrable() {
+ public Transferable getTransferable() {
return transferable;
}
@@ -43,4 +44,12 @@ public class DragRequest {
responseData.put(key, value);
}
+ public void setEventDetails(Object eventDetails) {
+ this.eventDetails = eventDetails;
+ }
+
+ public Object getEventDetails() {
+ return eventDetails;
+ }
+
}
diff --git a/src/com/vaadin/event/HasDropHandler.java b/src/com/vaadin/event/HasDropHandler.java
index 73ce74c392..8326e5ff37 100644
--- a/src/com/vaadin/event/HasDropHandler.java
+++ b/src/com/vaadin/event/HasDropHandler.java
@@ -1,13 +1,27 @@
package com.vaadin.event;
+import java.util.Map;
+
import com.vaadin.ui.Component;
/**
- * Implementing component most commonly has also setDropHandler method, but
- * not polluting interface here as component might also have internal
+ * Implementing component most commonly has also setDropHandler method, but not
+ * polluting interface here as component might also have internal
* AbstractDropHandler implementation.
*
*/
public interface HasDropHandler extends Component {
public DropHandler getDropHandler();
+
+ /**
+ * TODO Consider using map-like type as return type that would be auto
+ * created by terminal in case this implementation would return null. Would
+ * enable using simple event details without server side class. Should at
+ * least include the component that {@link HasDropHandler} -> would make it
+ * possible for one drophandler to be used on multiple components.
+ *
+ * @param rawVariables
+ * @return
+ */
+ public Object getDragEventDetails(Map<String, Object> rawVariables);
} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/TransferTranslator.java b/src/com/vaadin/terminal/DragSource.java
index 01d56a73ed..ee4006e742 100644
--- a/src/com/vaadin/terminal/TransferTranslator.java
+++ b/src/com/vaadin/terminal/DragSource.java
@@ -4,17 +4,19 @@ import java.util.Map;
import com.vaadin.event.Transferable;
-public interface TransferTranslator {
+public interface DragSource {
/**
- * Translate translators may convert client side variables to meaningful
- * values on server side. For example in Selects we convert item identifiers
- * to generated string keys for the client side. Translators in Selects
- * should convert them back to item identifiers.
+ * DragSource may convert client side variables to meaningful values on
+ * server side. For example in Selects we convert item identifiers to
+ * generated string keys for the client side. Translators in Selects should
+ * convert them back to item identifiers.
* <p>
* Translator should remove variables it handled from rawVariables. All non
* handled variables are added to Transferable automatically by terminal.
*
+ * <p>
+ *
* @param transferable
* the Transferable object if one has been created for this drag
* and drop operation, null if Transferable is not yet
@@ -23,6 +25,6 @@ public interface TransferTranslator {
* @return
*/
public Transferable getTransferrable(Transferable transferable,
- Map<String, Object> rawVariables, boolean isDropTarget);
+ Map<String, Object> rawVariables);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java b/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java
index 6bdfa7a9bb..3504b8d258 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java
@@ -1,5 +1,7 @@
package com.vaadin.terminal.gwt.client.ui;
+import java.util.Map;
+
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.event.dom.client.MouseDownEvent;
@@ -47,7 +49,7 @@ public class VDragDropPane extends VAbsoluteLayout implements Container,
cloneNode.getStyle().setBackgroundColor("#999");
cloneNode.getStyle().setOpacity(0.4);
drag.setDragImage(cloneNode);
- drag.getTransferrable().setData(
+ drag.getEventDetails().put(
"mouseDown",
new MouseEventDetails(event.getNativeEvent())
.serialize());
@@ -206,7 +208,7 @@ public class VDragDropPane extends VAbsoluteLayout implements Container,
return false;
}
- Transferable transferable = drag.getTransferrable();
+ Map<String, Object> transferable = drag.getEventDetails();
// this is absolute layout based, and we may want to set
// component
@@ -216,8 +218,8 @@ public class VDragDropPane extends VAbsoluteLayout implements Container,
int absoluteLeft = getAbsoluteLeft();
int absoluteTop = getAbsoluteTop();
- transferable.setData("absoluteLeft", absoluteLeft);
- transferable.setData("absoluteTop", absoluteTop);
+ transferable.put("absoluteLeft", absoluteLeft);
+ transferable.put("absoluteTop", absoluteTop);
getStyleElement().getStyle().setBackgroundColor("yellow");
return super.drop(drag);
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
index a680835126..08419ec45b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
@@ -41,6 +41,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.VScrollTable.VScrollTableBody.VScrollTableRow;
import com.vaadin.terminal.gwt.client.ui.dd.DragAndDropManager;
+import com.vaadin.terminal.gwt.client.ui.dd.DragEvent;
import com.vaadin.terminal.gwt.client.ui.dd.Transferable;
/**
@@ -2503,9 +2504,8 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler {
transferable.setItemId("" + rowKey);
// TODO propertyId
- com.vaadin.terminal.gwt.client.ui.dd.DragEvent ev = DragAndDropManager
- .get().startDrag(transferable, event,
- true);
+ DragEvent ev = DragAndDropManager.get()
+ .startDrag(transferable, event, true);
Element cloneNode = (Element) getElement()
.cloneNode(true);
cloneNode.getStyle().setOpacity(0.4);
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
index f3fa28c656..948e6705c1 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
@@ -162,7 +162,7 @@ public class VTree extends FlowPanel implements Paintable, HasDropHandler {
}
private void updateTreeRelatedTransferData(DragEvent drag) {
- drag.getTransferrable().setData("itemIdOver", currentMouseOverKey);
+ drag.getEventDetails().put("itemIdOver", currentMouseOverKey);
if (currentMouseOverKey != null) {
String detail = getDropDetail(drag.getCurrentGwtEvent());
@@ -171,9 +171,8 @@ public class VTree extends FlowPanel implements Paintable, HasDropHandler {
&& "Center".equals(detail)) {
overTreeNode = true;
}
- drag.getTransferrable().setData("itemIdOverIsNode", overTreeNode);
-
- drag.getTransferrable().setData("detail", detail);
+ drag.getEventDetails().put("itemIdOverIsNode", overTreeNode);
+ drag.getEventDetails().put("detail", detail);
}
}
@@ -194,10 +193,10 @@ public class VTree extends FlowPanel implements Paintable, HasDropHandler {
@Override
public void dragOver(final DragEvent currentDrag) {
- final Object oldIdOver = currentDrag.getTransferrable()
- .getData("itemIdOver");
+ final Object oldIdOver = currentDrag.getEventDetails().get(
+ "itemIdOver");
final String oldDetail = (String) currentDrag
- .getTransferrable().getData("detail");
+ .getEventDetails().get("detail");
/*
* Using deferred command, so event bubbles to TreeNode
* event listener. Currently here via preview
@@ -209,7 +208,7 @@ public class VTree extends FlowPanel implements Paintable, HasDropHandler {
boolean nodeHasChanged = (currentMouseOverKey != null && currentMouseOverKey != oldIdOver)
|| (oldIdOver != null);
boolean detailHasChanded = !detail
- .equals(oldIdOver);
+ .equals(oldDetail);
if (nodeHasChanged || detailHasChanded) {
ApplicationConnection.getConsole().log(
@@ -236,8 +235,7 @@ public class VTree extends FlowPanel implements Paintable, HasDropHandler {
DragEventType.OVER, accpectedCb);
} else {
- if (validates(currentDrag
- .getTransferrable())) {
+ if (validates(currentDrag)) {
accpectedCb.handleResponse(null);
} else {
keyToNode.get(currentMouseOverKey)
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/AbstractDropHandler.java b/src/com/vaadin/terminal/gwt/client/ui/dd/AbstractDropHandler.java
index db656829fa..0319655b75 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/AbstractDropHandler.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/AbstractDropHandler.java
@@ -58,7 +58,7 @@ public abstract class AbstractDropHandler implements DropHandler {
}
}
});
- } else if (validates(drag.getTransferrable())) {
+ } else if (validates(drag)) {
dragAccepted(drag);
}
}
@@ -68,17 +68,17 @@ public abstract class AbstractDropHandler implements DropHandler {
/**
* Returns true if client side rules are met.
*
- * @param transferable
+ * @param drag
* @return
*/
- protected boolean validates(Transferable transferable) {
+ protected boolean validates(DragEvent drag) {
if (criterioUIDL != null) {
String criteriaName = criterioUIDL.getStringAttribute("name");
AcceptCriteria acceptCriteria = AcceptCriterion.get(criteriaName);
if (acceptCriteria != null) {
// ApplicationConnection.getConsole().log(
// "Criteria : " + acceptCriteria.getClass().getName());
- return acceptCriteria.accept(transferable, criterioUIDL);
+ return acceptCriteria.accept(drag, criterioUIDL);
}
}
return false;
@@ -88,7 +88,7 @@ public abstract class AbstractDropHandler implements DropHandler {
if (serverValidate) {
return true;
} else {
- return validates(drag.getTransferrable());
+ return validates(drag);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriteria.java b/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriteria.java
index 34f9f6dc66..8a1081fff3 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriteria.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriteria.java
@@ -4,6 +4,6 @@ import com.vaadin.terminal.gwt.client.UIDL;
public interface AcceptCriteria {
- public boolean accept(Transferable transferable, UIDL configuration);
+ public boolean accept(DragEvent drag, UIDL configuration);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterionImpl.java b/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterionImpl.java
index 5444cfb7e6..e0e170bc19 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterionImpl.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterionImpl.java
@@ -10,9 +10,9 @@ import com.vaadin.terminal.gwt.client.UIDL;
public class AcceptCriterionImpl {
private final class OverTreeNode implements AcceptCriteria {
- public boolean accept(Transferable transferable, UIDL configuration) {
- Boolean containsKey = (Boolean) transferable
- .getData("itemIdOverIsNode");
+ public boolean accept(DragEvent drag, UIDL configuration) {
+ Boolean containsKey = (Boolean) drag.getEventDetails().get(
+ "itemIdOverIsNode");
if (containsKey != null && containsKey.booleanValue()) {
return true;
}
@@ -21,11 +21,9 @@ public class AcceptCriterionImpl {
}
private final class ComponentCriteria implements AcceptCriteria {
- public boolean accept(Transferable transferable, UIDL configuration) {
+ public boolean accept(DragEvent drag, UIDL configuration) {
try {
- // FIXME should have access to client too, change transferrable
- // to DragEvent??
- Paintable component = transferable.getComponent();
+ Paintable component = drag.getTransferrable().getComponent();
String requiredPid = configuration
.getStringAttribute("component");
String pid = ((Widget) component).getElement()
@@ -38,7 +36,7 @@ public class AcceptCriterionImpl {
}
private final class And implements AcceptCriteria {
- public boolean accept(Transferable transferable, UIDL configuration) {
+ public boolean accept(DragEvent drag, UIDL configuration) {
UIDL childUIDL = configuration.getChildUIDL(0);
UIDL childUIDL2 = configuration.getChildUIDL(1);
AcceptCriteria acceptCriteria = AcceptCriterion.get(childUIDL
@@ -50,21 +48,21 @@ public class AcceptCriterionImpl {
"And criteria didn't found a chidl criteria");
return false;
}
- boolean accept = acceptCriteria.accept(transferable, childUIDL);
- boolean accept2 = acceptCriteria2.accept(transferable, childUIDL2);
+ boolean accept = acceptCriteria.accept(drag, childUIDL);
+ boolean accept2 = acceptCriteria2.accept(drag, childUIDL2);
return accept && accept2;
}
}
private final class AcceptAll implements AcceptCriteria {
- public boolean accept(Transferable transferable, UIDL configuration) {
+ public boolean accept(DragEvent drag, UIDL configuration) {
return true;
}
}
private final class HasItemId implements AcceptCriteria {
- public boolean accept(Transferable transferable, UIDL configuration) {
- return transferable.getItemId() != null;
+ public boolean accept(DragEvent drag, UIDL configuration) {
+ return drag.getTransferrable().getItemId() != null;
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/DragAndDropManager.java b/src/com/vaadin/terminal/gwt/client/ui/dd/DragAndDropManager.java
index 8dc17e0f78..b97cad5da5 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/DragAndDropManager.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/DragAndDropManager.java
@@ -345,19 +345,21 @@ public class DragAndDropManager {
try {
MouseEventDetails mouseEventDetails = new MouseEventDetails(
currentDrag.currentGwtEvent);
- transferable.setData("mouseEvent", mouseEventDetails
- .serialize());
+ currentDrag.getEventDetails().put("mouseEvent",
+ mouseEventDetails.serialize());
} catch (Exception e) {
// NOP, (at least oophm on Safari) can't serialize html dd event
// to
// mouseevent
}
} else {
- transferable.setData("mouseEvent", null);
+ currentDrag.getEventDetails().put("mouseEvent", null);
}
+ client.updateVariable(DD_SERVICE, "evt", currentDrag.getEventDetails(),
+ false);
- client.updateVariable(DD_SERVICE, "payload", transferable
- .getVariableMap(), true);
+ client.updateVariable(DD_SERVICE, "tra", transferable.getVariableMap(),
+ true);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/DragEvent.java b/src/com/vaadin/terminal/gwt/client/ui/dd/DragEvent.java
index abed4679ee..a64a29925c 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/DragEvent.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/DragEvent.java
@@ -1,6 +1,8 @@
package com.vaadin.terminal.gwt.client.ui.dd;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.Element;
@@ -25,6 +27,8 @@ public class DragEvent {
private Date start;
+ private HashMap<String, Object> dropDetails = new HashMap<String, Object>();
+
DragEvent(Transferable t, NativeEvent startEvent) {
transferable = t;
this.startEvent = startEvent;
@@ -63,4 +67,15 @@ public class DragEvent {
DragAndDropManager.get().setDragElement(node);
}
+ /**
+ * TODO consider using similar smaller (than map) api as in Transferable
+ *
+ * TODO clean up when drop handler changes
+ *
+ * @return
+ */
+ public Map<String, Object> getEventDetails() {
+ return dropDetails;
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/Transferable.java b/src/com/vaadin/terminal/gwt/client/ui/dd/Transferable.java
index 52ea08fe7e..dc0244ae24 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/Transferable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/Transferable.java
@@ -4,7 +4,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import com.vaadin.terminal.TransferTranslator;
+import com.vaadin.terminal.DragSource;
import com.vaadin.terminal.gwt.client.Paintable;
/**
@@ -32,7 +32,7 @@ public class Transferable {
* This is commonly actually a key to property id on client side than the
* actual propertyId.
*
- * Translated by terminal and {@link TransferTranslator}
+ * Translated by terminal and {@link DragSource}
*
* @return the propertyId
*/
@@ -44,7 +44,7 @@ public class Transferable {
* This is commonly actually a key to property id on client side than the
* actual propertyId.
*
- * Translated by terminal and {@link TransferTranslator}
+ * Translated by terminal and {@link DragSource}
*
* @param propertyId
* the propertyId to set
@@ -64,7 +64,7 @@ public class Transferable {
* This is commonly actually a key to item id on client side than the actual
* itemId.
*
- * Translated by terminal and {@link TransferTranslator}
+ * Translated by terminal and {@link DragSource}
*
* @param itemId
* the itemId to set
diff --git a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
index 3371c741ae..64df92ed48 100644
--- a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
+++ b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
@@ -10,7 +10,7 @@ import com.vaadin.event.DragRequest;
import com.vaadin.event.DropHandler;
import com.vaadin.event.HasDropHandler;
import com.vaadin.event.Transferable;
-import com.vaadin.terminal.TransferTranslator;
+import com.vaadin.terminal.DragSource;
import com.vaadin.terminal.VariableOwner;
import com.vaadin.terminal.gwt.client.ui.dd.DragAndDropManager.DragEventType;
import com.vaadin.ui.Component;
@@ -38,6 +38,12 @@ public class DragAndDropService implements VariableOwner {
currentRequest = constructDragRequest(variables, dropHandlerOwner);
DropHandler dropHandler = (dropHandlerOwner).getDropHandler();
+
+ Object eventDetails = dropHandlerOwner
+ .getDragEventDetails((Map<String, Object>) variables.get("evt"));
+
+ currentRequest.setEventDetails(eventDetails);
+
dropHandler.handleDragRequest(currentRequest);
if (currentRequest.getType() == DragEventType.DROP) {
// TODO transferable should also be cleaned on each non-dnd
@@ -70,10 +76,13 @@ public class DragAndDropService implements VariableOwner {
final Component sourceComponent = (Component) variables
.get("component");
+
+ variables = (Map<String, Object>) variables.get("tra");
+
if (sourceComponent != null
- && sourceComponent instanceof TransferTranslator) {
- transferable = ((TransferTranslator) sourceComponent)
- .getTransferrable(transferable, variables, false);
+ && sourceComponent instanceof DragSource) {
+ transferable = ((DragSource) sourceComponent)
+ .getTransferrable(transferable, variables);
} else {
if (transferable == null) {
if (sourceComponent != null) {
@@ -118,19 +127,10 @@ public class DragAndDropService implements VariableOwner {
}
}
}
- /*
- * Also let dropHandler translate variables if it implements
- * TransferTranslator
- */
- if (dropHandlerOwner instanceof TransferTranslator) {
- transferable = ((TransferTranslator) dropHandlerOwner)
- .getTransferrable(transferable, variables, true);
- }
/*
* Add remaining (non-handled) variables to transferable as is
*/
- variables = (Map<String, Object>) variables.get("payload");
for (String key : variables.keySet()) {
transferable.setData(key, variables.get(key));
}
diff --git a/src/com/vaadin/ui/DragDropPane.java b/src/com/vaadin/ui/DragDropPane.java
index 293ea8a6ae..4111955335 100644
--- a/src/com/vaadin/ui/DragDropPane.java
+++ b/src/com/vaadin/ui/DragDropPane.java
@@ -1,5 +1,7 @@
package com.vaadin.ui;
+import java.util.Map;
+
import com.vaadin.event.AbstractDropHandler;
import com.vaadin.event.ComponentTransferrable;
import com.vaadin.event.DataBindedTransferrable;
@@ -43,7 +45,10 @@ public class DragDropPane extends AbsoluteLayout implements HasDropHandler {
if (dropHandler == null) {
dropHandler = new AbstractDropHandler() {
@Override
- public void receive(Transferable transferable) {
+ public void receive(Transferable transferable,
+ Object dropDetails) {
+
+ DragEventDetails ed = (DragEventDetails) dropDetails;
if (transferable instanceof ComponentTransferrable) {
ComponentTransferrable ctr = (ComponentTransferrable) transferable;
Component component = ctr.getSourceComponent();
@@ -68,14 +73,11 @@ public class DragDropPane extends AbsoluteLayout implements HasDropHandler {
// this
DragDropPane.this.addComponent(component);
}
- Integer left = (Integer) transferable
- .getData("absoluteLeft");
- Integer top = (Integer) transferable
- .getData("absoluteTop");
- MouseEventDetails eventDetails = MouseEventDetails
- .deSerialize((String) transferable
- .getData("mouseEvent"));
+ Integer left = ed.getAbsoluteLeft();
+ Integer top = ed.getAbsoluteTop();
+
+ MouseEventDetails eventDetails = ed.getMouseEvent();
int clientX = eventDetails.getClientX();
int clientY = eventDetails.getClientY();
@@ -91,12 +93,8 @@ public class DragDropPane extends AbsoluteLayout implements HasDropHandler {
} else {
// drag ended inside the this Pane
- MouseEventDetails start = MouseEventDetails
- .deSerialize((String) transferable
- .getData("mouseDown"));
- MouseEventDetails eventDetails = MouseEventDetails
- .deSerialize((String) transferable
- .getData("mouseEvent"));
+ MouseEventDetails start = ed.getMouseDownEvent();
+ MouseEventDetails eventDetails = ed.getMouseEvent();
int deltaX = eventDetails.getClientX()
- start.getClientX();
@@ -161,4 +159,36 @@ public class DragDropPane extends AbsoluteLayout implements HasDropHandler {
return abstractDropHandler;
}
+ class DragEventDetails {
+
+ private Map<String, Object> vars;
+
+ public DragEventDetails(Map<String, Object> rawVariables) {
+ vars = rawVariables;
+ }
+
+ public Integer getAbsoluteTop() {
+ return (Integer) vars.get("absoluteTop");
+ }
+
+ public Integer getAbsoluteLeft() {
+ return (Integer) vars.get("absoluteLeft");
+ }
+
+ public MouseEventDetails getMouseDownEvent() {
+ return MouseEventDetails
+ .deSerialize((String) vars.get("mouseDown"));
+ }
+
+ public MouseEventDetails getMouseEvent() {
+ return MouseEventDetails.deSerialize((String) vars
+ .get("mouseEvent"));
+ }
+
+ }
+
+ public Object getDragEventDetails(Map<String, Object> rawVariables) {
+ return new DragEventDetails(rawVariables);
+ }
+
}
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index 5b99f614f1..8babc68e1a 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -33,7 +33,7 @@ import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
-import com.vaadin.terminal.TransferTranslator;
+import com.vaadin.terminal.DragSource;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VScrollTable;
@@ -58,7 +58,7 @@ import com.vaadin.terminal.gwt.client.ui.VScrollTable;
@ClientWidget(VScrollTable.class)
public class Table extends AbstractSelect implements Action.Container,
Container.Ordered, Container.Sortable, ItemClickSource,
- TransferTranslator {
+ DragSource {
/**
* Modes that Table support as drag sourse.
@@ -3352,25 +3352,21 @@ public class Table extends AbstractSelect implements Action.Container,
}
- private void updateTransferrable(Map<String, Object> rawVariables,
- Transferable tr, boolean isDropTarget) {
- Map<String, Object> payload = (Map<String, Object>) rawVariables
- .get("payload");
- if (!isDropTarget) {
- Object object = payload.get("itemId");
- if (object != null) {
- tr.setData("itemId", itemIdMapper.get((String) object));
- payload.remove("itemId");
- }
+ private void updateTransferrable(Map<String, Object> payload,
+ Transferable tr) {
+ Object object = payload.get("itemId");
+ if (object != null) {
+ tr.setData("itemId", itemIdMapper.get((String) object));
+ payload.remove("itemId");
}
}
public Transferable getTransferrable(Transferable transferable,
- Map<String, Object> rawVariables, boolean isDropTarget) {
+ Map<String, Object> rawVariables) {
if (transferable == null) {
transferable = new TableTransferrable();
}
- updateTransferrable(rawVariables, transferable, isDropTarget);
+ updateTransferrable(rawVariables, transferable);
return transferable;
}
}
diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java
index 8e5cd8aca7..61c667cde0 100644
--- a/src/com/vaadin/ui/Tree.java
+++ b/src/com/vaadin/ui/Tree.java
@@ -31,11 +31,11 @@ import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.Transferable;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.event.ItemClickEvent.ItemClickSource;
+import com.vaadin.terminal.DragSource;
import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
-import com.vaadin.terminal.TransferTranslator;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VTree;
@@ -51,7 +51,7 @@ import com.vaadin.terminal.gwt.client.ui.VTree;
@SuppressWarnings("serial")
@ClientWidget(VTree.class)
public class Tree extends AbstractSelect implements Container.Hierarchical,
- Action.Container, ItemClickSource, TransferTranslator, HasDropHandler {
+ Action.Container, ItemClickSource, DragSource, HasDropHandler {
private static final Method EXPAND_METHOD;
@@ -145,27 +145,16 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
}
public Transferable getTransferrable(Transferable transferable,
- Map<String, Object> rawVariables, boolean isDropTarget) {
+ Map<String, Object> payload) {
if (transferable == null) {
transferable = new TreeTransferrable();
}
- Map<String, Object> payload = (Map<String, Object>) rawVariables
- .get("payload");
- if (isDropTarget) {
- // updating drag target variables
- Object object = payload.get("itemIdOver");
- Object object2 = itemIdMapper.get((String) object);
- transferable.setData("itemIdOver", object2);
- payload.remove("itemIdOver");
- } else {
- // updating drag source variables
- Object object = payload.get("itemId");
- if (object != null) {
- transferable.setData("itemId", itemIdMapper
- .get((String) object));
- }
- payload.remove("itemId");
+ // updating drag source variables
+ Object object = payload.get("itemId");
+ if (object != null) {
+ transferable.setData("itemId", itemIdMapper.get((String) object));
}
+ payload.remove("itemId");
return transferable;
}
@@ -1162,4 +1151,43 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
this.abstractDropHandler = abstractDropHandler;
}
+ public Object getDragEventDetails(Map<String, Object> rawVariables) {
+ return new TreeDropDetails(rawVariables);
+ }
+
+ public enum Location {
+ TOP, BOTTOM, MIDDLE
+ }
+
+ public class TreeDropDetails {
+
+ private Map<String, Object> vars;
+ private Object idOver;
+
+ TreeDropDetails(Map<String, Object> rawVariables) {
+ vars = rawVariables;
+ // eagar fetch itemid, mapper may be emptied
+ String keyover = (String) vars.get("itemIdOver");
+ if (keyover != null) {
+ idOver = itemIdMapper.get(keyover);
+ }
+ }
+
+ public Object getItemIdOver() {
+ return idOver;
+ }
+
+ public Location getDropLocation() {
+ String s = (String) vars.get("detail");
+ if ("Top".equals(s)) {
+ return Location.TOP;
+ } else if ("Bottom".equals(s)) {
+ return Location.BOTTOM;
+ } else {
+ return Location.MIDDLE;
+ }
+ }
+
+ }
+
}
diff --git a/tests/src/com/vaadin/tests/dd/AcceptFromComponent.java b/tests/src/com/vaadin/tests/dd/AcceptFromComponent.java
index 3b3a9c13a0..28bc8b53c8 100644
--- a/tests/src/com/vaadin/tests/dd/AcceptFromComponent.java
+++ b/tests/src/com/vaadin/tests/dd/AcceptFromComponent.java
@@ -1,6 +1,7 @@
package com.vaadin.tests.dd;
import com.vaadin.event.ComponentTransferrable;
+import com.vaadin.event.DragRequest;
import com.vaadin.event.Transferable;
import com.vaadin.event.AbstractDropHandler.AcceptCriterion;
import com.vaadin.ui.DragDropPane;
@@ -15,7 +16,8 @@ public class AcceptFromComponent extends Window {
DragDropPane pane = new DragDropPane();
setContent(pane);
pane.getDropHandler().setAcceptCriterion(new AcceptCriterion() {
- public boolean accepts(Transferable transferable) {
+ public boolean accepts(DragRequest request) {
+ Transferable transferable = request.getTransferable();
if (transferable instanceof ComponentTransferrable) {
ComponentTransferrable componentTransferrable = (ComponentTransferrable) transferable;
if (componentTransferrable.getSourceComponent() == tree1) {
diff --git a/tests/src/com/vaadin/tests/dd/CustomDDImplementation.java b/tests/src/com/vaadin/tests/dd/CustomDDImplementation.java
index 01490cd248..53c18fdfc8 100644
--- a/tests/src/com/vaadin/tests/dd/CustomDDImplementation.java
+++ b/tests/src/com/vaadin/tests/dd/CustomDDImplementation.java
@@ -1,5 +1,7 @@
package com.vaadin.tests.dd;
+import java.util.Map;
+
import com.vaadin.event.AbstractDropHandler;
import com.vaadin.event.DragRequest;
import com.vaadin.event.DropHandler;
@@ -41,9 +43,9 @@ public class CustomDDImplementation extends CustomComponent {
public DropHandler getDropHandler() {
return new DropHandler() {
- public void handleDragRequest(DragRequest event) {
- Transferable transferable = event.getTransferrable();
- DragEventType type = event.getType();
+ public void handleDragRequest(DragRequest dragRequest) {
+ Transferable transferable = dragRequest.getTransferable();
+ DragEventType type = dragRequest.getType();
switch (type) {
case DROP:
// Do something with data
@@ -53,7 +55,7 @@ public class CustomDDImplementation extends CustomComponent {
case ENTER:
// eg. validate transferrable
if (transferable.getDataFlawors().contains("Foo")) {
- event.getResponseData().put("valueFor",
+ dragRequest.getResponseData().put("valueFor",
"clientSideCallBack");
}
@@ -72,6 +74,15 @@ public class CustomDDImplementation extends CustomComponent {
};
}
+ public Object getDragEventDetails(Map<String, Object> rawVariables) {
+ /*
+ * If client side sets some event details, translate them to desired
+ * server side presentation here. The returned object will be passed
+ * for drop handler.
+ */
+ return null;
+ }
+
}
/**
diff --git a/tests/src/com/vaadin/tests/dd/DDTest1.java b/tests/src/com/vaadin/tests/dd/DDTest1.java
index 9fee73da0c..0dcf7aaf7f 100644
--- a/tests/src/com/vaadin/tests/dd/DDTest1.java
+++ b/tests/src/com/vaadin/tests/dd/DDTest1.java
@@ -7,6 +7,7 @@ import com.vaadin.data.util.HierarchicalContainer;
import com.vaadin.event.AbstractDropHandler;
import com.vaadin.event.ComponentTransferrable;
import com.vaadin.event.DataBindedTransferrable;
+import com.vaadin.event.DragRequest;
import com.vaadin.event.Transferable;
import com.vaadin.event.AbstractDropHandler.AcceptCriterion;
import com.vaadin.terminal.ExternalResource;
@@ -20,6 +21,8 @@ import com.vaadin.ui.Link;
import com.vaadin.ui.Table;
import com.vaadin.ui.Tree;
import com.vaadin.ui.Table.DragModes;
+import com.vaadin.ui.Tree.Location;
+import com.vaadin.ui.Tree.TreeDropDetails;
/**
* DD playground. Better quality example/prototype codes in {@link DDTest2}.
@@ -57,7 +60,8 @@ public class DDTest1 extends TestBase {
.setCaption("Pane2 (accept needs server side visit, only \"Bar\")");
AcceptCriterion f = new AcceptCriterion() {
- public boolean accepts(Transferable transferable) {
+ public boolean accepts(DragRequest request) {
+ Transferable transferable = request.getTransferable();
// System.out.println("Simulating 500ms processing...");
// try {
// Thread.sleep(200);
@@ -112,22 +116,22 @@ public class DDTest1 extends TestBase {
AbstractDropHandler itemSorter = new AbstractDropHandler() {
@Override
- public void receive(Transferable transferable) {
+ public void receive(Transferable transferable, Object dropdetails) {
+ TreeDropDetails details = (TreeDropDetails) dropdetails;
// TODO set properties, so same sorter could be used in Table
if (transferable instanceof DataBindedTransferrable) {
DataBindedTransferrable transferrable2 = (DataBindedTransferrable) transferable;
Object itemId = transferrable2.getItemId();
- Object itemIdOver = transferable.getData("itemIdOver");
+ Object itemIdOver = details.getItemIdOver();
- String detail = ((String) transferable.getData("detail"))
- .toLowerCase();
+ Location dropLocation = details.getDropLocation();
- if ("center".equals(detail)) {
+ if (dropLocation == Location.MIDDLE) {
t.setParent(itemId, itemIdOver);
return;
- } else if ("top".equals(detail)) {
+ } else if (Location.TOP == dropLocation) {
// if on top of the caption area, add before
itemIdOver = idx.prevItemId(itemIdOver);
}
@@ -142,7 +146,7 @@ public class DDTest1 extends TestBase {
if (removed) {
- if (detail == null) {
+ if (dropLocation == null) {
System.err
.println("No detail of drop place available");
}
diff --git a/tests/src/com/vaadin/tests/dd/DDTest2.java b/tests/src/com/vaadin/tests/dd/DDTest2.java
index 6777eade4d..04162045f7 100644
--- a/tests/src/com/vaadin/tests/dd/DDTest2.java
+++ b/tests/src/com/vaadin/tests/dd/DDTest2.java
@@ -18,6 +18,7 @@ import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.Tree;
import com.vaadin.ui.Window;
+import com.vaadin.ui.Tree.TreeDropDetails;
public class DDTest2 extends TestBase {
@@ -53,7 +54,7 @@ public class DDTest2 extends TestBase {
AbstractDropHandler dropHandler = new AbstractDropHandler() {
@Override
- public void receive(Transferable transferable) {
+ public void receive(Transferable transferable, Object dropdetails) {
/*
* We know transferrable is from table, so it is of type
* DataBindedTransferrable
@@ -63,14 +64,16 @@ public class DDTest2 extends TestBase {
Table fromTable = (Table) tr.getSourceComponent();
String name = fromTable.getItem(itemId).getItemProperty("Name")
.toString();
+
tree1.addItem(name);
tree1.setChildrenAllowed(name, false);
/*
- * As we also accept only drops on folders, we know data
- * contains itemIdOver
+ * As we also accept only drops on folders, we know dropDetails
+ * is from Tree and it contains itemIdOver.
*/
- Object idOver = tr.getData("itemIdOver");
+ TreeDropDetails details = (TreeDropDetails) dropdetails;
+ Object idOver = details.getItemIdOver();
tree1.setParent(name, idOver);
/*
@@ -99,12 +102,14 @@ public class DDTest2 extends TestBase {
dropHandler = new AbstractDropHandler() {
@Override
- public void receive(Transferable transferable) {
+ public void receive(Transferable transferable, Object dropdetails) {
+ TreeDropDetails details = (TreeDropDetails) dropdetails;
+
if (transferable instanceof DataBindedTransferrable) {
DataBindedTransferrable tr = (DataBindedTransferrable) transferable;
Object itemId = tree2.addItem();
- tree2.setParent(itemId, tr.getData("itemIdOver"));
+ tree2.setParent(itemId, details.getItemIdOver());
if (tr.getSourceComponent() == tree1) {
// use item id from tree1 as caption
tree2.setItemCaption(itemId, (String) tr.getItemId());