diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-01-31 13:55:43 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-01-31 13:55:43 +0000 |
commit | c7c9e8c2c7b52a82882ed9165f84494802211749 (patch) | |
tree | 4f48299fe7db771ea2294381a89d156671988dc0 /src/com/vaadin/event | |
parent | 9c57035c34e8228c602b61672587c30b3be2fe1f (diff) | |
download | vaadin-framework-c7c9e8c2c7b52a82882ed9165f84494802211749.tar.gz vaadin-framework-c7c9e8c2c7b52a82882ed9165f84494802211749.zip |
svn changeset:11066/svn branch:6.3_dd
Diffstat (limited to 'src/com/vaadin/event')
-rw-r--r-- | src/com/vaadin/event/AbstractDropHandler.java | 48 | ||||
-rw-r--r-- | src/com/vaadin/event/DragRequest.java | 11 | ||||
-rw-r--r-- | src/com/vaadin/event/HasDropHandler.java | 18 |
3 files changed, 50 insertions, 27 deletions
diff --git a/src/com/vaadin/event/AbstractDropHandler.java b/src/com/vaadin/event/AbstractDropHandler.java index da15dc61b6..9023183f50 100644 --- a/src/com/vaadin/event/AbstractDropHandler.java +++ b/src/com/vaadin/event/AbstractDropHandler.java @@ -4,6 +4,8 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.ui.dd.DragAndDropManager.DragEventType; import com.vaadin.ui.Component; +import com.vaadin.ui.Tree.Location; +import com.vaadin.ui.Tree.TreeDropDetails; /** * An implementation of DropHandler interface. @@ -19,12 +21,9 @@ public abstract class AbstractDropHandler implements DropHandler { * Criterion that can be used create policy to accept/discard dragged * content (presented by {@link Transferable}). * - * TODO figure out how this can be done partly on client at least in some - * cases. isClientSideFilterable() tms. - * */ public interface AcceptCriterion { - public boolean accepts(Transferable transferable); + public boolean accepts(DragRequest request); } public interface ClientSideVerifiable extends AcceptCriterion { @@ -41,7 +40,7 @@ public abstract class AbstractDropHandler implements DropHandler { } private static final class AcceptAll implements ClientSideVerifiable { - public boolean accepts(Transferable transferable) { + public boolean accepts(DragRequest event) { return true; } @@ -65,8 +64,8 @@ public abstract class AbstractDropHandler implements DropHandler { this.f2 = f2; } - public boolean accepts(Transferable transferable) { - return f1.accepts(transferable) && f2.accepts(transferable); + public boolean accepts(DragRequest event) { + return f1.accepts(event) && f2.accepts(event); } public boolean isClientSideVerifiable() { @@ -95,9 +94,9 @@ public abstract class AbstractDropHandler implements DropHandler { this.component = component; } - public boolean accepts(Transferable transferable) { - if (transferable instanceof ComponentTransferrable) { - return ((ComponentTransferrable) transferable) + public boolean accepts(DragRequest event) { + if (event.getTransferable() instanceof ComponentTransferrable) { + return ((ComponentTransferrable) event.getTransferable()) .getSourceComponent() == component; } else { return false; @@ -117,7 +116,8 @@ public abstract class AbstractDropHandler implements DropHandler { } private static final class IsDataBinded implements ClientSideVerifiable { - public boolean accepts(Transferable transferable) { + public boolean accepts(DragRequest event) { + Transferable transferable = event.getTransferable(); if (transferable instanceof DataBindedTransferrable) { return ((DataBindedTransferrable) transferable).getItemId() != null; } @@ -142,8 +142,8 @@ public abstract class AbstractDropHandler implements DropHandler { this.acceptCriterion = acceptCriterion; } - public boolean accepts(Transferable transferable) { - return !acceptCriterion.accepts(transferable); + public boolean accepts(DragRequest event) { + return !acceptCriterion.accepts(event); } } @@ -157,17 +157,18 @@ public abstract class AbstractDropHandler implements DropHandler { this.f2 = f2; } - public boolean accepts(Transferable transferable) { - return f1.accepts(transferable) || f2.accepts(transferable); + public boolean accepts(DragRequest event) { + return f1.accepts(event) || f2.accepts(event); } } public static class OverTreeNode implements ClientSideVerifiable { - public boolean accepts(Transferable transferable) { + public boolean accepts(DragRequest event) { try { - return transferable.getData("detail").toString().toLowerCase() - .equals("center"); + TreeDropDetails eventDetails = (TreeDropDetails) event + .getEventDetails(); + return eventDetails.getDropLocation() == Location.MIDDLE; } catch (Exception e) { return false; } @@ -197,8 +198,8 @@ public abstract class AbstractDropHandler implements DropHandler { * @seecom.vaadin.event.DropHandler#acceptTransferrable(com.vaadin.event. * Transferable) */ - public boolean acceptTransferrable(Transferable transferable) { - return acceptCriterion.accepts(transferable); + public boolean acceptTransferrable(DragRequest request) { + return acceptCriterion.accepts(request); } private boolean clientSideVerifiable() { @@ -210,11 +211,10 @@ public abstract class AbstractDropHandler implements DropHandler { } public void handleDragRequest(DragRequest event) { - boolean acceptTransferrable = acceptTransferrable(event - .getTransferrable()); + boolean acceptTransferrable = acceptTransferrable(event); if (acceptTransferrable) { if (event.getType() == DragEventType.DROP) { - receive(event.getTransferrable()); + receive(event.getTransferable(), event.getEventDetails()); } else { event.setResponseParameter("accepted", true); } @@ -237,7 +237,7 @@ public abstract class AbstractDropHandler implements DropHandler { * * @see com.vaadin.event.DropHandler#receive(com.vaadin.event.Transferable) */ - public abstract void receive(Transferable transferable); + public abstract void receive(Transferable transferable, Object dropDetails); public void setAcceptCriterion(AcceptCriterion acceptCriterion) { this.acceptCriterion = acceptCriterion; diff --git a/src/com/vaadin/event/DragRequest.java b/src/com/vaadin/event/DragRequest.java index b1bd2a6316..c9a918aa23 100644 --- a/src/com/vaadin/event/DragRequest.java +++ b/src/com/vaadin/event/DragRequest.java @@ -10,13 +10,14 @@ public class DragRequest { private DragEventType dragEventType; private Transferable transferable; private Map<String, Object> responseData; + private Object eventDetails; public DragRequest(DragEventType dragEventType, Transferable transferable) { this.dragEventType = dragEventType; this.transferable = transferable; } - public Transferable getTransferrable() { + public Transferable getTransferable() { return transferable; } @@ -43,4 +44,12 @@ public class DragRequest { responseData.put(key, value); } + public void setEventDetails(Object eventDetails) { + this.eventDetails = eventDetails; + } + + public Object getEventDetails() { + return eventDetails; + } + } diff --git a/src/com/vaadin/event/HasDropHandler.java b/src/com/vaadin/event/HasDropHandler.java index 73ce74c392..8326e5ff37 100644 --- a/src/com/vaadin/event/HasDropHandler.java +++ b/src/com/vaadin/event/HasDropHandler.java @@ -1,13 +1,27 @@ package com.vaadin.event; +import java.util.Map; + import com.vaadin.ui.Component; /** - * Implementing component most commonly has also setDropHandler method, but - * not polluting interface here as component might also have internal + * Implementing component most commonly has also setDropHandler method, but not + * polluting interface here as component might also have internal * AbstractDropHandler implementation. * */ public interface HasDropHandler extends Component { public DropHandler getDropHandler(); + + /** + * TODO Consider using map-like type as return type that would be auto + * created by terminal in case this implementation would return null. Would + * enable using simple event details without server side class. Should at + * least include the component that {@link HasDropHandler} -> would make it + * possible for one drophandler to be used on multiple components. + * + * @param rawVariables + * @return + */ + public Object getDragEventDetails(Map<String, Object> rawVariables); }
\ No newline at end of file |