/**
* 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
*
@ClientCriterion(VAcceptAll.class)
public final class AcceptAll extends ClientSideCriterion {
+ private static final long serialVersionUID = 7406683402153141461L;
private static AcceptCriterion singleton = new AcceptAll();
private AcceptAll() {
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
*
@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
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
*/
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.
public abstract class ServerSideCriterion implements Serializable,
AcceptCriterion {
+ private static final long serialVersionUID = 2128510128911628902L;
+
public final boolean isClientSideVerifiable() {
return false;
}
*/
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"));
@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
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);
}
}
- 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