summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2010-03-17 11:30:46 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2010-03-17 11:30:46 +0000
commit4ca8752a4022803b3d350422f4228e78f17418e4 (patch)
tree93d746673f3cd08e32ba8adb8d68da7d2c9fe0f4
parent58bcba80f3399851fa2f77b876a78e32fccccea5 (diff)
downloadvaadin-framework-4ca8752a4022803b3d350422f4228e78f17418e4.tar.gz
vaadin-framework-4ca8752a4022803b3d350422f4228e78f17418e4.zip
DD related javadocs, cleanup, small refactoring
svn changeset:11927/svn branch:6.3
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/ContainsDataFlavor.java19
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java19
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/IsDataBound.java19
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/IsSameSourceAndTarget.java19
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/Not.java3
-rw-r--r--src/com/vaadin/event/dd/acceptCriteria/Or.java22
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VDataBound.java17
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java46
-rw-r--r--tests/src/com/vaadin/tests/dd/DDTest6.java51
9 files changed, 130 insertions, 85 deletions
diff --git a/src/com/vaadin/event/dd/acceptCriteria/ContainsDataFlavor.java b/src/com/vaadin/event/dd/acceptCriteria/ContainsDataFlavor.java
index 1a17b69b69..93530791d6 100644
--- a/src/com/vaadin/event/dd/acceptCriteria/ContainsDataFlavor.java
+++ b/src/com/vaadin/event/dd/acceptCriteria/ContainsDataFlavor.java
@@ -6,27 +6,30 @@
*/
package com.vaadin.event.dd.acceptCriteria;
+import com.vaadin.event.Transferable;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VContainsDataFlavor;
/**
- * TODO Javadoc!
+ * A Criterion that checks whether {@link Transferable} contains given data
+ * flavor. The developer might for example accept the incoming data only if it
+ * contains "Url" or "Text".
*
* @since 6.3
- *
*/
@ClientCriterion(VContainsDataFlavor.class)
-public final class ContainsDataFlavor extends ClientSideCriterion {
+public class ContainsDataFlavor extends ClientSideCriterion {
private String dataFlavorId;
/**
- * TODO should support basic UIDL data types
+ * Constructs a new instance of {@link ContainsDataFlavor}.
*
* @param dataFlawor
- * @param value
+ * the type of data that will be checked from
+ * {@link Transferable}
*/
public ContainsDataFlavor(String dataFlawor) {
dataFlavorId = dataFlawor;
@@ -42,4 +45,10 @@ public final class ContainsDataFlavor extends ClientSideCriterion {
return dragEvent.getTransferable().getDataFlavors().contains(
dataFlavorId);
}
+
+ @Override
+ protected String getIdentifier() {
+ // extending classes use client side implementation from this class
+ return ContainsDataFlavor.class.getCanonicalName();
+ }
} \ No newline at end of file
diff --git a/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java b/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java
index 134d928e91..b97f0159bb 100644
--- a/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java
+++ b/src/com/vaadin/event/dd/acceptCriteria/DropTargetDetailEquals.java
@@ -7,16 +7,19 @@
package com.vaadin.event.dd.acceptCriteria;
import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropTargetDetails;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VDropDetailEquals;
/**
- * Criteria for checking if drop target details contain the specific property
- * with the specific value.
+ * Criterion for checking if drop target details contains the specific property
+ * with the specific value. Currently only String values are supported.
*
* @since 6.3
*
+ * TODO add support for other basic data types that we support in UIDL.
+ *
*/
@ClientCriterion(VDropDetailEquals.class)
public final class DropTargetDetailEquals extends ClientSideCriterion {
@@ -25,13 +28,17 @@ public final class DropTargetDetailEquals extends ClientSideCriterion {
private String value;
/**
- * TODO should support basic UIDL data types
+ * Constructs a criterion which ensures that the value there is a value in
+ * {@link DropTargetDetails} that equals the reference value.
*
- * @param propertyName
+ * @param dataFlavor
+ * the type of data to be checked
* @param value
+ * the reference value to which the drop target detail will be
+ * compared
*/
- public DropTargetDetailEquals(String propertyName, String value) {
- this.propertyName = propertyName;
+ public DropTargetDetailEquals(String dataFlavor, String value) {
+ propertyName = dataFlavor;
this.value = value;
}
diff --git a/src/com/vaadin/event/dd/acceptCriteria/IsDataBound.java b/src/com/vaadin/event/dd/acceptCriteria/IsDataBound.java
index c492f3c259..c8050f94bf 100644
--- a/src/com/vaadin/event/dd/acceptCriteria/IsDataBound.java
+++ b/src/com/vaadin/event/dd/acceptCriteria/IsDataBound.java
@@ -6,27 +6,38 @@
*/
package com.vaadin.event.dd.acceptCriteria;
+import com.vaadin.data.Container;
+import com.vaadin.data.Item;
import com.vaadin.event.DataBoundTransferable;
+import com.vaadin.event.Transferable;
import com.vaadin.event.dd.DragAndDropEvent;
-import com.vaadin.terminal.gwt.client.ui.dd.VDataBound;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Tree;
/**
- * TODO Javadoc
+ * A simple accept criterion which ensures that {@link Transferable} contains an
+ * {@link Item} identifiers. In other words the criterion check that drag is
+ * coming from a {@link Container} like {@link Tree} or {@link Table}. TODO
+ * Javadoc
+ * <p>
+ * Note! class is singleton, use {@link #get()} method to get the instance.
*
* @since 6.3
*
*/
-@ClientCriterion(VDataBound.class)
-public final class IsDataBound extends ClientSideCriterion {
+public final class IsDataBound extends ContainsDataFlavor {
+ private static final long serialVersionUID = 1952366107184656946L;
private static IsDataBound singleton = new IsDataBound();
private IsDataBound() {
+ super("itemId");
}
public static IsDataBound get() {
return singleton;
}
+ @Override
public boolean accepts(DragAndDropEvent dragEvent) {
if (dragEvent.getTransferable() instanceof DataBoundTransferable) {
return ((DataBoundTransferable) dragEvent.getTransferable())
diff --git a/src/com/vaadin/event/dd/acceptCriteria/IsSameSourceAndTarget.java b/src/com/vaadin/event/dd/acceptCriteria/IsSameSourceAndTarget.java
index 5f4d3db116..1c14506d38 100644
--- a/src/com/vaadin/event/dd/acceptCriteria/IsSameSourceAndTarget.java
+++ b/src/com/vaadin/event/dd/acceptCriteria/IsSameSourceAndTarget.java
@@ -6,14 +6,22 @@
*/
package com.vaadin.event.dd.acceptCriteria;
+import com.vaadin.event.Transferable;
import com.vaadin.event.TransferableImpl;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VSourceIsSameAsTarget;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Tree;
/**
- * TODO Javadoc
+ *
+ * A criterion that ensures the drag source is the same as drop target. Eg.
+ * {@link Tree} or {@link Table} could support only re-ordering of items, but no
+ * {@link Transferable}s coming outside.
+ * <p>
+ * Note! Class is singleton, use {@link #get()} method to get the instance.
*
* @since 6.3
*
@@ -21,7 +29,8 @@ import com.vaadin.ui.Component;
@ClientCriterion(VSourceIsSameAsTarget.class)
public class IsSameSourceAndTarget extends ClientSideCriterion {
- private static IsSameSourceAndTarget instance;
+ private static final long serialVersionUID = -451399314705532584L;
+ private static IsSameSourceAndTarget instance = new IsSameSourceAndTarget();
private IsSameSourceAndTarget() {
}
@@ -33,14 +42,10 @@ public class IsSameSourceAndTarget extends ClientSideCriterion {
DropTarget target = dragEvent.getDropTargetDetails().getTarget();
return sourceComponent == target;
}
-
return false;
}
- public static IsSameSourceAndTarget get() {
- if (instance == null) {
- instance = new IsSameSourceAndTarget();
- }
+ public static synchronized IsSameSourceAndTarget get() {
return instance;
}
diff --git a/src/com/vaadin/event/dd/acceptCriteria/Not.java b/src/com/vaadin/event/dd/acceptCriteria/Not.java
index eaddce79b8..e4828cd83b 100644
--- a/src/com/vaadin/event/dd/acceptCriteria/Not.java
+++ b/src/com/vaadin/event/dd/acceptCriteria/Not.java
@@ -12,7 +12,7 @@ import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VNot;
/**
- * TODO Javadoc
+ * Criterion that wraps another criterion and inverts its return value.
*
* @since 6.3
*
@@ -20,6 +20,7 @@ import com.vaadin.terminal.gwt.client.ui.dd.VNot;
@ClientCriterion(VNot.class)
public class Not extends ClientSideCriterion {
+ private static final long serialVersionUID = 1131422338558613244L;
private AcceptCriterion acceptCriterion;
public Not(ClientSideCriterion acceptCriterion) {
diff --git a/src/com/vaadin/event/dd/acceptCriteria/Or.java b/src/com/vaadin/event/dd/acceptCriteria/Or.java
index 45a795e2cd..26cb90b18e 100644
--- a/src/com/vaadin/event/dd/acceptCriteria/Or.java
+++ b/src/com/vaadin/event/dd/acceptCriteria/Or.java
@@ -12,7 +12,7 @@ import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VOr;
/**
- * TODO Javadoc
+ * A compound criterion that returns true if any of criteria returns true.
*
* @since 6.3
*
@@ -23,23 +23,27 @@ public class Or extends ClientSideCriterion {
*
*/
private static final long serialVersionUID = 1L;
- private AcceptCriterion f1;
- private AcceptCriterion f2;
+ private AcceptCriterion criteria[];
- public Or(ClientSideCriterion f1, ClientSideCriterion f2) {
- this.f1 = f1;
- this.f2 = f2;
+ public Or(ClientSideCriterion... criteria) {
+ this.criteria = criteria;
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
- f1.paint(target);
- f2.paint(target);
+ for (AcceptCriterion crit : criteria) {
+ crit.paint(target);
+ }
}
public boolean accepts(DragAndDropEvent dragEvent) {
- return f1.accepts(dragEvent) || f2.accepts(dragEvent);
+ for (AcceptCriterion crit : criteria) {
+ if (crit.accepts(dragEvent)) {
+ return true;
+ }
+ }
+ return false;
}
} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDataBound.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDataBound.java
deleted file mode 100644
index e7db3e0e2f..0000000000
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDataBound.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
-@ITMillApache2LicenseForJavaFiles@
- */
-/**
- *
- */
-package com.vaadin.terminal.gwt.client.ui.dd;
-
-import com.vaadin.terminal.gwt.client.UIDL;
-
-final public class VDataBound extends VAcceptCriterion {
-
- @Override
- public boolean validates(VDragEvent drag, UIDL configuration) {
- return drag.getTransferable().getData("itemId") != null;
- }
-} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java
index 4f4fbe60a8..b069f23ab3 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java
@@ -6,51 +6,27 @@
*/
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 VOr extends VAcceptCriterion {
- private boolean b1;
- private boolean b2;
- private VAcceptCriterion crit1;
- private VAcceptCriterion crit2;
+final public class VOr extends VAcceptCriterion implements VAcceptCallback {
+ private boolean accepted;
@Override
public void accept(VDragEvent drag, UIDL configuration,
VAcceptCallback callback) {
- if (crit1 == null) {
- crit1 = getCriteria(drag, configuration, 0);
- crit2 = getCriteria(drag, configuration, 1);
- if (crit1 == null || crit2 == null) {
- ApplicationConnection.getConsole().log(
- "Or criteria didn't found a chidl criteria");
+ int childCount = configuration.getChildCount();
+ accepted = false;
+ for (int i = 0; i < childCount; i++) {
+ VAcceptCriterion crit = getCriteria(drag, configuration, i);
+ crit.accept(drag, configuration.getChildUIDL(i), this);
+ if (accepted == true) {
+ callback.accepted(drag);
return;
}
}
-
- 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);
- if (b1 || b2) {
- callback.accepted(drag);
- }
}
private VAcceptCriterion getCriteria(VDragEvent drag, UIDL configuration,
@@ -69,4 +45,8 @@ final public class VOr extends VAcceptCriterion {
return false; // not used here
}
+ public void accepted(VDragEvent event) {
+ accepted = true;
+ }
+
} \ No newline at end of file
diff --git a/tests/src/com/vaadin/tests/dd/DDTest6.java b/tests/src/com/vaadin/tests/dd/DDTest6.java
index 1150d8f0de..ea3859c664 100644
--- a/tests/src/com/vaadin/tests/dd/DDTest6.java
+++ b/tests/src/com/vaadin/tests/dd/DDTest6.java
@@ -25,6 +25,7 @@ import com.vaadin.event.dd.acceptCriteria.AcceptAll;
import com.vaadin.event.dd.acceptCriteria.AcceptCriterion;
import com.vaadin.event.dd.acceptCriteria.IsSameSourceAndTarget;
import com.vaadin.event.dd.acceptCriteria.Not;
+import com.vaadin.terminal.ApplicationResource;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.StreamResource;
import com.vaadin.terminal.ThemeResource;
@@ -39,6 +40,7 @@ import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;
import com.vaadin.ui.SplitPanel;
+import com.vaadin.ui.Table;
import com.vaadin.ui.Tree;
import com.vaadin.ui.Window;
import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
@@ -252,11 +254,37 @@ public class DDTest6 extends TestBase {
private void openFile(File file) {
// ATM supports only images.
+ if (file.getType().equals("image/png")) {
+ Embedded embedded = new Embedded(file.getName(), file.getResource());
+ Window w = new Window(file.getName());
+ w.addComponent(embedded);
+ w.getContent().setSizeUndefined();
+ getMainWindow().addWindow(w);
+ } else if (file.getType().equals("text/csv")) {
+ showSpreadsheet(file);
+ }
+ }
- Embedded embedded = new Embedded(file.getName(), file.getResource());
+ private void showSpreadsheet(File file) {
+ ApplicationResource resource = (ApplicationResource) file.getResource();
+ String string = new String(file.bas.toByteArray());
+ String[] rows = string.split("\n");
+ String[] cols = rows[0].split(",");
+ Table table = new Table();
+ for (String string2 : cols) {
+ String col = string2.replaceAll("\"", ""); // remove surrounding ""
+ table.addContainerProperty(string2, String.class, "");
+ }
+ for (int i = 1; i < rows.length; i++) {
+ String[] split = rows[i].split(",");
+ table.addItem(split, "" + i);
+ }
Window w = new Window(file.getName());
- w.addComponent(embedded);
+ w.getContent().setSizeUndefined();
+ table.setEditable(true);
+ w.addComponent(table);
getMainWindow().addWindow(w);
+ // TODO saving would be nice demo
}
@@ -385,6 +413,10 @@ public class DDTest6 extends TestBase {
File file = new File(fileName, bas);
file.setType(html5File.getType());
+ // FF don't know csv
+ if (fileName.endsWith(".csv")) {
+ file.setType("text/csv");
+ }
DDTest6.get().fs1.addBean(file);
DDTest6.get().tree1.setChildrenAllowed(file, false);
DDTest6.get().setParent(file, folder);
@@ -426,13 +458,26 @@ public class DDTest6 extends TestBase {
get().tree1.setValue(file);
} else {
String type = file.getType();
- if (type != null && type.equals("image/png")) {
+ if (canDisplay(type)) {
DDTest6.get().openFile(file);
}
}
}
}
+
+ String[] knownTypes = new String[] { "image/png", "text/csv" };
+
+ private boolean canDisplay(String type) {
+ if (type != null) {
+ for (String t : knownTypes) {
+ if (t.equals(type)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
});
if (file instanceof Folder) {