diff options
author | Artur Signell <artur@vaadin.com> | 2012-08-30 17:24:36 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-08-30 17:24:36 +0300 |
commit | 7b25b3886ea95bc6495506fbe9472e45fcbde684 (patch) | |
tree | 0b93cb65dab437feb46720659a63b8f1ef48f7f4 /uitest/src/com/vaadin/tests/dd/AcceptAnythingWindow.java | |
parent | 8941056349e302e687e40e94c13709e75f256d73 (diff) | |
download | vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.tar.gz vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.zip |
Renamed tests -> uitest and tests/testbench -> uitest/src (#9299)
Diffstat (limited to 'uitest/src/com/vaadin/tests/dd/AcceptAnythingWindow.java')
-rw-r--r-- | uitest/src/com/vaadin/tests/dd/AcceptAnythingWindow.java | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/dd/AcceptAnythingWindow.java b/uitest/src/com/vaadin/tests/dd/AcceptAnythingWindow.java new file mode 100644 index 0000000000..5d57de388c --- /dev/null +++ b/uitest/src/com/vaadin/tests/dd/AcceptAnythingWindow.java @@ -0,0 +1,138 @@ +package com.vaadin.tests.dd; + +import com.vaadin.event.DataBoundTransferable; +import com.vaadin.event.Transferable; +import com.vaadin.event.TransferableImpl; +import com.vaadin.event.dd.DragAndDropEvent; +import com.vaadin.event.dd.DropHandler; +import com.vaadin.event.dd.acceptcriteria.AcceptAll; +import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.AbsoluteLayout.ComponentPosition; +import com.vaadin.ui.Component; +import com.vaadin.ui.DragAndDropWrapper; +import com.vaadin.ui.DragAndDropWrapper.DragStartMode; +import com.vaadin.ui.DragAndDropWrapper.WrapperTargetDetails; +import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class AcceptAnythingWindow extends Window { + + private AbsoluteLayout layout = new AbsoluteLayout(); + + public AcceptAnythingWindow() { + setCaption("Drop anything here"); + + final DragAndDropWrapper wrapper = new DragAndDropWrapper(layout); + wrapper.setDropHandler(new DropHandler() { + + @Override + public AcceptCriterion getAcceptCriterion() { + return AcceptAll.get(); + } + + @Override + public void drop(DragAndDropEvent event) { + WrapperTargetDetails ed = (WrapperTargetDetails) event + .getTargetDetails(); + Transferable transferable = event.getTransferable(); + TransferableImpl ctr = (TransferableImpl) transferable; + Component component = ctr.getSourceComponent(); + if (component == wrapper) { + // if the drag source was wrapper we are interested about + // the dragged component + WrapperTransferable tr = (WrapperTransferable) transferable; + component = tr.getDraggedComponent(); + // html5 drag created by wrapper set component null + } + + if (component != null) { + + if (component.getParent() != layout) { + if (transferable instanceof DataBoundTransferable) { + // Item has been dragged, construct a Label from + // Item id + Label l = new Label(); + l.setSizeUndefined(); + l.setValue("ItemId : " + + ((DataBoundTransferable) transferable) + .getItemId()); + layout.addComponent(l); + component = l; + + } else { + // we have a component that is been dragged, add + // it to this + layout.addComponent(component); + } + + Integer left = ed.getAbsoluteLeft(); + Integer top = ed.getAbsoluteTop(); + + MouseEventDetails eventDetails = ed.getMouseEvent(); + + int clientX = eventDetails.getClientX(); + int clientY = eventDetails.getClientY(); + + try { + layout.getPosition(component).setTopValue( + Float.valueOf(clientY - top)); + layout.getPosition(component).setLeftValue( + Float.valueOf(clientX - left)); + } catch (Exception e) { + // TODO: handle exception + } + } else { + + WrapperTransferable tr = (WrapperTransferable) transferable; + // drag ended inside the this Pane + + MouseEventDetails start = tr.getMouseDownEvent(); + MouseEventDetails eventDetails = ed.getMouseEvent(); + + int deltaX = eventDetails.getClientX() + - start.getClientX(); + int deltaY = eventDetails.getClientY() + - start.getClientY(); + + ComponentPosition p = layout.getPosition(component); + p.setTopValue(p.getTopValue() + deltaY); + p.setLeftValue(p.getLeftValue() + deltaX); + + } + + } else { + // drag coming outside of Vaadin + String object = (String) transferable.getData("Text"); + + String content = (String) transferable + .getData("fileContents"); + + Label l = new Label(); + l.setCaption("Generated from HTML5 drag:"); + if (object != null) { + l.setValue(object); + } else { + l.setValue("HTML5 dd"); + } + + l.setDescription(content); + l.setSizeUndefined(); + + layout.addComponent(l); + + } + return; + } + }); + + wrapper.setDragStartMode(DragStartMode.COMPONENT); + wrapper.setSizeFull(); + setContent(wrapper); + + setWidth("250px"); + setHeight("100px"); + } +} |