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

src/com/vaadin/event/dd/DragAndDropEvent.java
src/com/vaadin/event/dd/DragSource.java
src/com/vaadin/event/dd/DropHandler.java
src/com/vaadin/event/dd/DropTarget.java
src/com/vaadin/event/dd/DropTargetDetails.java
src/com/vaadin/event/dd/DropTargetDetailsImpl.java
src/com/vaadin/terminal/gwt/client/ui/dd/VTransferable.java
src/com/vaadin/terminal/gwt/server/DragAndDropService.java
tests/src/com/vaadin/tests/dd/DDTest6.java

index d572739ef2c607ffe01d064125b8bb0318df0609..275e2127015e25b67be584e06921cd3e1b3429c2 100644 (file)
@@ -6,9 +6,18 @@ package com.vaadin.event.dd;
 import java.io.Serializable;
 
 import com.vaadin.event.Transferable;
+import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
 
 /**
- * TODO Javadoc
+ * DragAndDropEvent wraps information related to drag and drop operation. It is
+ * passed by terminal implementation for
+ * {@link DropHandler#drop(DragAndDropEvent)} and
+ * {@link AcceptCriterion#accepts(DragAndDropEvent)} methods.
+ * <p>
+ * DragAndDropEvent instances contains both the dragged data in
+ * {@link Transferable} (generated by {@link DragSource} and details about the
+ * current drop event in {@link DropTargetDetails} (generated by
+ * {@link DropTarget}.
  * 
  * @since 6.3
  * 
@@ -24,10 +33,18 @@ public class DragAndDropEvent implements Serializable {
         this.dropTargetDetails = dropTargetDetails;
     }
 
+    /**
+     * @return the Transferable instance representing the data dragged in this
+     *         drag and drop event
+     */
     public Transferable getTransferable() {
         return transferable;
     }
 
+    /**
+     * @return the DropTargetDetails containing drop target related details of
+     *         drag and drop operation
+     */
     public DropTargetDetails getDropTargetDetails() {
         return dropTargetDetails;
     }
index 3751ed00e6923c1c72dbdb320218086891bd732d..3635bf54680b279c536112006dcd7556074790e8 100644 (file)
@@ -3,35 +3,49 @@
  */
 package com.vaadin.event.dd;
 
-import java.io.Serializable;
 import java.util.Map;
 
 import com.vaadin.event.Transferable;
+import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Tree;
 
 /**
- * TODO Javadoc
+ * DragSource is a {@link Component} that builds a {@link Transferable} for a
+ * drag and drop operation.
+ * <p>
+ * In Vaadin the drag and drop operation practically starts from client side
+ * component. The client side component initially defines the data that will be
+ * present in {@link Transferable} object on server side. If the server side
+ * counterpart of the component implements this interface, terminal
+ * implementation lets it create the {@link Transferable} instance from the raw
+ * client side "seed data". This way server side implementation may translate or
+ * extend the data that will be available for {@link DropHandler}.
  * 
  * @since 6.3
  * 
  */
