]> source.dussan.org Git - vaadin-framework.git/commitdiff
DD related javadocs, cleanup, small refactoring
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 17 Mar 2010 12:05:34 +0000 (12:05 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 17 Mar 2010 12:05:34 +0000 (12:05 +0000)
svn changeset:11929/svn branch:6.3

src/com/vaadin/event/dd/acceptCriteria/AcceptAll.java
src/com/vaadin/event/dd/acceptCriteria/And.java
src/com/vaadin/event/dd/acceptCriteria/ClientCriterion.java
src/com/vaadin/event/dd/acceptCriteria/ServerSideCriterion.java
src/com/vaadin/terminal/gwt/client/ui/dd/VAnd.java
src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java

index 1498d2b5aaa758f76d4a76bc4e4644eb2b26c096..942a85ee64062110176a2704a7f1ab6b315c30ed 100644 (file)
@@ -11,6 +11,9 @@ import com.vaadin.terminal.gwt.client.ui.dd.VAcceptAll;
 
 /**
  * Criterion that accepts all drops anywhere on the component.
+ * <p>
+ * Note! Class is singleton, use {@link #get()} method to get the instance.
+ * 
  * 
  * @since 6.3
  * 
@@ -18,6 +21,7 @@ import com.vaadin.terminal.gwt.client.ui.dd.VAcceptAll;
 @ClientCriterion(VAcceptAll.class)
 public final class AcceptAll extends ClientSideCriterion {
 
+    private static final long serialVersionUID = 7406683402153141461L;
     private static AcceptCriterion singleton = new AcceptAll();
 
     private AcceptAll() {
index 3ae2b84113fcc41d72a74ae8a4603d03a2ec08fd..e3cfa216d395f6fcebb5bfce057b471cc6e559e6 100644 (file)
@@ -11,8 +11,8 @@ import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 
 /**
- * Criterion that joins two {@link ClientSideCriterion} together and validates
- * if both sub criterion validate.
+ * Criterion type that joins two or more {@link ClientSideCriterion} together
+ * and validates that all sub criterion validates.
  * 
  * @since 6.3
  * 
@@ -20,23 +20,32 @@ import com.vaadin.terminal.PaintTarget;
 @ClientCriterion(com.vaadin.terminal.gwt.client.ui.dd.VAnd.class)
 public class And extends ClientSideCriterion {
 
-    private AcceptCriterion f1;
-    private AcceptCriterion f2;
+    private ClientSideCriterion[] f1;
 
-    public And(ClientSideCriterion f1, ClientSideCriterion f2) {
+    /**
+     * 
+     * @param f1
+     *            ClientSideCriterion that must match
+     */
+    public And(ClientSideCriterion... f1) {
         this.f1 = f1;
-        this.f2 = f2;
     }
 
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
         super.paintContent(target);
-        f1.paint(target);
-        f2.paint(target);
+        for (ClientSideCriterion crit : f1) {
+            crit.paint(target);
+        }
     }
 
     public boolean accepts(DragAndDropEvent dragEvent) {
-        return f1.accepts(dragEvent) && f2.accepts(dragEvent);
+        for (ClientSideCriterion crit : f1) {
+            if (!crit.accepts(dragEvent)) {
+                return false;
+            }
+        }
+        return true;
     }
 
 }
\ No newline at end of file
index 03e5e98415735d3ab28faafb479e7ba6fadf36e8..465637afe768099fe4107bd8b68592b7d4de7043 100644 (file)
@@ -9,9 +9,16 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
 import com.vaadin.terminal.gwt.client.ui.dd.VAcceptCriterion;
+import com.vaadin.ui.ClientWidget;
 
 /**
- * TODO
+ * An annotation type used to point the client side counterpart for server side
+ * a {@link AcceptCriterion} class. Usage is pretty similar to
+ * {@link ClientWidget} which is used with Vaadin components that have a
+ * specialized client side counterpart.
+ * <p>
+ * Annotations are used at GWT compilation phase, so remember to rebuild your
+ * widgetset if you do changes for {@link ClientCriterion} mappings.
  * 
  * @since 6.3
  */
