]> source.dussan.org Git - vaadin-framework.git/commitdiff
Some drag'n'drop javadoc improvements and a new method in DataBoundTransferable.
authorHenri Sara <henri.sara@itmill.com>
Fri, 12 Mar 2010 14:38:39 +0000 (14:38 +0000)
committerHenri Sara <henri.sara@itmill.com>
Fri, 12 Mar 2010 14:38:39 +0000 (14:38 +0000)
svn changeset:11831/svn branch:6.3

src/com/vaadin/event/DataBoundTransferable.java
src/com/vaadin/event/dd/DropTarget.java
src/com/vaadin/event/dd/acceptCriteria/AcceptCriterion.java
src/com/vaadin/event/dd/acceptCriteria/ClientSideCriterion.java
src/com/vaadin/event/dd/acceptCriteria/ServerSideCriterion.java
src/com/vaadin/ui/Table.java
src/com/vaadin/ui/Tree.java
tests/src/com/vaadin/tests/dd/AcceptAnythingWindow.java
tests/src/com/vaadin/tests/dd/DDTest2.java
tests/src/com/vaadin/tests/dd/DDTest6.java
tests/src/com/vaadin/tests/dd/HorizontalLayoutSortableWithWrappers.java

index 75263b2dac37e577654decf8aa290173c61163ca..edef4c44275fe6a27aafb92fb8c18aceccf07379 100644 (file)
@@ -5,8 +5,22 @@ package com.vaadin.event;
 
 import java.util.Map;
 
+import com.vaadin.data.Container;
 import com.vaadin.ui.Component;
 