-public interface DragSource extends Serializable {
+public interface DragSource extends Component {
 
     /**
-     * DragSource may convert client side variables to meaningful values on
-     * server side. For example Tree converts item identifiers to generated
-     * string keys for the client side. Translators in Selects should convert
-     * them back to item identifiers.
+     * DragSource may convert data added by client side component to meaningful
+     * values for server side developer or add other data based on it.
      * 
      * <p>
-     * Translator should remove variables it handled from rawVariables. All non
-     * handled variables are added to Transferable automatically by terminal.
-     * </p>
-     * 
+     * For example Tree converts item identifiers to generated string keys for
+     * the client side. Vaadin developer don't and can't know anything about
+     * these generated keys, only about item identifiers. When tree node is
+     * dragged client puts that key to {@link Transferable}s client side
+     * counterpart. In {@link Tree#getTransferable(Map)} the key is converted
+     * back to item identifier that the server side developer can use.
      * <p>
      * 
      * @since 6.3
      * @param rawVariables
-     * @return the drag source related transferable
+     *            the data that client side initially included in
+     *            {@link Transferable}s client side counterpart.
+     * @return the {@link Transferable} instance that will be passed to
+     *         {@link DropHandler} (and/or {@link AcceptCriterion})
      */
     public Transferable getTransferable(Map<String, Object> rawVariables);
 
index 555bd7136b3127fed1369265428092fee181f1e7..c1c720ae2ca0b004ded6ca92e6f89319cb19d65c 100644 (file)
@@ -7,25 +7,50 @@ import java.io.Serializable;
 
 import com.vaadin.event.dd.acceptCriteria.AcceptAll;
 import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
+import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion;
 
 /**
- * TODO Javadoc
+ * DropHandlers contain the actual business logic for drag and drop operations.
+ * <p>
+ * The {@link #drop(DragAndDropEvent)} method is used to receive the transferred
+ * data and the #getAcceptCriterion()} method contains the (possibly client side
+ * verifiable) criterion whether the dragged data will be handled at all.
  * 
  * @since 6.3
  * 
  */
 public interface DropHandler extends Serializable {
 
+    /**
+     * Drop method is called when the end user has finished the drag operation
+     * on a {@link DropTarget} and {@link DragAndDropEvent} has passed
+     * {@link AcceptCriterion} defined by {@link #getAcceptCriterion()} method.
+     * The actual business logic of drag and drop operation is implemented into
+     * this method.
+     * 
+     * @param event
+     *            the event related to this drop
+     */
     public void drop(DragAndDropEvent event);
 
     /**
      * 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.
+     * {@link Transferable} will be handed over to
+     * {@link DropHandler#drop(DragAndDropEvent)} method. 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>
+     * Based on information from {@link AcceptCriterion} components may display
+     * some hints for the end user whether the drop will be accepted or not.
+     * <p>
+     * Vaadin contains a variety of criteria built in that can be composed to
+     * more complex criterion. If the build in criteria are not enough,
+     * developer can use a {@link ServerSideCriterion} or build own custom
+     * criterion with client side counterpart.
      * <p>
-     * If everything is accepted developer can return {@link AcceptAll}
-     * instance.
+     * If developer wants to handle everything in the
+     * {@link #drop(DragAndDropEvent)} method, {@link AcceptAll} instance can be
+     * returned.
      * 
      * @return the {@link AcceptCriterion}
      */
index 1d032c42e4ad19470729a6380d0761245bde8619..b2ab244c43206b37b7e4c6b4491409fe9e7478af 100644 (file)
@@ -16,17 +16,24 @@ import com.vaadin.ui.Component;
  */
 public interface DropTarget extends Component {
 
+    /**
+     * @return the drop hanler that will receive the dragged data or null if
+     *         drops are not currently accepted
+     */
     public DropHandler getDropHandler();
 
     /**
-     * Called before a drop operation to translate the drop target details
-     * provided by the client widget (drop target). Should return a DropData
-     * implementation with the new values. If null is returned the terminal
-     * implementation will automatically create a {@link DropTargetDetails} with
-     * all the client variables.
+     * Called before the {@link DragAndDropEvent} is passed to
+     * {@link DropHandler}. Implementation may for exmaple translate the drop
+     * target details provided by the client side (drop target) to meaningful
+     * server side values. If null is returned the terminal implementation will
+     * automatically create a {@link DropTargetDetails} with raw client side
+     * data.
+     * 
+     * @see DragSource#getTransferable(Map)
      * 
      * @param rawVariables
-     *            Parameters passed from the client side widget.
+     *            data passed from the DropTargets client side counterpart.
      * @return A DropTargetDetails object with the translated data or null to
      *         use a default implementation.
      */
index 1e3b38333daf9c52b13c37b33518410d26d2f725..770d58d9d3f481e8953b84939bf8e5440e8a9eba 100644 (file)
@@ -5,18 +5,33 @@ package com.vaadin.event.dd;
 
 import java.io.Serializable;
 
+import com.vaadin.ui.Tree.TreeDropTargetDetails;
+
 /**
- * TODO Javadoc
+ * DropTargetDetails wraps drop target related information about
+ * {@link DragAndDropEvent}.
+ * <p>
+ * When a DropTargetDetails object is used in {@link DropHandler} it is often
+ * preferable to cast the DropTargetDetail to an implementation provided by
+ * DropTarget like {@link TreeDropTargetDetails}. They often provide better
+ * typed, drop target specific API.
  * 
  * @since 6.3
  * 
  */
 public interface DropTargetDetails extends Serializable {
 
+    /**
+     * Gets target data associated to given string key
+     * 
+     * @param key
+     * @return
+     */
     public Object getData(String key);
 
-    public Object setData(String key, Object value);
-
+    /**
+     * @return the drop target on which the {@link DragAndDropEvent} happened.
+     */
     public DropTarget getTarget();
 
 }
index 2e6641c2cafea751d34eba32f64400ad2525f419..bcc35c623cd2b1f2c57bd8e1dd16224ae2de00d5 100644 (file)
@@ -6,22 +6,29 @@ package com.vaadin.event.dd;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.vaadin.terminal.gwt.server.DragAndDropService;
-
 /**
- * TODO Javadoc
+ * A HashMap backed implementation of {@link DropTargetDetails} for terminal
+ * implementation and for extension.
  * 
  * @since 6.3
  * 
  */
 public class DropTargetDetailsImpl implements DropTargetDetails {
 
+    private static final long serialVersionUID = -5099462771593036776L;
     private HashMap<String, Object> data = new HashMap<String, Object>();
+    private DropTarget dropTarget;
 
-    public DropTargetDetailsImpl(Map<String, Object> rawDropData) {
+    protected DropTargetDetailsImpl(Map<String, Object> rawDropData) {
         data.putAll(rawDropData);
     }
 
+    public DropTargetDetailsImpl(Map<String, Object> rawDropData,
+            DropTarget dropTarget) {
+        this(rawDropData);
+        this.dropTarget = dropTarget;
+    }
+
     public Object getData(String key) {
         return data.get(key);
     }
@@ -31,7 +38,7 @@ public class DropTargetDetailsImpl implements DropTargetDetails {
     }
 
     public DropTarget getTarget() {
-        return (DropTarget) data.get(DragAndDropService.DROPTARGET_KEY);
+        return dropTarget;
     }
 
 }
\ No newline at end of file
index 1574a6f6b4dae59c98e797f3e0ddbd572e231f22..57b4d90e079441efa01f0fe83c6dd4f67e3a3768 100644 (file)
@@ -34,7 +34,7 @@ public class VTransferable {
      * Sets the component currently being dragged or from which the transferable
      * is created (eg. a tree which node is dragged).
      * <p>
-     * The server side counterpart of the componennt may implement
+     * The server side counterpart of the component may implement
      * {@link DragSource} interface if it wants to translate or complement the
      * server side instance of this Transferable.
      * 
index bcba64d8848e33cf67340743b149f15089f35087..a314ebc967c1c088e5805a338482bb65e5cdd8af 100644 (file)
@@ -6,8 +6,8 @@ package com.vaadin.terminal.gwt.server;
 import java.io.PrintWriter;
 import java.util.Map;
 
-import com.vaadin.event.TransferableImpl;
 import com.vaadin.event.Transferable;
+import com.vaadin.event.TransferableImpl;
 import com.vaadin.event.dd.DragAndDropEvent;
 import com.vaadin.event.dd.DragSource;
 import com.vaadin.event.dd.DropHandler;
@@ -24,8 +24,6 @@ public class DragAndDropService implements VariableOwner {
 
     private static final long serialVersionUID = -4745268869323400203L;
 
-    public static final String DROPTARGET_KEY = "target";
-
     private int lastVisitId;
 
     private int currentEventId;
@@ -148,11 +146,9 @@ public class DragAndDropService implements VariableOwner {
 
         if (dropData == null) {
             // Create a default DragDropDetails with all the raw variables
-            dropData = new DropTargetDetailsImpl(rawDragDropDetails);
+            dropData = new DropTargetDetailsImpl(rawDragDropDetails, dropTarget);
         }
 
-        dropData.setData(DROPTARGET_KEY, dropTarget);
-
         return dropData;
     }
 
index ea3859c66497593c73e8c5be7ca13f93386718b5..00fffdbaf01fb7843ce056356631fa5ace50d7bd 100644 (file)
@@ -2,6 +2,7 @@ package com.vaadin.tests.dd;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collection;
@@ -400,7 +401,12 @@ public class DDTest6 extends TestBase {
                     for (Html5File html5File : files2) {
                         String fileName = html5File.getFileName();
                         // int bytes = html5File.getFileSize();
-                        final ByteArrayOutputStream bas = new ByteArrayOutputStream();
+                        final ByteArrayOutputStream bas = new ByteArrayOutputStream() {
+                            @Override
+                            public void close() throws IOException {
+                                super.close();
+                            }
+                        };
 
                         Receiver receiver = new Receiver() {
                             public OutputStream receiveUpload(String filename,