diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-18 09:22:35 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-18 09:22:35 +0000 |
commit | 7588a1708218dc9a419a2c43a5efbbf627663338 (patch) | |
tree | be3c44482edb2009c260c4cd8ab200097a810b33 | |
parent | b8b6a3fa51cc78b5df2f6b7af459a589fcf81e5c (diff) | |
download | vaadin-framework-7588a1708218dc9a419a2c43a5efbbf627663338.tar.gz vaadin-framework-7588a1708218dc9a419a2c43a5efbbf627663338.zip |
DD related refactorings and javadocs
svn changeset:11952/svn branch:6.3
-rw-r--r-- | src/com/vaadin/event/dd/acceptCriteria/And.java | 13 | ||||
-rw-r--r-- | src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java | 23 | ||||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/dd/VDropDetailEquals.java | 18 | ||||
-rw-r--r-- | src/com/vaadin/ui/Tree.java | 37 |
4 files changed, 70 insertions, 21 deletions
diff --git a/src/com/vaadin/event/dd/acceptCriteria/And.java b/src/com/vaadin/event/dd/acceptCriteria/And.java index 52bf2f7c1d..4bab63386c 100644 --- a/src/com/vaadin/event/dd/acceptCriteria/And.java +++ b/src/com/vaadin/event/dd/acceptCriteria/And.java @@ -22,27 +22,28 @@ import com.vaadin.terminal.PaintTarget; @ClientCriterion(com.vaadin.terminal.gwt.client.ui.dd.VAnd.class) public class And extends ClientSideCriterion { - private ClientSideCriterion[] f1; + private static final long serialVersionUID = -5242574480825471748L; + protected ClientSideCriterion[] criteria; /** * - * @param f1 + * @param criteria * criteria of which the And criterion will be composed */ - public And(ClientSideCriterion... f1) { - this.f1 = f1; + public And(ClientSideCriterion... criteria) { + this.criteria = criteria; } @Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); - for (ClientSideCriterion crit : f1) { + for (ClientSideCriterion crit : criteria) { crit.paint(target); } } public boolean accepts(DragAndDropEvent dragEvent) { - for (ClientSideCriterion crit : f1) { + for (ClientSideCriterion crit : criteria) { if (!crit.accepts(dragEvent)) { return false; } diff --git a/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java b/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java index b97f0159bb..c18cbc8f7a 100644 --- a/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java +++ b/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java @@ -22,10 +22,11 @@ import com.vaadin.terminal.gwt.client.ui.dd.VDropDetailEquals; * */ @ClientCriterion(VDropDetailEquals.class) -public final class DropTargetDetailEquals extends ClientSideCriterion { +public class DropTargetDetailEquals extends ClientSideCriterion { + private static final long serialVersionUID = 763165450054331246L; private String propertyName; - private String value; + private Object value; /** * Constructs a criterion which ensures that the value there is a value in @@ -42,15 +43,31 @@ public final class DropTargetDetailEquals extends ClientSideCriterion { this.value = value; } + public DropTargetDetailEquals(String dataFlavor, Boolean true1) { + propertyName = dataFlavor; + value = true1; + } + @Override public void paintContent(PaintTarget target) throws PaintException { super.paintContent(target); target.addAttribute("p", propertyName); - target.addAttribute("v", value); + if (value instanceof Boolean) { + target.addAttribute("v", ((Boolean) value).booleanValue()); + target.addAttribute("t", "b"); + } else if (value instanceof String) { + target.addAttribute("v", (String) value); + } } public boolean accepts(DragAndDropEvent dragEvent) { Object data = dragEvent.getDropTargetDetails().getData(propertyName); return value.equals(data); } + + @Override + protected String getIdentifier() { + // sub classes by default use VDropDetailEquals a client implementation + return DropTargetDetailEquals.class.getCanonicalName(); + } }
\ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDropDetailEquals.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDropDetailEquals.java index fb8a64fcba..20efe854ce 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDropDetailEquals.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDropDetailEquals.java @@ -13,8 +13,20 @@ final public class VDropDetailEquals extends VAcceptCriterion { @Override public boolean validates(VDragEvent drag, UIDL configuration) { String name = configuration.getStringAttribute("p"); - String value = configuration.getStringAttribute("v"); - Object object = drag.getDropDetails().get(name); - return value.equals(object); + String t = configuration.hasAttribute("t") ? configuration + .getStringAttribute("t").intern() : "s"; + Object value = null; + if (t == "s") { + value = configuration.getStringAttribute("v"); + } else if (t == "b") { + value = configuration.getBooleanAttribute("v"); + } + if (value != null) { + Object object = drag.getDropDetails().get(name); + return value.equals(object); + } else { + return false; + } + } }
\ No newline at end of file diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 7ad0a159e7..018cc61985 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -35,6 +35,7 @@ import com.vaadin.event.dd.DropTarget; import com.vaadin.event.dd.DropTargetDetails; import com.vaadin.event.dd.acceptCriteria.ClientCriterion; import com.vaadin.event.dd.acceptCriteria.ClientSideCriterion; +import com.vaadin.event.dd.acceptCriteria.DropTargetDetailEquals; import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; import com.vaadin.terminal.KeyMapper; import com.vaadin.terminal.PaintException; @@ -43,7 +44,6 @@ import com.vaadin.terminal.Resource; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VTree; import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers; -import com.vaadin.terminal.gwt.client.ui.dd.VOverTreeNode; import com.vaadin.terminal.gwt.client.ui.dd.VTargetNodeIsChildOf; import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; import com.vaadin.tools.ReflectTools; @@ -1355,18 +1355,25 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } /** - * Accepts transferable only on tree Node (middle of the node + can has - * child) + * A criterion that accepts transferable only directly on a tree node that + * can have children. * - * TODO replace by composition of itemIdIs + drop property + * @see Tree#setChildrenAllowed(Object, boolean) * * @since 6.3 */ - @ClientCriterion(VOverTreeNode.class) - public static class OverFolderNode extends ClientSideCriterion { + public static class OverFolderNode extends DropTargetDetailEquals { private static final long serialVersionUID = 1L; + public OverFolderNode() { + super("itemIdOverIsNode", Boolean.TRUE); + } + + /* + * Uses enhanced server side check + */ + @Override public boolean accepts(DragAndDropEvent dragEvent) { try { // must be over tree node and in the middle of it (not top or @@ -1385,11 +1392,16 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, return false; } } + } /** - * Checks to parent (or parent hierarchy) for the item identifier given in - * constructor. If the parent is found, content is accepted. + * An accept criterion that checks the parent node (or parent hierarchy) for + * the item identifier given in constructor. If the parent is found, content + * is accepted. Criterion can be used to accepts drags on a select sub tree + * only. + * + * TODO consider renaming and starting traversing from "itemIdInto". */ @ClientCriterion(VTargetNodeIsChildOf.class) public class TargetNodeIsChildOf extends ClientSideCriterion { @@ -1398,16 +1410,22 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, private int depthToCheck = 1; /** + * Constructs a criteria that accepts the drag if the targeted item is a + * direct descendant of Item identified by given id * * @param parentItemId + * the item identifier of the parent node */ public TargetNodeIsChildOf(Object parentItemId) { this.parentItemId = parentItemId; } /** + * Constructs a criteria that accepts drops at any level below the item + * identified by given id * * @param parentItemId + * the item identifier to be sought for * @param depthToCheck * the depth that tree is traversed upwards to seek for the * parent, -1 means that the whole structure should be @@ -1429,7 +1447,8 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, Object itemIdOver = eventDetails.getItemIdOver(); Object parent2 = getParent(itemIdOver); int i = 0; - while (parent2 != null && i < depthToCheck) { + while (parent2 != null + && (depthToCheck == -1 || i < depthToCheck)) { if (parent2.equals(parentItemId)) { return true; } |