summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-02-12 11:40:21 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-02-12 11:40:21 +0000
commitb361498f510e144419b19bf3865f39895b07f1d2 (patch)
tree8333305362dd2d4658741a44ef129efd299e0a67 /src/com
parentac88783e91f6d4a40280d5c345fd4bd83ed4051d (diff)
downloadvaadin-framework-b361498f510e144419b19bf3865f39895b07f1d2.tar.gz
vaadin-framework-b361498f510e144419b19bf3865f39895b07f1d2.zip
n:th proto
svn changeset:11292/svn branch:6.3_dd
Diffstat (limited to 'src/com')
-rw-r--r--src/com/vaadin/event/AbstractDropHandler.java264
-rw-r--r--src/com/vaadin/event/DragDropDataTranslator.java26
-rw-r--r--src/com/vaadin/event/DragDropDetails.java12
-rw-r--r--src/com/vaadin/event/DragDropDetailsImpl.java28
-rw-r--r--src/com/vaadin/event/DragDropHandler.java8
-rw-r--r--src/com/vaadin/event/DragRequest.java40
-rw-r--r--src/com/vaadin/event/DropHandler.java7
-rw-r--r--src/com/vaadin/event/DropTarget.java15
-rw-r--r--src/com/vaadin/event/dd/DragAndDropEvent.java24
-rw-r--r--src/com/vaadin/event/dd/DragEvent.java34
-rw-r--r--src/com/vaadin/event/dd/DragSource.java (renamed from src/com/vaadin/terminal/DragSource.java)4
-rw-r--r--src/com/vaadin/event/dd/DropEvent.java10
-rw-r--r--src/com/vaadin/event/dd/DropHandler.java23
-rw-r--r--src/com/vaadin/event/dd/DropTarget.java34
-rw-r--r--src/com/vaadin/event/dd/TargetDetails.java10
-rw-r--r--src/com/vaadin/event/dd/TargetDetailsImpl.java27
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/AcceptAll.java39
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/AcceptCriterion.java48
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/And.java43
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/ClientSideCriterion.java36
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/ComponentFilter.java43
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/IsDataBinded.java43
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/Not.java36
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/Or.java37
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/OverTreeNode.java39
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/ServerSideCriterion.java36
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java25
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTree.java21
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VAbstractDropHandler.java75
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCallback.java2
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriteria.java13
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterion.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterionImpl.java184
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java74
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VDragEventServerCallback.java9
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VTransferable.java2
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java54
-rw-r--r--src/com/vaadin/terminal/gwt/server/DragAndDropService.java114
-rw-r--r--src/com/vaadin/ui/DragDropPane.java231
-rw-r--r--src/com/vaadin/ui/Table.java2
-rw-r--r--src/com/vaadin/ui/Tree.java105
41 files changed, 1165 insertions, 720 deletions
diff --git a/src/com/vaadin/event/AbstractDropHandler.java b/src/com/vaadin/event/AbstractDropHandler.java
deleted file mode 100644
index 633e7a0c10..0000000000
--- a/src/com/vaadin/event/AbstractDropHandler.java
+++ /dev/null
@@ -1,264 +0,0 @@
-package com.vaadin.event;
-
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.Tree.Location;
-import com.vaadin.ui.Tree.TreeDropDetails;
-
-/**
- * An implementation of DropHandler interface.
- *
- * AcceptCriterion may be used to configure accept rules. Using them can result
- * client side verifiable accept rules for quick feedback in UI. Still rules are
- * also validate on server so implementor don't need to double check validity on
- * {@link #receive(Transferable)} method.
- *
- */
-public abstract class AbstractDropHandler implements DragDropHandler {
- /**
- * Criterion that can be used create policy to accept/discard dragged
- * content (presented by {@link Transferable}).
- *
- */
- public interface AcceptCriterion {
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails);
- }
-
- public interface ClientSideVerifiable extends AcceptCriterion {
-
- /**
- * May depend on state, like in OR or AND, so to be really
- * ClientSideVerifiable needs to return true here (instead of just
- * implementing marker interface).
- */
- public boolean isClientSideVerifiable();
-
- public void paint(PaintTarget target) throws PaintException;
-
- }
-
- private static final class AcceptAll implements ClientSideVerifiable {
-
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- return true;
- }
-
- public boolean isClientSideVerifiable() {
- return true;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("acceptCriterion");
- target.addAttribute("name", "acceptAll");
- target.endTag("acceptCriterion");
- }
- }
-
- public static class And implements ClientSideVerifiable {
- private AcceptCriterion f1;
- private AcceptCriterion f2;
-
- public And(AcceptCriterion f1, AcceptCriterion f2) {
- this.f1 = f1;
- this.f2 = f2;
- }
-
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- return f1.accepts(transferable, dragDropDetails)
- && f2.accepts(transferable, dragDropDetails);
- }
-
- public boolean isClientSideVerifiable() {
- boolean a1 = f1 instanceof ClientSideVerifiable ? ((ClientSideVerifiable) f1)
- .isClientSideVerifiable()
- : false;
- boolean a2 = f2 instanceof ClientSideVerifiable ? ((ClientSideVerifiable) f2)
- .isClientSideVerifiable()
- : false;
- return a1 && a2;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("acceptCriterion");
- target.addAttribute("name", "and");
- ((ClientSideVerifiable) f1).paint(target);
- ((ClientSideVerifiable) f2).paint(target);
- target.endTag("acceptCriterion");
- }
- }
-
- public static class ComponentFilter implements ClientSideVerifiable {
- private Component component;
-
- public ComponentFilter(Component component) {
- this.component = component;
- }
-
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- if (transferable instanceof ComponentTransferable) {
- return ((ComponentTransferable) transferable)
- .getSourceComponent() == component;
- } else {
- return false;
- }
- }
-
- public boolean isClientSideVerifiable() {
- return true;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("acceptCriterion");
- target.addAttribute("name", "component");
- target.addAttribute("component", component);
- target.endTag("acceptCriterion");
- }
- }
-
- private static final class IsDataBinded implements ClientSideVerifiable {
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- if (transferable instanceof DataBindedTransferable) {
- return ((DataBindedTransferable) transferable).getItemId() != null;
- }
- return false;
- }
-
- public boolean isClientSideVerifiable() {
- return true;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("acceptCriterion");
- target.addAttribute("name", "needsItemId");
- target.endTag("acceptCriterion");
- }
- }
-
- public class Not implements AcceptCriterion {
- private AcceptCriterion acceptCriterion;
-
- public Not(AcceptCriterion acceptCriterion) {
- this.acceptCriterion = acceptCriterion;
- }
-
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- return !acceptCriterion.accepts(transferable, dragDropDetails);
- }
-
- }
-
- public class Or implements AcceptCriterion {
- private AcceptCriterion f1;
- private AcceptCriterion f2;
-
- Or(AcceptCriterion f1, AcceptCriterion f2) {
- this.f1 = f1;
- this.f2 = f2;
- }
-
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- return f1.accepts(transferable, dragDropDetails)
- || f2.accepts(transferable, dragDropDetails);
- }
- }
-
- public static class OverTreeNode implements ClientSideVerifiable {
-
- public boolean accepts(Transferable transferable,
- DragDropDetails dragDropDetails) {
- try {
- TreeDropDetails eventDetails = (TreeDropDetails) dragDropDetails;
- return eventDetails.getDropLocation() == Location.MIDDLE;
- } catch (Exception e) {
- return false;
- }
- }
-
- public boolean isClientSideVerifiable() {
- return true;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("acceptCriterion");
- target.addAttribute("name", "overTreeNode");
- target.endTag("acceptCriterion");
- }
-
- }
-
- public static final AcceptCriterion CRITERION_ACCEPT_ALL = new AcceptAll();
-
- public static final AcceptCriterion CRITERION_HAS_ITEM_ID = new IsDataBinded();
-
- private AcceptCriterion acceptCriterion = CRITERION_ACCEPT_ALL;
-
- /*
- * (non-Javadoc)
- *
- * @seecom.vaadin.event.DropHandler#acceptTransferable(com.vaadin.event.
- * Transferable)
- */
- public boolean acceptTransferable(Transferable transferable,
- DragDropDetails dragDropDetails) {
- return acceptCriterion.accepts(transferable, dragDropDetails);
- }
-
- private boolean clientSideVerifiable() {
- if (acceptCriterion instanceof ClientSideVerifiable) {
- return ((ClientSideVerifiable) acceptCriterion)
- .isClientSideVerifiable();
- }
- return false;
- }
-
- public void handleDragRequest(DragRequest event, Transferable transferable,
- DragDropDetails dragDropDetails) {
- boolean acceptTransferable = acceptTransferable(transferable,
- dragDropDetails);
- if (acceptTransferable) {
- event.setResponseParameter("accepted", true);
- }
- }
-
- public boolean drop(Transferable transferable,
- DragDropDetails dragDropDetails) {
- boolean acceptTransferable = acceptTransferable(transferable,
- dragDropDetails);
- if (acceptTransferable) {
- receive(transferable, dragDropDetails);
- return true;
- }
- return false;
- }
-
- public void paint(PaintTarget target) throws PaintException {
- target.startTag("dh");
- if (!clientSideVerifiable()) {
- target.addAttribute("serverValidate", true);
- } else {
- ((ClientSideVerifiable) acceptCriterion).paint(target);
- }
- target.endTag("dh");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.event.DropHandler#receive(com.vaadin.event.Transferable)
- */
- public abstract void receive(Transferable transferable,
- DragDropDetails dropDetails);
-
- public void setAcceptCriterion(AcceptCriterion acceptCriterion) {
- this.acceptCriterion = acceptCriterion;
- }
-
-}
diff --git a/src/com/vaadin/event/DragDropDataTranslator.java b/src/com/vaadin/event/DragDropDataTranslator.java
deleted file mode 100644
index dbb5141b81..0000000000
--- a/src/com/vaadin/event/DragDropDataTranslator.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.vaadin.event;
-
-import java.util.Map;
-
-/**
- * DragDropDataTranslator provides a method for translating drop data from a
- * client side widget to server side values. This interface is optional for drop
- * operations and only need to be implemented if translation is necessary. If
- * this is not implemented the data will be passed through as-is without
- * conversion.
- */
-public interface DragDropDataTranslator {
- /**
- * Called before a drop operation to translate the drop data provided by the
- * client widget. Should return a DropData implementation with the new
- * values. If null is returned the {@link DragDropHandler} will
- * automatically create a DropData with all the client variables.
- *
- * @param rawVariables
- * Parameters passed from the client side widget.
- * @return A DropData object with the translated data or null.
- */
- public DragDropDetails translateDragDropDetails(
- Map<String, Object> clientVariables);
-
-} \ No newline at end of file
diff --git a/src/com/vaadin/event/DragDropDetails.java b/src/com/vaadin/event/DragDropDetails.java
deleted file mode 100644
index f617411e23..0000000000
--- a/src/com/vaadin/event/DragDropDetails.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.vaadin.event;
-
-import com.vaadin.ui.Component;
-
-public interface DragDropDetails {
-
- public Object get(String key);
-
- public Object put(String key, Object value);
-
- public Component getTarget();
-}
diff --git a/src/com/vaadin/event/DragDropDetailsImpl.java b/src/com/vaadin/event/DragDropDetailsImpl.java
deleted file mode 100644
index 1a2ffb2010..0000000000
--- a/src/com/vaadin/event/DragDropDetailsImpl.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.vaadin.event;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.vaadin.terminal.gwt.server.DragAndDropService;
-import com.vaadin.ui.Component;
-
-public class DragDropDetailsImpl implements DragDropDetails {
-
- private HashMap<String, Object> data = new HashMap<String, Object>();
-
- public DragDropDetailsImpl(Map<String, Object> rawDropData) {
- data.putAll(rawDropData);
- }
-
- public Object get(String key) {
- return data.get(key);
- }
-
- public Object put(String key, Object value) {
- return data.put(key, value);
- }
-
- public Component getTarget() {
- return (Component) data.get(DragAndDropService.DROPTARGET_KEY);
- }
-}
diff --git a/src/com/vaadin/event/DragDropHandler.java b/src/com/vaadin/event/DragDropHandler.java
deleted file mode 100644
index 259dec8787..0000000000
--- a/src/com/vaadin/event/DragDropHandler.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.vaadin.event;
-
-public interface DragDropHandler extends DropHandler {
-
- public void handleDragRequest(DragRequest event, Transferable transferable,
- DragDropDetails dragDropDetails);
-
-}
diff --git a/src/com/vaadin/event/DragRequest.java b/src/com/vaadin/event/DragRequest.java
deleted file mode 100644
index 21c75926fc..0000000000
--- a/src/com/vaadin/event/DragRequest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.vaadin.event;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager.DragEventType;
-
-public class DragRequest {
-
- private DragEventType dragEventType;
- private Map<String, Object> responseData;
-
- public DragRequest(DragEventType dragEventType) {
- this.dragEventType = dragEventType;
- }
-
- public DragEventType getType() {
- return dragEventType;
- }
-
- public Map<String, Object> getResponseData() {
- return responseData;
- }
-
- /**
- * DropHanler can pass simple parameters back to client side.
- *
- * TODO define which types are supported (most likely the same as in UIDL)
- *
- * @param key
- * @param value
- */
- public void setResponseParameter(String key, Object value) {
- if (responseData == null) {
- responseData = new HashMap<String, Object>();
- }
- responseData.put(key, value);
- }
-
-}
diff --git a/src/com/vaadin/event/DropHandler.java b/src/com/vaadin/event/DropHandler.java
deleted file mode 100644
index f5ee8bc2d7..0000000000
--- a/src/com/vaadin/event/DropHandler.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.vaadin.event;
-
-public interface DropHandler {
-
- public boolean drop(Transferable transferable, DragDropDetails dropDetails);
-
-} \ No newline at end of file
diff --git a/src/com/vaadin/event/DropTarget.java b/src/com/vaadin/event/DropTarget.java
deleted file mode 100644
index 8519774cb6..0000000000
--- a/src/com/vaadin/event/DropTarget.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.vaadin.event;
-
-import com.vaadin.ui.Component;
-
-/**
- * DropTarget is a marker interface for components supporting drop operations. A
- * component that wants to receive drop events should implement this interface
- * and provide a DropHandler which will handle the actual drop event.
- *
- */
-public interface DropTarget extends Component {
-
- public DropHandler getDropHandler();
-
-} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/DragAndDropEvent.java b/src/com/vaadin/event/dd/DragAndDropEvent.java
new file mode 100644
index 0000000000..126edb15d8
--- /dev/null
+++ b/src/com/vaadin/event/dd/DragAndDropEvent.java
@@ -0,0 +1,24 @@
+package com.vaadin.event.dd;
+
+import java.io.Serializable;
+
+import com.vaadin.event.Transferable;
+
+public abstract class DragAndDropEvent implements Serializable {
+ private static final long serialVersionUID = -2232591107911385564L;
+ private Transferable transferable;
+ private TargetDetails dropDetails;
+
+ public DragAndDropEvent(Transferable tr, TargetDetails details) {
+ transferable = tr;
+ dropDetails = details;
+ }
+
+ public Transferable getTransferable() {
+ return transferable;
+ }
+
+ public TargetDetails getDropTargetData() {
+ return dropDetails;
+ }
+}
diff --git a/src/com/vaadin/event/dd/DragEvent.java b/src/com/vaadin/event/dd/DragEvent.java
new file mode 100644
index 0000000000..951f850dc7
--- /dev/null
+++ b/src/com/vaadin/event/dd/DragEvent.java
@@ -0,0 +1,34 @@
+package com.vaadin.event.dd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.vaadin.event.Transferable;
+
+public class DragEvent extends DragAndDropEvent {
+
+ private HashMap<String, Object> responseData;
+
+ public DragEvent(Transferable tr, TargetDetails details) {
+ super(tr, details);
+ }
+
+ private static final long serialVersionUID = 7105802828455781246L;
+
+ public void setResponseData(String key, Object value) {
+ if (responseData != null) {
+ responseData = new HashMap<String, Object>();
+ }
+ responseData.put(key, value);
+ }
+
+ /**
+ * non-api, used by terminal
+ *
+ * @return
+ */
+ public Map<String, Object> getResponseData() {
+ return responseData;
+ }
+
+}
diff --git a/src/com/vaadin/terminal/DragSource.java b/src/com/vaadin/event/dd/DragSource.java
index ece7a79e0c..9d901f0d41 100644
--- a/src/com/vaadin/terminal/DragSource.java
+++ b/src/com/vaadin/event/dd/DragSource.java
@@ -1,4 +1,4 @@
-package com.vaadin.terminal;
+package com.vaadin.event.dd;
import java.util.Map;
@@ -27,4 +27,4 @@ public interface DragSource {
public Transferable getTransferable(Transferable transferable,
Map<String, Object> rawVariables);
-}
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/DropEvent.java b/src/com/vaadin/event/dd/DropEvent.java
new file mode 100644
index 0000000000..546da317f6
--- /dev/null
+++ b/src/com/vaadin/event/dd/DropEvent.java
@@ -0,0 +1,10 @@
+package com.vaadin.event.dd;
+
+import com.vaadin.event.Transferable;
+
+public class DropEvent extends DragAndDropEvent {
+
+ public DropEvent(Transferable tr, TargetDetails details) {
+ super(tr, details);
+ }
+}
diff --git a/src/com/vaadin/event/dd/DropHandler.java b/src/com/vaadin/event/dd/DropHandler.java
new file mode 100644
index 0000000000..2bb03aa7b0
--- /dev/null
+++ b/src/com/vaadin/event/dd/DropHandler.java
@@ -0,0 +1,23 @@
+package com.vaadin.event.dd;
+
+import com.vaadin.event.dd.acceptCriteria.AcceptAll;
+import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
+
+public interface DropHandler {
+
+ public void drop(DropEvent dropEvent);
+
+ /**
+ * Returns the {@link AcceptCriterion} used to evaluate whether the
+ * {@link Transferable} will be handed over to {@link DropHandler}. If
+ * client side can't verify the {@link AcceptCriterion}, the same criteria
+ * may be tested also prior to actual drop - during the drag operation.
+ * <p>
+ * If everything is accepted developer can return {@link AcceptAll}
+ * instance.
+ *
+ * @return the {@link AcceptCriterion}
+ */
+ public AcceptCriterion getAcceptCriterion();
+
+}
diff --git a/src/com/vaadin/event/dd/DropTarget.java b/src/com/vaadin/event/dd/DropTarget.java
new file mode 100644
index 0000000000..9b24d7d2f5
--- /dev/null
+++ b/src/com/vaadin/event/dd/DropTarget.java
@@ -0,0 +1,34 @@
+package com.vaadin.event.dd;
+
+import java.util.Map;
+
+import com.vaadin.ui.Component;
+
+/**
+ * DropTarget is a marker interface for components supporting drop operations. A
+ * component that wants to receive drop events should implement this interface
+ * and provide a DropHandler which will handle the actual drop event.
+ *
+ */
+public interface DropTarget extends Component {
+
+ public DropHandler getDropHandler();
+
+ /**
+ * Called before a drop operation to translate the drop data provided by the
+ * client widget. Should return a DropData implementation with the new
+ * values. If null is returned the terminal implementation will
+ * automatically create a {@link TargetDetails} with all the client
+ * variables.
+ * <p>
+ * If this method returns null the data from client side will be passed
+ * through as-is without conversion.
+ *
+ * @param rawVariables
+ * Parameters passed from the client side widget.
+ * @return A DropData object with the translated data or null.
+ */
+ public TargetDetails translateDragDropDetails(
+ Map<String, Object> clientVariables);
+
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/TargetDetails.java b/src/com/vaadin/event/dd/TargetDetails.java
new file mode 100644
index 0000000000..d3f488052b
--- /dev/null
+++ b/src/com/vaadin/event/dd/TargetDetails.java
@@ -0,0 +1,10 @@
+package com.vaadin.event.dd;
+
+public interface TargetDetails {
+ public Object getData(String key);
+
+ public Object setData(String key, Object value);
+
+ public DropTarget getTarget();
+
+}
diff --git a/src/com/vaadin/event/dd/TargetDetailsImpl.java b/src/com/vaadin/event/dd/TargetDetailsImpl.java
new file mode 100644
index 0000000000..be9fa5598f
--- /dev/null
+++ b/src/com/vaadin/event/dd/TargetDetailsImpl.java
@@ -0,0 +1,27 @@
+package com.vaadin.event.dd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.vaadin.terminal.gwt.server.DragAndDropService;
+
+public class TargetDetailsImpl implements TargetDetails {
+
+ private HashMap<String, Object> data = new HashMap<String, Object>();
+
+ public TargetDetailsImpl(Map<String, Object> rawDropData) {
+ data.putAll(rawDropData);
+ }
+
+ public Object getData(String key) {
+ return data.get(key);
+ }
+
+ public Object setData(String key, Object value) {
+ return data.put(key, value);
+ }
+
+ public DropTarget getTarget() {
+ return (DropTarget) data.get(DragAndDropService.DROPTARGET_KEY);
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/AcceptAll.java b/src/com/vaadin/event/dd/acceptCriteria/AcceptAll.java
new file mode 100644
index 0000000000..5efdd6b7bd
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/AcceptAll.java
@@ -0,0 +1,39 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public final class AcceptAll implements AcceptCriterion {
+
+ private static AcceptCriterion singleton = new AcceptAll();
+
+ private AcceptAll() {
+ }
+
+ public boolean isClientSideVerifiable() {
+ return true;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", "acceptAll");
+ target.endTag("-ac");
+ }
+
+ public static AcceptCriterion get() {
+ return singleton;
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ return true;
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/AcceptCriterion.java b/src/com/vaadin/event/dd/acceptCriteria/AcceptCriterion.java
new file mode 100644
index 0000000000..24b0d9f2b8
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/AcceptCriterion.java
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.Transferable;
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public interface AcceptCriterion {
+
+ /**
+ * Criterion that can be used create policy to accept/discard dragged
+ * content (presented by {@link Transferable}).
+ *
+ * May depend on state, like in OR or AND, so to be really
+ * ClientSideVerifiable needs to return true here (instead of just
+ * implementing marker interface).
+ */
+ public boolean isClientSideVerifiable();
+
+ public void paint(PaintTarget target) throws PaintException;
+
+ /**
+ * This needs to be implemented iff criterion does some lazy server side
+ * initialization. The UIDL painted in this method will be passed to client
+ * side drop handler implementation. Implementation can assume that
+ * {@link #accepts(DragAndDropEvent)} is called before this method.
+ *
+ * @param target
+ * @throws PaintException
+ */
+ public void paintResponse(PaintTarget target) throws PaintException;
+
+ /**
+ * Validates the data in event to be approriate for
+ * {@link DropHandler#drop(com.vaadin.event.dd.DropEvent)} method.
+ * <p>
+ * Note, that event if your criterion is matched on client side, it is a
+ * very good manner to validate the data on server side too.
+ *
+ * @param dragEvent
+ * @return
+ */
+ public boolean accepts(DragAndDropEvent dragEvent);
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/And.java b/src/com/vaadin/event/dd/acceptCriteria/And.java
new file mode 100644
index 0000000000..54e809b06f
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/And.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public class And implements AcceptCriterion {
+ private AcceptCriterion f1;
+ private AcceptCriterion f2;
+
+ public And(AcceptCriterion f1, AcceptCriterion f2) {
+ this.f1 = f1;
+ this.f2 = f2;
+ }
+
+ public boolean isClientSideVerifiable() {
+ boolean a1 = f1 instanceof AcceptCriterion ? (f1)
+ .isClientSideVerifiable() : false;
+ boolean a2 = f2 instanceof AcceptCriterion ? (f2)
+ .isClientSideVerifiable() : false;
+ return a1 && a2;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", "and");
+ (f1).paint(target);
+ (f2).paint(target);
+ target.endTag("-ac");
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ return f1.accepts(dragEvent) && f2.accepts(dragEvent);
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/ClientSideCriterion.java b/src/com/vaadin/event/dd/acceptCriteria/ClientSideCriterion.java
new file mode 100644
index 0000000000..b221fb69cd
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/ClientSideCriterion.java
@@ -0,0 +1,36 @@
+package com.vaadin.event.dd.acceptCriteria;
+
+import java.io.Serializable;
+
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public abstract class ClientSideCriterion implements Serializable,
+ AcceptCriterion {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public final boolean isClientSideVerifiable() {
+ return true;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", getIdentifier());
+ paintContent(target);
+ target.endTag("-ac");
+ }
+
+ public void paintContent(PaintTarget target) {
+ }
+
+ abstract protected String getIdentifier();
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // NOP, nothing to do as this is client side verified criterion
+ }
+
+}
diff --git a/src/com/vaadin/event/dd/acceptCriteria/ComponentFilter.java b/src/com/vaadin/event/dd/acceptCriteria/ComponentFilter.java
new file mode 100644
index 0000000000..3bfa267c70
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/ComponentFilter.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.ComponentTransferable;
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+import com.vaadin.ui.Component;
+
+public class ComponentFilter implements AcceptCriterion {
+ private Component component;
+
+ public ComponentFilter(Component component) {
+ this.component = component;
+ }
+
+ public boolean isClientSideVerifiable() {
+ return true;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", "component");
+ target.addAttribute("component", component);
+ target.endTag("-ac");
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ if (dragEvent.getTransferable() instanceof ComponentTransferable) {
+ return ((ComponentTransferable) dragEvent.getTransferable())
+ .getSourceComponent() == component;
+ } else {
+ return false;
+ }
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/IsDataBinded.java b/src/com/vaadin/event/dd/acceptCriteria/IsDataBinded.java
new file mode 100644
index 0000000000..f579ec97f0
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/IsDataBinded.java
@@ -0,0 +1,43 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.DataBindedTransferable;
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public final class IsDataBinded implements AcceptCriterion {
+ private static IsDataBinded singleton = new IsDataBinded();
+
+ private IsDataBinded() {
+ }
+
+ public boolean isClientSideVerifiable() {
+ return true;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", "needsItemId");
+ target.endTag("-ac");
+ }
+
+ public static IsDataBinded get() {
+ return singleton;
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ if (dragEvent.getTransferable() instanceof DataBindedTransferable) {
+ return ((DataBindedTransferable) dragEvent.getTransferable())
+ .getItemId() != null;
+ }
+ return false;
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/Not.java b/src/com/vaadin/event/dd/acceptCriteria/Not.java
new file mode 100644
index 0000000000..2408d6b6a3
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/Not.java
@@ -0,0 +1,36 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public class Not implements AcceptCriterion {
+ private AcceptCriterion acceptCriterion;
+
+ public Not(AcceptCriterion acceptCriterion) {
+ this.acceptCriterion = acceptCriterion;
+ }
+
+ public boolean isClientSideVerifiable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ return !acceptCriterion.accepts(dragEvent);
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/Or.java b/src/com/vaadin/event/dd/acceptCriteria/Or.java
new file mode 100644
index 0000000000..6537f86b30
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/Or.java
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public class Or implements AcceptCriterion {
+ private AcceptCriterion f1;
+ private AcceptCriterion f2;
+
+ Or(AcceptCriterion f1, AcceptCriterion f2) {
+ this.f1 = f1;
+ this.f2 = f2;
+ }
+
+ public boolean isClientSideVerifiable() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ return f1.accepts(dragEvent) || f2.accepts(dragEvent);
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/OverTreeNode.java b/src/com/vaadin/event/dd/acceptCriteria/OverTreeNode.java
new file mode 100644
index 0000000000..70965c6452
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/OverTreeNode.java
@@ -0,0 +1,39 @@
+/**
+ *
+ */
+package com.vaadin.event.dd.acceptCriteria;
+
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+import com.vaadin.ui.Tree.Location;
+import com.vaadin.ui.Tree.TreeDropDetails;
+
+public class OverTreeNode implements AcceptCriterion {
+
+ public boolean isClientSideVerifiable() {
+ return true;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", "overTreeNode");
+ target.endTag("-ac");
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ try {
+ TreeDropDetails eventDetails = (TreeDropDetails) dragEvent
+ .getDropTargetData();
+ return eventDetails.getDropLocation() == Location.MIDDLE;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ // TODO Auto-generated method stub
+
+ }
+
+} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/ServerSideCriterion.java b/src/com/vaadin/event/dd/acceptCriteria/ServerSideCriterion.java
new file mode 100644
index 0000000000..f9dcd61483
--- /dev/null
+++ b/src/com/vaadin/event/dd/acceptCriteria/ServerSideCriterion.java
@@ -0,0 +1,36 @@
+package com.vaadin.event.dd.acceptCriteria;
+
+import java.io.Serializable;
+
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+
+public abstract class ServerSideCriterion implements Serializable,
+ AcceptCriterion {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public final boolean isClientSideVerifiable() {
+ return false;
+ }
+
+ public void paint(PaintTarget target) throws PaintException {
+ target.startTag("-ac");
+ target.addAttribute("name", getIdentifier());
+ paintContent(target);
+ target.endTag("-ac");
+ }
+
+ public void paintContent(PaintTarget target) {
+ }
+
+ public void paintResponse(PaintTarget target) throws PaintException {
+ }
+
+ protected String getIdentifier() {
+ return "-ss";
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java b/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java
index aba4779679..937f2f6bed 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VDragDropPane.java
@@ -41,16 +41,19 @@ public class VDragDropPane extends VAbsoluteLayout implements Container,
.getEventTarget();
Paintable paintable = client.getPaintable((Element) eventTarget
.cast());
- VTransferable transferable = new VTransferable();
- transferable.setComponent(paintable);
- VDragEvent drag = VDragAndDropManager.get().startDrag(
- transferable, event.getNativeEvent(), true);
- drag.createDragImage(((Widget) paintable).getElement(), true);
- drag.getDropDetails().put(
- "mouseDown",
- new MouseEventDetails(event.getNativeEvent())
- .serialize());
- event.preventDefault(); // prevent text selection
+ if (paintable != null) {
+ VTransferable transferable = new VTransferable();
+ transferable.setComponent(paintable);
+ VDragEvent drag = VDragAndDropManager.get().startDrag(
+ transferable, event.getNativeEvent(), true);
+ drag.createDragImage(((Widget) paintable).getElement(),
+ true);
+ drag.getDropDetails().put(
+ "mouseDown",
+ new MouseEventDetails(event.getNativeEvent())
+ .serialize());
+ event.preventDefault(); // prevent text selection
+ }
}
}, MouseDownEvent.getType());
@@ -193,7 +196,7 @@ public class VDragDropPane extends VAbsoluteLayout implements Container,
if (!uidl.hasAttribute("cached")) {
int childCount = uidl.getChildCount();
UIDL childUIDL = uidl.getChildUIDL(childCount - 1);
- getDropHandler().updateRules(childUIDL);
+ getDropHandler().updateAcceptRules(childUIDL);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
index a9db71d83e..1eb2867a6b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
@@ -131,7 +131,7 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
if ("actions".equals(childUidl.getTag())) {
updateActionMap(childUidl);
continue;
- } else if ("dh".equals(childUidl.getTag())) {
+ } else if ("-ac".equals(childUidl.getTag())) {
updateDropHandler(childUidl);
continue;
}
@@ -206,8 +206,6 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
@Override
public void dragEnter(VDragEvent drag) {
- updateTreeRelatedDragData(drag);
- super.dragEnter(drag);
}
@Override
@@ -227,16 +225,20 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
.getCurrentGwtEvent());
boolean nodeHasChanged = (currentMouseOverKey != null && currentMouseOverKey != oldIdOver)
|| (oldIdOver != null);
- boolean detailHasChanded = !detail.equals(oldDetail);
+ boolean detailHasChanded = (detail != null && !detail
+ .equals(oldDetail))
+ || (detail == null && oldDetail != null);
if (nodeHasChanged || detailHasChanded) {
ApplicationConnection.getConsole().log(
"Change in Transferable " + currentMouseOverKey
+ " " + detail);
+ final String newKey = currentMouseOverKey;
validate(new VAcceptCallback() {
- public void accepted() {
- keyToNode.get(currentMouseOverKey).emphasis(
- detail);
+ public void accepted(VDragEvent event) {
+ if (newKey != null) {
+ keyToNode.get(newKey).emphasis(detail);
+ }
}
}, currentDrag);
if (oldIdOver != null
@@ -276,11 +278,14 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler {
};
}
- dropHandler.updateRules(childUidl);
+ dropHandler.updateAcceptRules(childUidl);
}
public String getDropDetail(NativeEvent event) {
TreeNode treeNode = keyToNode.get(currentMouseOverKey);
+ if (treeNode == null) {
+ return null;
+ }
// TODO no scroll support
int offsetHeight = treeNode.nodeCaptionDiv.getOffsetHeight();
int absoluteTop = treeNode.getAbsoluteTop();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAbstractDropHandler.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAbstractDropHandler.java
index 2fe69101d8..74e4d4ca98 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAbstractDropHandler.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAbstractDropHandler.java
@@ -1,33 +1,31 @@
package com.vaadin.terminal.gwt.client.ui.dd;
-import com.vaadin.event.AbstractDropHandler;
-import com.vaadin.event.DropTarget;
+import com.google.gwt.user.client.Command;
import com.vaadin.event.Transferable;
-import com.vaadin.event.AbstractDropHandler.AcceptCriterion;
+import com.vaadin.event.dd.DropTarget;
+import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
public abstract class VAbstractDropHandler implements VDropHandler {
- private boolean mustValidateOnServer = true;
private UIDL criterioUIDL;
+ private VAcceptCriteria acceptCriteria;
/**
* Implementor/user of {@link VAbstractDropHandler} must pass the UIDL
- * painted by {@link AbstractDropHandler} (the server side counterpart) to
- * this method. Practically the details about {@link AcceptCriterion} are
- * saved.
+ * painted by {@link AcceptCriterion} to this method. Practically the
+ * details about {@link AcceptCriterion} are saved.
*
* @param uidl
*/
- public void updateRules(UIDL uidl) {
- mustValidateOnServer = uidl.getBooleanAttribute("serverValidate");
- int childCount = uidl.getChildCount();
- for (int i = 0; i < childCount; i++) {
- UIDL childUIDL = uidl.getChildUIDL(i);
- if (childUIDL.getTag().equals("acceptCriterion")) {
- criterioUIDL = childUIDL;
- }
+ public void updateAcceptRules(UIDL uidl) {
+ criterioUIDL = uidl;
+ acceptCriteria = VAcceptCriterion.get(uidl.getStringAttribute("name"));
+ if (acceptCriteria == null) {
+ throw new IllegalArgumentException(
+ "No accept criteria found with given name "
+ + uidl.getStringAttribute("name"));
}
}
@@ -62,7 +60,8 @@ public abstract class VAbstractDropHandler implements VDropHandler {
*/
public void dragEnter(final VDragEvent drag) {
validate(new VAcceptCallback() {
- public void accepted() {
+
+ public void accepted(VDragEvent event) {
dragAccepted(drag);
}
}, drag);
@@ -79,44 +78,36 @@ public abstract class VAbstractDropHandler implements VDropHandler {
*/
abstract protected void dragAccepted(VDragEvent drag);
- protected void validate(VAcceptCallback cb, VDragEvent event) {
- if (mustValidateOnServer) {
- VDragAndDropManager.get().visitServer(cb);
- } else if (validateOnClient(event)) {
- cb.accepted();
- }
- }
-
- /**
- * Returns true if client side rules are met.
- *
- * @param drag
- * @return
- */
- protected boolean validateOnClient(VDragEvent drag) {
- if (criterioUIDL != null) {
- String criteriaName = criterioUIDL.getStringAttribute("name");
- VAcceptCriteria acceptCriteria = VAcceptCriterion.get(criteriaName);
- if (acceptCriteria != null) {
- // ApplicationConnection.getConsole().log(
- // "Criteria : " + acceptCriteria.getClass().getName());
- return acceptCriteria.accept(drag, criterioUIDL);
+ protected void validate(final VAcceptCallback cb, final VDragEvent event) {
+ Command checkCriteria = new Command() {
+ public void execute() {
+ acceptCriteria.accept(event, criterioUIDL, cb);
}
- }
- return false;
+ };
+
+ VDragAndDropManager.get().executeWhenReady(checkCriteria);
}
+ boolean validated = false;
+
/**
* The default implemmentation visits server if {@link AcceptCriterion}
* can't be verified on client or if {@link AcceptCriterion} are met on
* client.
*/
public boolean drop(VDragEvent drag) {
- if (mustValidateOnServer) {
+ if (acceptCriteria.needsServerSideCheck(drag, criterioUIDL)) {
return true;
} else {
- return validateOnClient(drag);
+ validated = false;
+ acceptCriteria.accept(drag, criterioUIDL, new VAcceptCallback() {
+ public void accepted(VDragEvent event) {
+ validated = true;
+ }
+ });
+ return validated;
}
+
}
/**
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCallback.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCallback.java
index 6c47604ea4..fbfcf0cf49 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCallback.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCallback.java
@@ -10,6 +10,6 @@ public interface VAcceptCallback {
* the drag and drop operation ends or the {@link VAbstractDropHandler} has
* changed before response arrives, the method is never called.
*/
- public void accepted();
+ public void accepted(VDragEvent event);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriteria.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriteria.java
index 70f163c6d7..99d43ab5ee 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriteria.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriteria.java
@@ -4,6 +4,17 @@ import com.vaadin.terminal.gwt.client.UIDL;
public interface VAcceptCriteria {
- public boolean accept(VDragEvent drag, UIDL configuration);
+ /**
+ * Checks if current drag event has valid drop target and target accepts the
+ * transferable. If drop target is valid, callback is used.
+ *
+ * @param drag
+ * @param configuration
+ * @param callback
+ */
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback);
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterion.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterion.java
index fe251df4e9..5134661603 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterion.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterion.java
@@ -1,24 +1,20 @@
package com.vaadin.terminal.gwt.client.ui.dd;
-import java.util.HashMap;
-import java.util.Map;
-
import com.google.gwt.core.client.GWT;
/**
* A class via all AcceptCriteria instances are fetched by an identifier.
*/
public class VAcceptCriterion {
- protected static Map<String, VAcceptCriteria> criterion = new HashMap<String, VAcceptCriteria>();
private static VAcceptCriterionImpl impl;
static {
impl = GWT.create(VAcceptCriterionImpl.class);
- impl.populateCriterionMap(criterion);
+ impl.init();
}
public static VAcceptCriteria get(String name) {
- return criterion.get(name);
+ return impl.get(name);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterionImpl.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterionImpl.java
index 7f93dfa149..de8f4f8326 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterionImpl.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptCriterionImpl.java
@@ -1,5 +1,7 @@
package com.vaadin.terminal.gwt.client.ui.dd;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
@@ -9,18 +11,25 @@ import com.vaadin.terminal.gwt.client.UIDL;
public class VAcceptCriterionImpl {
private final class OverTreeNode implements VAcceptCriteria {
- public boolean accept(VDragEvent drag, UIDL configuration) {
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
Boolean containsKey = (Boolean) drag.getDropDetails().get(
"itemIdOverIsNode");
if (containsKey != null && containsKey.booleanValue()) {
- return true;
+ callback.accepted(drag);
+ return;
}
+ return;
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
return false;
}
}
private final class ComponentCriteria implements VAcceptCriteria {
- public boolean accept(VDragEvent drag, UIDL configuration) {
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
try {
Paintable component = drag.getTransferable().getComponent();
String requiredPid = configuration
@@ -28,44 +37,161 @@ public class VAcceptCriterionImpl {
Paintable paintable = VDragAndDropManager.get()
.getCurrentDropHandler().getApplicationConnection()
.getPaintable(requiredPid);
- return paintable == component;
+ if (paintable == component) {
+ callback.accepted(drag);
+ }
} catch (Exception e) {
}
+ return;
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
return false;
}
}
private final class And implements VAcceptCriteria {
- public boolean accept(VDragEvent drag, UIDL configuration) {
- UIDL childUIDL = configuration.getChildUIDL(0);
- UIDL childUIDL2 = configuration.getChildUIDL(1);
- VAcceptCriteria acceptCriteria = VAcceptCriterion.get(childUIDL
- .getStringAttribute("name"));
- VAcceptCriteria acceptCriteria2 = VAcceptCriterion.get(childUIDL2
- .getStringAttribute("name"));
- if (acceptCriteria == null || acceptCriteria2 == null) {
+ private boolean b1;
+ private boolean b2;
+
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
+
+ VAcceptCriteria crit1 = getCriteria(drag, configuration, 0);
+ VAcceptCriteria crit2 = getCriteria(drag, configuration, 1);
+ if (crit1 == null || crit2 == null) {
ApplicationConnection.getConsole().log(
"And criteria didn't found a chidl criteria");
- return false;
+ return;
}
- boolean accept = acceptCriteria.accept(drag, childUIDL);
- boolean accept2 = acceptCriteria2.accept(drag, childUIDL2);
- return accept && accept2;
+
+ b1 = false;
+ b2 = false;
+
+ VAcceptCallback accept1cb = new VAcceptCallback() {
+ public void accepted(VDragEvent event) {
+ b1 = true;
+ }
+ };
+ VAcceptCallback accept2cb = new VAcceptCallback() {
+ public void accepted(VDragEvent event) {
+ b2 = true;
+ }
+ };
+
+ crit1.accept(drag, configuration.getChildUIDL(0), accept1cb);
+ crit2.accept(drag, configuration.getChildUIDL(0), callback);
+ if (b1 && b2) {
+ callback.accepted(drag);
+ }
+ }
+
+ private VAcceptCriteria getCriteria(VDragEvent drag,
+ UIDL configuration, int i) {
+ UIDL childUIDL = configuration.getChildUIDL(i);
+ return VAcceptCriterion.get(childUIDL.getStringAttribute("name"));
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return false; // enforce on server side
+ // return getCriteria(drag, criterioUIDL, 0).needsServerSideCheck(
+ // drag, criterioUIDL.getChildUIDL(0))
+ // && getCriteria(drag, criterioUIDL, 1).needsServerSideCheck(
+ // drag, criterioUIDL.getChildUIDL(1));
}
}
private final class AcceptAll implements VAcceptCriteria {
- public boolean accept(VDragEvent drag, UIDL configuration) {
- return true;
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
+ callback.accepted(drag);
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return false;
}
}
private final class HasItemId implements VAcceptCriteria {
- public boolean accept(VDragEvent drag, UIDL configuration) {
- return drag.getTransferable().getData("itemId") != null;
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
+ if (drag.getTransferable().getData("itemId") != null) {
+ callback.accepted(drag);
+ }
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return false;
+ }
+ }
+
+ private final class ServerAccept implements VAcceptCriteria {
+ public void accept(final VDragEvent drag, UIDL configuration,
+ final VAcceptCallback callback) {
+
+ // TODO could easily cache the response for current drag event
+
+ VDragEventServerCallback acceptCallback = new VDragEventServerCallback() {
+ public void handleResponse(boolean accepted, UIDL response) {
+ if (accepted) {
+ callback.accepted(drag);
+ }
+ }
+ };
+ VDragAndDropManager.get().visitServer(acceptCallback);
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return true;
+ }
+ }
+
+ private final class LazyInitItemIdentifiers implements VAcceptCriteria {
+ private boolean loaded = false;
+ private HashSet<String> hashSet;
+ private VDragEvent lastDragEvent;
+
+ public void accept(final VDragEvent drag, UIDL configuration,
+ final VAcceptCallback callback) {
+ if (lastDragEvent == null || lastDragEvent != drag) {
+ loaded = false;
+ lastDragEvent = drag;
+ }
+ if (loaded) {
+ Object object = drag.getDropDetails().get("itemIdOver");
+ if (hashSet.contains(object)) {
+ callback.accepted(drag);
+ }
+ } else {
+
+ VDragEventServerCallback acceptCallback = new VDragEventServerCallback() {
+
+ public void handleResponse(boolean accepted, UIDL response) {
+ hashSet = new HashSet<String>();
+ String[] stringArrayAttribute = response
+ .getStringArrayAttribute("allowedIds");
+ for (int i = 0; i < stringArrayAttribute.length; i++) {
+ hashSet.add(stringArrayAttribute[i]);
+ }
+ loaded = true;
+ if (accepted) {
+ callback.accepted(drag);
+ }
+ }
+ };
+
+ VDragAndDropManager.get().visitServer(acceptCallback);
+ }
+
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return loaded;
}
}
+ private Map<String, VAcceptCriteria> instances = new HashMap<String, VAcceptCriteria>();
+
/**
* TODO this class/method must be written by generator
*
@@ -73,7 +199,7 @@ public class VAcceptCriterionImpl {
*
* TODO use fully qualified names of server side counterparts as keys
*/
- public void populateCriterionMap(Map<String, VAcceptCriteria> map) {
+ private void populateCriterionMap(Map<String, VAcceptCriteria> map) {
VAcceptCriteria crit;
crit = new HasItemId();
@@ -92,4 +218,20 @@ public class VAcceptCriterionImpl {
map.put("component", crit);
}
+
+ public void init() {
+ populateCriterionMap(instances);
+ }
+
+ public VAcceptCriteria get(String name) {
+ // FIXME make all lazy inited and possibility to use instances per
+ // handler
+ if (name.equals("-ss")) {
+ return new ServerAccept();
+ } else if (name.equals("com.vaadin.ui.Tree.TreeDropCriterion")) {
+ return new LazyInitItemIdentifiers();
+ } else {
+ return instances.get(name);
+ }
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java
index 6382147634..027a03eeda 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java
@@ -1,5 +1,7 @@
package com.vaadin.terminal.gwt.client.ui.dd;
+import java.util.LinkedList;
+
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Node;
@@ -19,6 +21,7 @@ import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.Paintable;
+import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ValueMap;
@@ -83,7 +86,7 @@ public class VDragAndDropManager {
// dragleave on old
if (currentDropHandler != null) {
currentDropHandler.dragLeave(currentDrag);
- acceptCallback = null;
+ serverCallback = null;
}
// dragenter on new
currentDropHandler = findDragTarget;
@@ -115,7 +118,7 @@ public class VDragAndDropManager {
} catch (Exception e) {
ApplicationConnection.getConsole().log(
"FIXME : ERROR in elementFromPoint hack.");
- e.printStackTrace();
+ throw new RuntimeException(e);
} finally {
dragElement.getStyle().setProperty("display", display);
}
@@ -157,7 +160,7 @@ public class VDragAndDropManager {
&& currentDropHandler != newDragHanler) {
currentDropHandler.dragLeave(currentDrag);
currentDropHandler = null;
- acceptCallback = null;
+ serverCallback = null;
}
break;
case Event.ONMOUSEMOVE:
@@ -210,7 +213,7 @@ public class VDragAndDropManager {
this.currentDropHandler = currentDropHandler;
}
- private VAcceptCallback acceptCallback;
+ private VDragEventServerCallback serverCallback;
private HandlerRegistration deferredStartRegistration;
@@ -457,7 +460,7 @@ public class VDragAndDropManager {
doRequest(DragEventType.DROP);
}
currentDropHandler = null;
- acceptCallback = null;
+ serverCallback = null;
}
@@ -484,9 +487,9 @@ public class VDragAndDropManager {
*
* @param acceptCallback
*/
- public void visitServer(VAcceptCallback acceptCallback) {
+ public void visitServer(VDragEventServerCallback acceptCallback) {
doRequest(DragEventType.ENTER);
- this.acceptCallback = acceptCallback;
+ serverCallback = acceptCallback;
}
private void doRequest(DragEventType drop) {
@@ -539,15 +542,27 @@ public class VDragAndDropManager {
}
public void handleServerResponse(ValueMap valueMap) {
- if (acceptCallback == null) {
+ if (serverCallback == null) {
return;
}
- int visitId = valueMap.getInt("visitId");
+ UIDL uidl = (UIDL) valueMap.cast();
+ int visitId = uidl.getIntAttribute("visitId");
+
if (this.visitId == visitId) {
- if (valueMap.containsKey("accepted")) {
- acceptCallback.accepted();
+ serverCallback.handleResponse(uidl.getBooleanAttribute("accepted"),
+ uidl);
+ serverCallback = null;
+ }
+ runDeferredCommands();
+ }
+
+ private void runDeferredCommands() {
+ if (deferredCommands != null && !deferredCommands.isEmpty()) {
+ Command command = deferredCommands.poll();
+ command.execute();
+ if (!isBusy()) {
+ runDeferredCommands();
}
- acceptCallback = null;
}
}
@@ -591,4 +606,39 @@ public class VDragAndDropManager {
}
};
+ private LinkedList<Command> deferredCommands;
+
+ private boolean isBusy() {
+ return serverCallback != null;
+ }
+
+ /**
+ * Method to que tasks until all dd related server visits are done
+ *
+ * @param command
+ */
+ private void defer(Command command) {
+ if (deferredCommands == null) {
+ deferredCommands = new LinkedList<Command>();
+ }
+ deferredCommands.add(command);
+ }
+
+ /**
+ * Method to execute commands when all existing dd related tasks are
+ * completed (some may require server visit).
+ * <p>
+ * Using this method may be handy if criterion that uses lazy initialization
+ * are used. Check
+ *
+ * @param command
+ */
+ public void executeWhenReady(Command command) {
+ if (isBusy()) {
+ defer(command);
+ } else {
+ command.execute();
+ }
+ }
+
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragEventServerCallback.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragEventServerCallback.java
new file mode 100644
index 0000000000..d1265febe5
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragEventServerCallback.java
@@ -0,0 +1,9 @@
+package com.vaadin.terminal.gwt.client.ui.dd;
+
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public interface VDragEventServerCallback {
+
+ public void handleResponse(boolean accepted, UIDL response);
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VTransferable.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VTransferable.java
index 2654f9a013..e2ef58cc2d 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VTransferable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VTransferable.java
@@ -4,7 +4,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import com.vaadin.terminal.DragSource;
+import com.vaadin.event.dd.DragSource;
import com.vaadin.terminal.gwt.client.Paintable;
/**
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index d6fa230f3c..67b806f0f0 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -4,32 +4,6 @@
package com.vaadin.terminal.gwt.server;
-import com.vaadin.Application;
-import com.vaadin.Application.SystemMessages;
-import com.vaadin.external.org.apache.commons.fileupload.FileItemIterator;
-import com.vaadin.external.org.apache.commons.fileupload.FileItemStream;
-import com.vaadin.external.org.apache.commons.fileupload.FileUpload;
-import com.vaadin.external.org.apache.commons.fileupload.FileUploadException;
-import com.vaadin.external.org.apache.commons.fileupload.ProgressListener;
-import com.vaadin.terminal.ApplicationResource;
-import com.vaadin.terminal.DownloadStream;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.Paintable;
-import com.vaadin.terminal.URIHandler;
-import com.vaadin.terminal.UploadStream;
-import com.vaadin.terminal.VariableOwner;
-import com.vaadin.terminal.Paintable.RepaintRequestEvent;
-import com.vaadin.terminal.Terminal.ErrorEvent;
-import com.vaadin.terminal.Terminal.ErrorListener;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout;
-import com.vaadin.ui.AbstractField;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.Upload;
-import com.vaadin.ui.Window;
-import com.vaadin.ui.Upload.UploadException;
-
import java.io.BufferedWriter;
import java.io.CharArrayWriter;
import java.io.IOException;
@@ -66,6 +40,32 @@ import javax.portlet.PortletResponse;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
+import com.vaadin.Application;
+import com.vaadin.Application.SystemMessages;
+import com.vaadin.external.org.apache.commons.fileupload.FileItemIterator;
+import com.vaadin.external.org.apache.commons.fileupload.FileItemStream;
+import com.vaadin.external.org.apache.commons.fileupload.FileUpload;
+import com.vaadin.external.org.apache.commons.fileupload.FileUploadException;
+import com.vaadin.external.org.apache.commons.fileupload.ProgressListener;
+import com.vaadin.terminal.ApplicationResource;
+import com.vaadin.terminal.DownloadStream;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.Paintable;
+import com.vaadin.terminal.URIHandler;
+import com.vaadin.terminal.UploadStream;
+import com.vaadin.terminal.VariableOwner;
+import com.vaadin.terminal.Paintable.RepaintRequestEvent;
+import com.vaadin.terminal.Terminal.ErrorEvent;
+import com.vaadin.terminal.Terminal.ErrorListener;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.server.ComponentSizeValidator.InvalidLayout;
+import com.vaadin.ui.AbstractField;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Upload;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Upload.UploadException;
+
/**
* This is a common base class for the server-side implementations of the
* communication system between the client code (compiled with GWT into
@@ -1132,7 +1132,7 @@ public abstract class AbstractCommunicationManager implements
private VariableOwner getDragAndDropService() {
if (dragAndDropService == null) {
- dragAndDropService = new DragAndDropService();
+ dragAndDropService = new DragAndDropService(this);
}
return dragAndDropService;
}
diff --git a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
index a573fc3272..5a318f071c 100644
--- a/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
+++ b/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
@@ -6,15 +6,16 @@ import java.util.HashMap;
import java.util.Map;
import com.vaadin.event.ComponentTransferable;
-import com.vaadin.event.DragDropDataTranslator;
-import com.vaadin.event.DragDropDetails;
-import com.vaadin.event.DragDropDetailsImpl;
-import com.vaadin.event.DragDropHandler;
-import com.vaadin.event.DragRequest;
-import com.vaadin.event.DropHandler;
-import com.vaadin.event.DropTarget;
import com.vaadin.event.Transferable;
-import com.vaadin.terminal.DragSource;
+import com.vaadin.event.dd.DragEvent;
+import com.vaadin.event.dd.DragSource;
+import com.vaadin.event.dd.DropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.DropTarget;
+import com.vaadin.event.dd.TargetDetails;
+import com.vaadin.event.dd.TargetDetailsImpl;
+import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
+import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.VariableOwner;
import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager.DragEventType;
import com.vaadin.ui.Component;
@@ -27,12 +28,22 @@ public class DragAndDropService implements VariableOwner {
private int lastVisitId;
- private DragRequest currentRequest;
-
private int currentEventId;
private Transferable transferable;
+ private boolean lastVisitAccepted = false;
+
+ private DragEvent dragEvent;
+
+ private final AbstractCommunicationManager manager;
+
+ private AcceptCriterion acceptCriterion;
+
+ public DragAndDropService(AbstractCommunicationManager manager) {
+ this.manager = manager;
+ }
+
public void changeVariables(Object source, Map<String, Object> variables) {
Object owner = variables.get("dhowner");
@@ -50,7 +61,8 @@ public class DragAndDropService implements VariableOwner {
DropTarget dropTarget = (DropTarget) owner;
lastVisitId = (Integer) variables.get("visitId");
- // Is this a drop request or a drag/move request?
+ // request may be dropRequest or request during drag operation (commonly
+ // dragover or dragenter)
boolean dropRequest = isDropRequest(variables);
if (dropRequest) {
handleDropRequest(dropTarget, variables);
@@ -83,10 +95,11 @@ public class DragAndDropService implements VariableOwner {
* source for Transferable, drop target for DragDropDetails).
*/
Transferable transferable = constructTransferable(dropTarget, variables);
- DragDropDetails dropData = constructDragDropDetails(dropTarget,
- variables);
-
- dropHandler.drop(transferable, dropData);
+ TargetDetails dropData = constructDragDropDetails(dropTarget, variables);
+ DropEvent dropEvent = new DropEvent(transferable, dropData);
+ if (dropHandler.getAcceptCriterion().accepts(dropEvent)) {
+ dropHandler.drop(dropEvent);
+ }
}
/**
@@ -99,34 +112,20 @@ public class DragAndDropService implements VariableOwner {
Map<String, Object> variables) {
lastVisitId = (Integer) variables.get("visitId");
- DropHandler dropHandler = (dropTarget).getDropHandler();
- if (!(dropHandler instanceof DragDropHandler)) {
- System.err
- .println("DragRequest could not be send to handler as DropHandle does not implement DragDropHandler");
- return;
- }
+ acceptCriterion = dropTarget.getDropHandler().getAcceptCriterion();
- DragDropHandler dragDropHandler = (DragDropHandler) dropHandler;
/*
* Construct the Transferable and the DragDropDetails for the drag
* operation based on the info passed from the client widgets (drag
* source for Transferable, current target for DragDropDetails).
*/
Transferable transferable = constructTransferable(dropTarget, variables);
- DragDropDetails dragDropDetails = constructDragDropDetails(dropTarget,
+ TargetDetails dragDropDetails = constructDragDropDetails(dropTarget,
variables);
- currentRequest = constructDragRequest(variables, transferable);
- dragDropHandler.handleDragRequest(currentRequest, transferable,
- dragDropDetails);
- }
-
- private static DragRequest constructDragRequest(
- Map<String, Object> variables, Transferable transferable) {
+ dragEvent = new DragEvent(transferable, dragDropDetails);
- int type = (Integer) variables.get("type");
- DragRequest dragRequest = new DragRequest(DragEventType.values()[type]);
- return dragRequest;
+ lastVisitAccepted = acceptCriterion.accepts(dragEvent);
}
/**
@@ -139,23 +138,20 @@ public class DragAndDropService implements VariableOwner {
* @return
*/
@SuppressWarnings("unchecked")
- private DragDropDetails constructDragDropDetails(DropTarget dropTarget,
+ private TargetDetails constructDragDropDetails(DropTarget dropTarget,
Map<String, Object> variables) {
Map<String, Object> rawDragDropDetails = (Map<String, Object>) variables
.get("evt");
- DragDropDetails dropData = null;
- if (dropTarget instanceof DragDropDataTranslator) {
- dropData = ((DragDropDataTranslator) dropTarget)
- .translateDragDropDetails(rawDragDropDetails);
- }
+ TargetDetails dropData = dropTarget
+ .translateDragDropDetails(rawDragDropDetails);
if (dropData == null) {
// Create a default DragDropDetails with all the raw variables
- dropData = new DragDropDetailsImpl(rawDragDropDetails);
+ dropData = new TargetDetailsImpl(rawDragDropDetails);
}
- dropData.put(DROPTARGET_KEY, dropTarget);
+ dropData.setData(DROPTARGET_KEY, dropTarget);
return dropData;
}
@@ -249,30 +245,30 @@ public class DragAndDropService implements VariableOwner {
return true;
}
- void printJSONResponse(PrintWriter outWriter) {
+ void printJSONResponse(PrintWriter outWriter) throws PaintException {
if (isDirty()) {
- // TODO paint responsedata
- outWriter.print(", dd : {");
- outWriter.print("visitId:");
- outWriter.print(lastVisitId);
- Map<String, Object> responseData = currentRequest.getResponseData();
- if (responseData != null) {
- for (String key : responseData.keySet()) {
- Object object = responseData.get(key);
- outWriter.print(",\"");
- // TODO JSON escaping for key and object
- outWriter.print(key);
- outWriter.print("\":");
- outWriter.print(object);
- }
+
+ outWriter.print(", \"dd\":");
+
+ JsonPaintTarget jsonPaintTarget = new JsonPaintTarget(manager,
+ outWriter, false);
+ jsonPaintTarget.startTag("dd");
+ jsonPaintTarget.addAttribute("visitId", lastVisitId);
+ if (acceptCriterion != null) {
+ jsonPaintTarget.addAttribute("accepted", lastVisitAccepted);
+ acceptCriterion.paintResponse(jsonPaintTarget);
}
- outWriter.print("}");
- currentRequest = null;
+ jsonPaintTarget.endTag("dd");
+ jsonPaintTarget.close();
+ lastVisitId = -1;
+ lastVisitAccepted = false;
+ acceptCriterion = null;
+ dragEvent = null;
}
}
private boolean isDirty() {
- if (currentRequest != null) {
+ if (lastVisitId > 0) {
return true;
}
return false;
diff --git a/src/com/vaadin/ui/DragDropPane.java b/src/com/vaadin/ui/DragDropPane.java
index 070f7a5c8f..ec8443e237 100644
--- a/src/com/vaadin/ui/DragDropPane.java
+++ b/src/com/vaadin/ui/DragDropPane.java
@@ -2,14 +2,16 @@ package com.vaadin.ui;
import java.util.Map;
-import com.vaadin.event.AbstractDropHandler;
import com.vaadin.event.ComponentTransferable;
import com.vaadin.event.DataBindedTransferable;
-import com.vaadin.event.DragDropDataTranslator;
-import com.vaadin.event.DragDropDetails;
-import com.vaadin.event.DragDropDetailsImpl;
-import com.vaadin.event.DropTarget;
import com.vaadin.event.Transferable;
+import com.vaadin.event.dd.DropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.DropTarget;
+import com.vaadin.event.dd.TargetDetails;
+import com.vaadin.event.dd.TargetDetailsImpl;
+import com.vaadin.event.dd.acceptCriteria.AcceptAll;
+import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
@@ -37,159 +39,158 @@ import com.vaadin.terminal.gwt.client.MouseEventDetails;
*/
@SuppressWarnings("serial")
@ClientWidget(com.vaadin.terminal.gwt.client.ui.VDragDropPane.class)
-public class DragDropPane extends AbsoluteLayout implements DropTarget,
- DragDropDataTranslator {
+public class DragDropPane extends AbsoluteLayout implements DropTarget {
- private AbstractDropHandler abstractDropHandler;
+ private DropHandler dropHandler;
- public DragDropPane(AbstractDropHandler dropHandler) {
+ public DragDropPane(DropHandler dropHandler) {
setWidth("400px");
setHeight("300px");
if (dropHandler == null) {
- dropHandler = new AbstractDropHandler() {
- @Override
- public void receive(Transferable transferable,
- DragDropDetails dropDetails) {
-
- DragEventDetails ed = (DragEventDetails) dropDetails;
- if (transferable instanceof ComponentTransferable) {
- ComponentTransferable ctr = (ComponentTransferable) transferable;
- Component component = ctr.getSourceComponent();
-
- if (component.getParent() != DragDropPane.this) {
- if (transferable instanceof DataBindedTransferable) {
- // Item has been dragged, construct a Label from
- // Item id
- Label l = new Label();
- l.setSizeUndefined();
- l
- .setValue("ItemId : "
- + ((DataBindedTransferable) transferable)
- .getItemId());
- DragDropPane.this.addComponent(l);
- component = l;
-
- } else {
- // we have a component that is been dragged, add
- // it
- // to
- // this
- DragDropPane.this.addComponent(component);
- }
-
- Integer left = ed.getAbsoluteLeft();
- Integer top = ed.getAbsoluteTop();
-
- MouseEventDetails eventDetails = ed.getMouseEvent();
-
- int clientX = eventDetails.getClientX();
- int clientY = eventDetails.getClientY();
-
- try {
- DragDropPane.this.getPosition(component)
- .setTopValue(clientY - top);
- DragDropPane.this.getPosition(component)
- .setLeftValue(clientX - left);
- } catch (Exception e) {
- // TODO: handle exception
- }
- } else {
- // drag ended inside the this Pane
-
- MouseEventDetails start = ed.getMouseDownEvent();
- MouseEventDetails eventDetails = ed.getMouseEvent();
-
- int deltaX = eventDetails.getClientX()
- - start.getClientX();
- int deltaY = eventDetails.getClientY()
- - start.getClientY();
-
- ComponentPosition p = DragDropPane.this
- .getPosition(component);
- p.setTopValue(p.getTopValue() + deltaY);
- p.setLeftValue(p.getLeftValue() + deltaX);
-
- }
+ this.dropHandler = new ImportPrettyMuchAnything();
+ } else {
+ this.dropHandler = dropHandler;
+ }
- } else {
- // drag coming outside of Vaadin
- String object = (String) transferable
- .getData("text/plain");
+ }
+
+ public DragDropPane() {
+ this(null);
+ }
+
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ super.paintContent(target);
+ dropHandler.getAcceptCriterion().paint(target);
+ }
- String content = (String) transferable
- .getData("fileContents");
+ public DropHandler getDropHandler() {
+ return dropHandler;
+ }
+ public static class ImportPrettyMuchAnything implements DropHandler {
+ public void drop(DropEvent event) {
+ DragDropPane pane = (DragDropPane) event.getDropTargetData()
+ .getTarget();
+
+ DragEventDetails ed = (DragEventDetails) event.getDropTargetData();
+ Transferable transferable = event.getTransferable();
+ if (transferable instanceof ComponentTransferable) {
+ ComponentTransferable ctr = (ComponentTransferable) transferable;
+ Component component = ctr.getSourceComponent();
+
+ if (component.getParent() != pane) {
+ if (transferable instanceof DataBindedTransferable) {
+ // Item has been dragged, construct a Label from
+ // Item id
Label l = new Label();
- l.setCaption("Generated from HTML5 drag:");
- if (object != null) {
- l.setValue(object);
- } else {
- l.setValue("HTML5 dd");
- }
-
- l.setDescription(content);
l.setSizeUndefined();
+ l.setValue("ItemId : "
+ + ((DataBindedTransferable) transferable)
+ .getItemId());
+ pane.addComponent(l);
+ component = l;
+
+ } else {
+ // we have a component that is been dragged, add
+ // it
+ // to
+ // this
+ pane.addComponent(component);
+ }
+
+ Integer left = ed.getAbsoluteLeft();
+ Integer top = ed.getAbsoluteTop();
+
+ MouseEventDetails eventDetails = ed.getMouseEvent();
- DragDropPane.this.addComponent(l);
+ int clientX = eventDetails.getClientX();
+ int clientY = eventDetails.getClientY();
+ try {
+ pane.getPosition(component).setTopValue(clientY - top);
+ pane.getPosition(component)
+ .setLeftValue(clientX - left);
+ } catch (Exception e) {
+ // TODO: handle exception
}
+ } else {
+ // drag ended inside the this Pane
+
+ MouseEventDetails start = ed.getMouseDownEvent();
+ MouseEventDetails eventDetails = ed.getMouseEvent();
+
+ int deltaX = eventDetails.getClientX() - start.getClientX();
+ int deltaY = eventDetails.getClientY() - start.getClientY();
+
+ ComponentPosition p = pane.getPosition(component);
+ p.setTopValue(p.getTopValue() + deltaY);
+ p.setLeftValue(p.getLeftValue() + deltaX);
}
- };
- if (dropHandler instanceof AbstractDropHandler) {
- AbstractDropHandler new_name = dropHandler;
- new_name
- .setAcceptCriterion(AbstractDropHandler.CRITERION_ACCEPT_ALL);
- }
- }
- abstractDropHandler = dropHandler;
- }
- public DragDropPane() {
- this(null);
- }
+ } else {
+ // drag coming outside of Vaadin
+ String object = (String) transferable.getData("text/plain");
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
- super.paintContent(target);
- if (abstractDropHandler instanceof AbstractDropHandler) {
- AbstractDropHandler new_name = abstractDropHandler;
- new_name.paint(target);
+ String content = (String) transferable.getData("fileContents");
+
+ Label l = new Label();
+ l.setCaption("Generated from HTML5 drag:");
+ if (object != null) {
+ l.setValue(object);
+ } else {
+ l.setValue("HTML5 dd");
+ }
+
+ l.setDescription(content);
+ l.setSizeUndefined();
+
+ pane.addComponent(l);
+
+ }
+ return;
}
- }
- public AbstractDropHandler getDropHandler() {
- return abstractDropHandler;
+ public AcceptCriterion getAcceptCriterion() {
+ return AcceptAll.get();
+ }
}
- class DragEventDetails extends DragDropDetailsImpl {
+ class DragEventDetails extends TargetDetailsImpl {
public DragEventDetails(Map<String, Object> rawVariables) {
super(rawVariables);
}
public Integer getAbsoluteTop() {
- return (Integer) get("absoluteTop");
+ return (Integer) getData("absoluteTop");
}
public Integer getAbsoluteLeft() {
- return (Integer) get("absoluteLeft");
+ return (Integer) getData("absoluteLeft");
}
public MouseEventDetails getMouseDownEvent() {
- return MouseEventDetails.deSerialize((String) get("mouseDown"));
+ return MouseEventDetails.deSerialize((String) getData("mouseDown"));
}
public MouseEventDetails getMouseEvent() {
- return MouseEventDetails.deSerialize((String) get("mouseEvent"));
+ return MouseEventDetails
+ .deSerialize((String) getData("mouseEvent"));
}
}
- public DragDropDetails translateDragDropDetails(
+ public TargetDetails translateDragDropDetails(
Map<String, Object> clientVariables) {
return new DragEventDetails(clientVariables);
}
+ public void setDropHandler(DropHandler dropHandler2) {
+ dropHandler = dropHandler2;
+ requestRepaint();
+ }
+
}
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index 41cf86750f..0ef6950936 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -29,7 +29,7 @@ import com.vaadin.event.Transferable;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.event.ItemClickEvent.ItemClickSource;
-import com.vaadin.terminal.DragSource;
+import com.vaadin.event.dd.DragSource;
import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java
index 566d8ed4ea..c235405b36 100644
--- a/src/com/vaadin/ui/Tree.java
+++ b/src/com/vaadin/ui/Tree.java
@@ -22,18 +22,18 @@ import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.ContainerHierarchicalWrapper;
import com.vaadin.data.util.IndexedContainer;
-import com.vaadin.event.AbstractDropHandler;
import com.vaadin.event.Action;
import com.vaadin.event.DataBindedTransferable;
-import com.vaadin.event.DragDropDataTranslator;
-import com.vaadin.event.DragDropDetailsImpl;
-import com.vaadin.event.DropHandler;
-import com.vaadin.event.DropTarget;
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.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DragSource;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.DropTarget;
+import com.vaadin.event.dd.TargetDetailsImpl;
+import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion;
import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
@@ -53,8 +53,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, DragSource, DropTarget,
- DragDropDataTranslator {
+ Action.Container, ItemClickSource, DragSource, DropTarget {
private static final Method EXPAND_METHOD;
@@ -135,6 +134,9 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
}
public Object getData(String dataFlawor) {
+ if (dataFlawor.equals("Text")) {
+ return getItemCaption(getItemId());
+ }
return data.get(dataFlawor);
}
@@ -644,8 +646,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
// New items
target.addVariable(this, "newitem", new String[] {});
- if (dropHandler instanceof AbstractDropHandler) {
- ((AbstractDropHandler) dropHandler).paint(target);
+ if (dropHandler != null) {
+ dropHandler.getAcceptCriterion().paint(target);
}
}
@@ -1158,14 +1160,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
TOP, BOTTOM, MIDDLE
}
- public class TreeDropDetails extends DragDropDetailsImpl {
+ public class TreeDropDetails extends TargetDetailsImpl {
private Object idOver;
TreeDropDetails(Map<String, Object> rawVariables) {
super(rawVariables);
// eagar fetch itemid, mapper may be emptied
- String keyover = (String) get("itemIdOver");
+ String keyover = (String) getData("itemIdOver");
if (keyover != null) {
idOver = itemIdMapper.get(keyover);
}
@@ -1176,7 +1178,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
}
public Location getDropLocation() {
- String s = (String) get("detail");
+ String s = (String) getData("detail");
if ("Top".equals(s)) {
return Location.TOP;
} else if ("Bottom".equals(s)) {
@@ -1193,4 +1195,81 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
return new TreeDropDetails(clientVariables);
}
+ /**
+ * API for {@link TreeDropCriterion}
+ *
+ * @param itemId
+ * @return
+ */
+ private String key(Object itemId) {
+ return itemIdMapper.key(itemId);
+ }
+
+ /**
+ * An example of lazy initializing criterion. Initially pretty much no data
+ * is sent to client, on first accepts set (per drag request) the client
+ * side data structure is initialized and no subsequent requests requests
+ * are needed during that drag and drop operation.
+ * <p>
+ * See client side counterpart
+ */
+ public static abstract class TreeDropCriterion extends ServerSideCriterion {
+
+ private Tree tree;
+
+ private Set<Object> allowedItemIds;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.event.dd.acceptCriteria.ServerSideCriterion#getIdentifier
+ * ()
+ */
+ @Override
+ protected String getIdentifier() {
+ return TreeDropCriterion.class.getCanonicalName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.event.dd.acceptCriteria.AcceptCriterion#accepts(com.vaadin
+ * .event.dd.DragAndDropEvent)
+ */
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ TreeDropDetails dropTargetData = (TreeDropDetails) dragEvent
+ .getDropTargetData();
+ tree = (Tree) dragEvent.getDropTargetData().getTarget();
+ allowedItemIds = getAllowedItemIds(dragEvent, tree);
+ return allowedItemIds.contains(dropTargetData.getItemIdOver());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.event.dd.acceptCriteria.AcceptCriterion#paintResponse(
+ * com.vaadin.terminal.PaintTarget)
+ */
+ @Override
+ public void paintResponse(PaintTarget target) throws PaintException {
+ /*
+ * send allowed nodes to client so subsequent requests can be
+ * avoided
+ */
+ Object[] array = allowedItemIds.toArray();
+ for (int i = 0; i < array.length; i++) {
+ String key = tree.key(array[i]);
+ array[i] = key;
+ }
+ target.addAttribute("allowedIds", array);
+ }
+
+ protected abstract Set<Object> getAllowedItemIds(
+ DragAndDropEvent dragEvent, Tree tree);
+
+ }
+
}