aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-02-18 11:44:57 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-02-18 11:44:57 +0000
commit27feab20edab094c1f003dffc6e99dd31dbf6199 (patch)
tree69298f30a3e58acc46982e2a2405aa0b6d5a8a99 /src/com/vaadin
parent4b388c9c48d00e117d857e13b66a070db228c8af (diff)
downloadvaadin-framework-27feab20edab094c1f003dffc6e99dd31dbf6199.tar.gz
vaadin-framework-27feab20edab094c1f003dffc6e99dd31dbf6199.zip
new criteria + enhancements
svn changeset:11376/svn branch:6.3_dd
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VIdentifierIs.java28
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java28
-rw-r--r--src/com/vaadin/ui/AbstractSelect.java105
-rw-r--r--src/com/vaadin/ui/Table.java44
-rw-r--r--src/com/vaadin/ui/Tree.java27
5 files changed, 165 insertions, 67 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VIdentifierIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VIdentifierIs.java
new file mode 100644
index 0000000000..ebe8a3e23a
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VIdentifierIs.java
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package com.vaadin.terminal.gwt.client.ui.dd;
+
+import java.util.Set;
+
+import com.vaadin.terminal.gwt.client.UIDL;
+
+final public class VIdentifierIs implements VAcceptCriteria {
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
+ try {
+ Object data = drag.getTransferable().getData("itemId");
+ Set<String> stringArrayVariableAsSet = configuration
+ .getStringArrayVariableAsSet("keys");
+ if (stringArrayVariableAsSet.contains(data)) {
+ callback.accepted(drag);
+ }
+ } catch (Exception e) {
+ }
+ return;
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java
new file mode 100644
index 0000000000..87b09307bf
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package com.vaadin.terminal.gwt.client.ui.dd;
+
+import java.util.Set;
+
+import com.vaadin.terminal.gwt.client.UIDL;
+
+final public class VIsOverId implements VAcceptCriteria {
+ public void accept(VDragEvent drag, UIDL configuration,
+ VAcceptCallback callback) {
+ try {
+ Set<String> stringArrayVariableAsSet = configuration
+ .getStringArrayVariableAsSet("keys");
+ if (stringArrayVariableAsSet.contains(drag.getDropDetails().get(
+ "itemIdOver"))) {
+ callback.accepted(drag);
+ }
+ } catch (Exception e) {
+ }
+ return;
+ }
+
+ public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java
index 088bd5bd0b..cdaf2715e2 100644
--- a/src/com/vaadin/ui/AbstractSelect.java
+++ b/src/com/vaadin/ui/AbstractSelect.java
@@ -19,10 +19,19 @@ import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.event.DataBoundTransferable;
+import com.vaadin.event.Transferable;
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.TargetDetailsImpl;
+import com.vaadin.event.dd.acceptCriteria.ClientCriterion;
+import com.vaadin.event.dd.acceptCriteria.ClientSideCriterion;
import com.vaadin.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
+import com.vaadin.terminal.gwt.client.ui.dd.VIdentifierIs;
+import com.vaadin.terminal.gwt.client.ui.dd.VIsOverId;
+import com.vaadin.ui.Tree.Location;
/**
* <p>
@@ -1681,4 +1690,100 @@ public abstract class AbstractSelect extends AbstractField implements
}
+ /**
+ * Criterion for selects that support drop (Tree and Table). With this
+ * criterion drop is accepted on given identifier or set of identifiers.
+ */
+ @ClientCriterion(VIsOverId.class)
+ public static class IsOverId extends AbstractItemSetCriterion {
+
+ public IsOverId(AbstractSelect select, Object... itemId) {
+ super(select, itemId);
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ AbstractSelectDropDetails dropTargetData = (AbstractSelectDropDetails) dragEvent
+ .getDropTargetData();
+ return itemIds.contains(dropTargetData.getItemIdOver());
+ }
+
+ }
+
+ private static abstract class AbstractItemSetCriterion extends
+ ClientSideCriterion {
+ protected final Collection<Object> itemIds = new HashSet<Object>();
+ private AbstractSelect select;
+
+ public AbstractItemSetCriterion(AbstractSelect select, Object... itemId) {
+ if (itemIds == null || select == null) {
+ throw new IllegalArgumentException(
+ "Accepted item identifiers must be accepted.");
+ }
+ Collections.addAll(itemIds, itemId);
+ this.select = select;
+ }
+
+ @Override
+ public void paintContent(PaintTarget target) throws PaintException {
+ super.paintContent(target);
+ String[] keys = new String[itemIds.size()];
+ int i = 0;
+ for (Object itemId : itemIds) {
+ String key = select.itemIdMapper.key(itemId);
+ keys[i++] = key;
+ }
+ target.addVariable(select, "keys", keys);
+ }
+
+ }
+
+ /**
+ * Criterion for selects that support drop (Tree and Table). With this
+ * criterion drop is accepted only if {@link Transferable} (from this
+ * {@link AbstractSelect}) contains given item identifier or identifiers.
+ */
+ @ClientCriterion(VIdentifierIs.class)
+ public static class IdentifierIs extends AbstractItemSetCriterion {
+ public IdentifierIs(AbstractSelect select, Object... itemId) {
+ super(select, itemId);
+ }
+
+ public boolean accepts(DragAndDropEvent dragEvent) {
+ DataBoundTransferable transferable = (DataBoundTransferable) dragEvent
+ .getTransferable();
+ return itemIds.contains(transferable.getItemId());
+ }
+
+ }
+
+ public class AbstractSelectDropDetails extends TargetDetailsImpl {
+
+ private Object idOver;
+
+ AbstractSelectDropDetails(Map<String, Object> rawVariables) {
+ super(rawVariables);
+ // eagar fetch itemid, mapper may be emptied
+ String keyover = (String) getData("itemIdOver");
+ if (keyover != null) {
+ idOver = itemIdMapper.get(keyover);
+ }
+ }
+
+ public Object getItemIdOver() {
+ return idOver;
+ }
+
+ public Location getDropLocation() {
+ String s = (String) getData("detail");
+ if ("TOP".equals(s)) {
+ return Location.TOP;
+ } else if ("BOTTOM".equals(s)) {
+ return Location.BOTTOM;
+ } else {
+ return Location.MIDDLE;
+ }
+ }
+
+ }
+
}
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index fe28c1fed9..f6e01025d3 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -32,15 +32,12 @@ import com.vaadin.event.ItemClickEvent.ItemClickSource;
import com.vaadin.event.dd.DragSource;
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.terminal.KeyMapper;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.VScrollTable;
-import com.vaadin.ui.Tree.Location;
/**
* <p>
@@ -3388,45 +3385,8 @@ public class Table extends AbstractSelect implements Action.Container,
this.dropHandler = dropHandler;
}
- /*
- * TODO add propertyId
- */
- public class TableTargetDetails extends TargetDetailsImpl {
- private Object idOver;
-
- public TableTargetDetails(Map<String, Object> rawDropData) {
- super(rawDropData);
- // eagar fetch itemid, mapper may be emptied
- String keyover = (String) getData("itemIdOver");
- if (keyover != null) {
- idOver = itemIdMapper.get(keyover);
- }
- }
-
- public Object getItemIdOver() {
- return idOver;
- }
-
- public Location getDropLocation() {
- String s = (String) getData("detail");
- if ("TOP".equals(s)) {
- return Location.TOP;
- } else if ("BOTTOM".equals(s)) {
- return Location.BOTTOM;
- } else {
- return Location.MIDDLE;
- }
- }
-
- @Override
- public Table getTarget() {
- return (Table) super.getTarget();
- }
-
- }
-
- public TargetDetails translateDragDropDetails(
+ public AbstractSelectDropDetails translateDragDropDetails(
Map<String, Object> clientVariables) {
- return new TableTargetDetails(clientVariables);
+ return new AbstractSelectDropDetails(clientVariables);
}
}
diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java
index c4a1bff12d..02b486046f 100644
--- a/src/com/vaadin/ui/Tree.java
+++ b/src/com/vaadin/ui/Tree.java
@@ -32,7 +32,6 @@ 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.ClientCriterion;
import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion;
import com.vaadin.terminal.KeyMapper;
@@ -1162,32 +1161,10 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
TOP, BOTTOM, MIDDLE;
}
- public class TreeDropDetails extends TargetDetailsImpl {
-
- private Object idOver;
+ public class TreeDropDetails extends AbstractSelectDropDetails {
TreeDropDetails(Map<String, Object> rawVariables) {
super(rawVariables);
- // eagar fetch itemid, mapper may be emptied
- String keyover = (String) getData("itemIdOver");
- if (keyover != null) {
- idOver = itemIdMapper.get(keyover);
- }
- }
-
- public Object getItemIdOver() {
- return idOver;
- }
-
- public Location getDropLocation() {
- String s = (String) getData("detail");
- if ("TOP".equals(s)) {
- return Location.TOP;
- } else if ("BOTTOM".equals(s)) {
- return Location.BOTTOM;
- } else {
- return Location.MIDDLE;
- }
}
@Override
@@ -1247,7 +1224,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
* .event.dd.DragAndDropEvent)
*/
public boolean accepts(DragAndDropEvent dragEvent) {
- TreeDropDetails dropTargetData = (TreeDropDetails) dragEvent
+ AbstractSelectDropDetails dropTargetData = (AbstractSelectDropDetails) dragEvent
.getDropTargetData();
tree = (Tree) dragEvent.getDropTargetData().getTarget();
allowedItemIds = getAllowedItemIds(dragEvent, tree);