index e4a6956141f4c317b156970d5582d1af12f7a337..a1f3d0e9705becbe6f5c78a076d94b06ca6dcab6 100644 (file)
@@ -11,13 +11,13 @@ import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.gwt.client.ui.dd.VServerAccept;
 
 /**
- * Parent class for criteria that are verified on the server side during a drag
+ * Parent class for criteria which are verified on the server side during a drag
  * operation to accept/discard dragged content (presented by
  * {@link Transferable}).
- * 
+ * <p>
  * Subclasses should implement the
  * {@link AcceptCriterion#accepts(com.vaadin.event.dd.DragAndDropEvent)} method.
- * 
+ * <p>
  * As all server side state can be used to make a decision, this is more
  * flexible than {@link ClientSideCriterion}. However, this does require
  * additional requests from the browser to the server during a drag operation.
@@ -31,6 +31,8 @@ import com.vaadin.terminal.gwt.client.ui.dd.VServerAccept;
 public abstract class ServerSideCriterion implements Serializable,
         AcceptCriterion {
 
+    private static final long serialVersionUID = 2128510128911628902L;
+
     public final boolean isClientSideVerifiable() {
         return false;
     }
index 694f9eddf5156f870985178a53328551e0fb0648..a9e6c7827697e73aff5d880fdcf4f3274a0faf35 100644 (file)
@@ -6,20 +6,12 @@
  */
 package com.vaadin.terminal.gwt.client.ui.dd;
 
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.UIDL;
 
-/**
- * TODO implementation could now be simplified/optimized
- * 
- */
-final public class VAnd extends VAcceptCriterion {
+final public class VAnd extends VAcceptCriterion implements VAcceptCallback {
     private boolean b1;
-    private boolean b2;
-    private VAcceptCriterion crit1;
-    private VAcceptCriterion crit2;
 
-    private VAcceptCriterion getCriteria(VDragEvent drag, UIDL configuration,
+    static VAcceptCriterion getCriteria(VDragEvent drag, UIDL configuration,
             int i) {
         UIDL childUIDL = configuration.getChildUIDL(i);
         return VAcceptCriteria.get(childUIDL.getStringAttribute("name"));
@@ -27,34 +19,20 @@ final public class VAnd extends VAcceptCriterion {
 
     @Override
     public boolean validates(VDragEvent drag, UIDL configuration) {
-        if (crit1 == null) {
-            crit1 = getCriteria(drag, configuration, 0);
-            crit2 = getCriteria(drag, configuration, 1);
-            if (crit1 == null || crit2 == null) {
-                ApplicationConnection.getConsole().log(
-                        "And criteria didn't found a chidl criteria");
+        int childCount = configuration.getChildCount();
+        for (int i = 0; i < childCount; i++) {
+            VAcceptCriterion crit = getCriteria(drag, configuration, i);
+            b1 = false;
+            crit.accept(drag, configuration.getChildUIDL(i), this);
+            if (!b1) {
                 return false;
             }
         }
+        return true;
+    }
 
-        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(1), accept2cb);
-
-        return b1 && b2;
+    public void accepted(VDragEvent event) {
+        b1 = true;
     }
 
 }
\ No newline at end of file
index b069f23ab35b091fafdf64746daf40079b7c5233..3e33cd6b0ca9156777babb668d972504909400ce 100644 (file)
@@ -20,7 +20,7 @@ final public class VOr extends VAcceptCriterion implements VAcceptCallback {
         int childCount = configuration.getChildCount();
         accepted = false;
         for (int i = 0; i < childCount; i++) {
-            VAcceptCriterion crit = getCriteria(drag, configuration, i);
+            VAcceptCriterion crit = VAnd.getCriteria(drag, configuration, i);
             crit.accept(drag, configuration.getChildUIDL(i), this);
             if (accepted == true) {
                 callback.accepted(drag);
@@ -29,15 +29,9 @@ final public class VOr extends VAcceptCriterion implements VAcceptCallback {
         }
     }
 
-    private VAcceptCriterion getCriteria(VDragEvent drag, UIDL configuration,
-            int i) {
-        UIDL childUIDL = configuration.getChildUIDL(i);
-        return VAcceptCriteria.get(childUIDL.getStringAttribute("name"));
-    }
-
     @Override
     public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
-        return false; // TODO enforce on server side
+        return false;
     }
 
     @Override