+/**
+ * Parent class for {@link Transferable} implementations that have a Vaadin
+ * container as a data source. The transfer is associated with an item
+ * (identified by its Id) and optionally also a property identifier (e.g. a
+ * table column identifier when transferring a single table cell).
+ * 
+ * The component must implement the interface {@link Container.Viewer}.
+ * 
+ * In most cases, receivers of data transfers should depend on this class
+ * instead of its concrete subclasses.
+ * 
+ * @since 6.3
+ */
 public abstract class DataBoundTransferable extends TransferableImpl {
 
     public DataBoundTransferable(Component sourceComponent,
@@ -14,8 +28,38 @@ public abstract class DataBoundTransferable extends TransferableImpl {
         super(sourceComponent, rawVariables);
     }
 
+    /**
+     * Returns the identifier of the item being transferred.
+     * 
+     * @return item identifier
+     */
     public abstract Object getItemId();
 
+    /**
+     * Returns the optional property identifier that the transfer concerns.
+     * 
+     * This can be e.g. the table column from which a drag operation originated.
+     * 
+     * @return property identifier
+     */
     public abstract Object getPropertyId();
 
+    /**
+     * Returns the container data source from which the transfer occurs.
+     * 
+     * {@link Container.Viewer#getContainerDataSource()} is used to obtain the
+     * underlying container of the source component.
+     * 
+     * @return Container
+     */
+    public Container getSourceContainer() {
+        Component sourceComponent = getSourceComponent(); 
+        if (sourceComponent instanceof Container.Viewer) {
+            return ((Container.Viewer) sourceComponent)
+                    .getContainerDataSource();
+        } else {
+            // this should not happen
+            return null;
+        }
+    }
 }
index 7bd3efa8eebfc0891342bbbb96d7832009ac08e3..1d032c42e4ad19470729a6380d0761245bde8619 100644 (file)
@@ -10,7 +10,7 @@ import com.vaadin.ui.Component;
 /**
  * DropTarget is an 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.
+ * and provide a {@link DropHandler} which will handle the actual drop event.
  * 
  * @since 6.3
  */
index 4b9ce0fe188d5c8023a5bce0b7628bb63d12b716..d65c64d81eb533ada831c145ee62104981ac15b6 100644 (file)
@@ -15,20 +15,36 @@ import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 
 /**
- * TODO Javadoc
+ * Criterion that can be used create policy to accept/discard dragged content
+ * (presented by {@link Transferable}).
  * 
- * @since 6.3
+ * The drag and drop mechanism will verify the criteria returned by
+ * {@link DropHandler#getAcceptCriterion()} before calling
+ * {@link DropHandler#drop(DragAndDropEvent)}.
+ * 
+ * The criteria can be evaluated either on the client (browser - see
+ * {@link ClientSideCriterion}) or on the server (see
+ * {@link ServerSideCriterion}). If no constraints are needed, an
+ * {@link AcceptAll} can be used.
+ * 
+ * In addition to accepting or rejecting a possible drop, criteria can provide
+ * additional hints for client side painting.
  * 
+ * @see DropHandler
+ * @see ClientSideCriterion
+ * @see ServerSideCriterion
+ * 
+ * @since 6.3
  */
 public interface AcceptCriterion extends Serializable {
 
     /**
-     * Criterion that can be used create policy to accept/discard dragged
-     * content (presented by {@link Transferable}).
+     * Returns whether the criteria can be checked on the client or whether a
+     * server request is needed to check the criteria.
      * 
-     * 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).
+     * This requirement may depend on the state of the criterion (e.g. logical
+     * operations between criteria), so this cannot be based on a marker
+     * interface.
      */
     public boolean isClientSideVerifiable();
 
@@ -46,11 +62,11 @@ public interface AcceptCriterion extends Serializable {
     public void paintResponse(PaintTarget target) throws PaintException;
 
     /**
-     * Validates the data in event to be approriate for
+     * Validates the data in event to be appropriate 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.
+     * Note that even 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
index 849f25bc0ac84153f44279f51f05d60e7ae9a5ab..e406535958d535dab6b22c2dff7ece3eacd7c1fb 100644 (file)
@@ -13,6 +13,11 @@ import com.vaadin.terminal.PaintTarget;
  * All classes that provide criteria that can be completely validated on client
  * side should extend this class.
  * 
+ * It is recommended that subclasses of ClientSideCriterion re-validate the
+ * condition on the server side in
+ * {@link AcceptCriterion#accepts(com.vaadin.event.dd.DragAndDropEvent)} after
+ * the client side validation has accepted a transfer.
+ * 
  * @since 6.3
  */
 public abstract class ClientSideCriterion implements Serializable,
index 8011586950a9b8f712ba48994b0364a3f1e7d8ce..e4a6956141f4c317b156970d5582d1af12f7a337 100644 (file)
@@ -5,15 +5,27 @@ package com.vaadin.event.dd.acceptCriteria;
 
 import java.io.Serializable;
 
+import com.vaadin.event.Transferable;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.gwt.client.ui.dd.VServerAccept;
 
 /**
- * TODO Javadoc
+ * Parent class for criteria that are verified on the server side during a drag
+ * operation to accept/discard dragged content (presented by
+ * {@link Transferable}).
  * 
- * @since 6.3
+ * Subclasses should implement the
+ * {@link AcceptCriterion#accepts(com.vaadin.event.dd.DragAndDropEvent)} method.
+ * 
+ * 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.
  * 
+ * @see AcceptCriterion
+ * @see ClientSideCriterion
+ * 
+ * @since 6.3
  */
 @ClientCriterion(VServerAccept.class)
 public abstract class ServerSideCriterion implements Serializable,
index 71ceb3a2300d602a02bca3d4ec0634deae078197..c0ac21b274124d64c73d6ff5fe595c30fe54a528 100644 (file)
@@ -3340,7 +3340,15 @@ public class Table extends AbstractSelect implements Action.Container,
         requestRepaint();
     }
 
-    class TableTransferable extends DataBoundTransferable {
+    /**
+     * Concrete implementation of {@link DataBoundTransferable} for data
+     * transferred from a table.
+     * 
+     * @see {@link DataBoundTransferable}.
+     * 
+     * @since 6.3
+     */
+    protected class TableTransferable extends DataBoundTransferable {
 
         public TableTransferable(Map<String, Object> rawVariables) {
             super(Table.this, rawVariables);
@@ -3357,6 +3365,7 @@ public class Table extends AbstractSelect implements Action.Container,
 
         @Override
         public Object getPropertyId() {
+            // FIXME incorrect implementation, drag can also concern a cell
             return getItemCaptionPropertyId();
         }
 
index 4c1c7136fb7b3d5269fede431d1fc798dc445354..9f3649ebe9358b08197d58205abc261e664648b4 100644 (file)
@@ -1220,11 +1220,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
     }
 
     /**
-     * TODO Javadoc!
+     * Concrete implementation of {@link DataBoundTransferable} for data
+     * transferred from a tree.
+     * 
+     * @see {@link DataBoundTransferable}.
      * 
      * @since 6.3
      */
-    public class TreeTransferable extends DataBoundTransferable {
+    protected class TreeTransferable extends DataBoundTransferable {
 
         public TreeTransferable(Component sourceComponent,
                 Map<String, Object> rawVariables) {
index c07051ef3220805d1f71bd776b5fac85f89c7f39..38ecc308b534a7873ff035e924c765090c694ab5 100644 (file)
@@ -62,9 +62,7 @@ public class AcceptAnythingWindow extends Window {
 
                         } else {
                             // we have a component that is been dragged, add
-                            // it
-                            // to
-                            // this
+                            // it to this
                             layout.addComponent(component);
                         }
 
index 929542b1751fe3b57604995aada6ef7098501c0a..3a3fad5d54c494fa94274ce2355a16bfc231cad0 100644 (file)
@@ -139,10 +139,10 @@ public class DDTest2 extends TestBase {
                 DataBoundTransferable tr = (DataBoundTransferable) event
                         .getTransferable();
                 Object itemId = tr.getItemId();
-                Container sourceContainer = (Container) tr.getSourceComponent();
-                if (sourceContainer != tree1) {
+                Container sourceContainer = tr.getSourceContainer();
+                if (tr.getSourceComponent() != tree1) {
                     // if the source is from table (not from tree1 itself),
-                    // transfer Name property and use it as an indentifier in
+                    // transfer Name property and use it as an identifier in
                     // tree1
                     String name = sourceContainer.getItem(itemId)
                             .getItemProperty("Name").toString();
index 39d1f1fb7bf857ce7e88344697aacb57717d821b..6df55917fa84e3e2437ceeedbf1df5b803a759d7 100644 (file)
@@ -37,7 +37,6 @@ import com.vaadin.ui.Tree;
 import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
 import com.vaadin.ui.Tree.TreeDragMode;
 import com.vaadin.ui.Tree.TreeDropTargetDetails;
-import com.vaadin.ui.Tree.TreeTransferable;
 
 public class DDTest6 extends TestBase {
 
@@ -311,7 +310,7 @@ public class DDTest6 extends TestBase {
 
                 // dragged something from tree to the folder shown
 
-                File draggedFile = (File) ((TreeTransferable) dropEvent
+                File draggedFile = (File) ((DataBoundTransferable) dropEvent
                         .getTransferable()).getItemId();
                 DDTest6.get().setParent(draggedFile, folder);
             }
index 95011ffd42010908f8e6a6289c47406bfc0991a0..fbaf70b2764924cdbba6f6c4dfd6050a85cbb983 100644 (file)
@@ -96,7 +96,7 @@ public class HorizontalLayoutSortableWithWrappers extends Window {
     };
 
     public HorizontalLayoutSortableWithWrappers() {
-        setCaption("Horizontally sortable layout via (ddwrappers):Try sorting blocks by draggin them");
+        setCaption("Horizontally sortable layout via (ddwrappers): Try sorting blocks by dragging them");
         DragAndDropWrapper pane = new DragAndDropWrapper(layout);
         setContent(pane);
         pane.setSizeFull();