From: Matti Tahvonen Date: Thu, 4 Mar 2010 09:51:31 +0000 (+0000) Subject: changes X-Git-Tag: 6.7.0.beta1~1988^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9b84a02d3f46d1f4dca4cc3b17c388d51ca5194a;p=vaadin-framework.git changes svn changeset:11630/svn branch:6.3_dd --- diff --git a/WebContent/VAADIN/themes/base/styles.css b/WebContent/VAADIN/themes/base/styles.css index 948cf42f5b..60fb294fa0 100644 --- a/WebContent/VAADIN/themes/base/styles.css +++ b/WebContent/VAADIN/themes/base/styles.css @@ -1,5 +1,5 @@ -.v-theme-version:after {content:"6_3_0_dev-20100217";} -.v-theme-version-6_3_0_dev-20100217 {display: none;} +.v-theme-version:after {content:"6_3_0_dev-20100304";} +.v-theme-version-6_3_0_dev-20100304 {display: none;} /* Automatically compiled css file from subdirectories. */ .v-absolutelayout-wrapper { @@ -1354,18 +1354,6 @@ div.v-progressindicator-indeterminate-disabled { cursor: pointer; } -/* TODO remove important, replace with better anchors or order */ -.v-table tr.v-table-row-drag-center { - background-color: cyan !important; -} -/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ -.v-table-row-drag-top .v-table-cell-content { - border-top: 1px solid cyan ; -} -.v-table-row-drag-bottom .v-table-cell-content { - border-bottom: 1px solid cyan; -} - .v-table-body-noselection .v-table-row, .v-table-body-noselection .v-table-row-odd { cursor: default; @@ -1432,6 +1420,19 @@ div.v-progressindicator-indeterminate-disabled { color: #ddd; } +/* TODO remove important, replace with better anchors or order */ +.v-table-row-drag-middle .v-table-cell-content { + background-color: cyan; +} +/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ +.v-table-row-drag-top .v-table-cell-content { + border-top: 1px solid cyan ; +} +.v-table-row-drag-bottom .v-table-cell-content { + border-bottom: 1px solid cyan; +} + + .v-tabsheet, .v-tabsheet-content, .v-tabsheet-deco { diff --git a/WebContent/VAADIN/themes/base/table/table.css b/WebContent/VAADIN/themes/base/table/table.css index 235594493f..213d090b52 100644 --- a/WebContent/VAADIN/themes/base/table/table.css +++ b/WebContent/VAADIN/themes/base/table/table.css @@ -87,18 +87,6 @@ cursor: pointer; } -/* TODO remove important, replace with better anchors or order */ -.v-table tr.v-table-row-drag-center { - background-color: cyan !important; -} -/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ -.v-table-row-drag-top .v-table-cell-content { - border-top: 1px solid cyan ; -} -.v-table-row-drag-bottom .v-table-cell-content { - border-bottom: 1px solid cyan; -} - .v-table-body-noselection .v-table-row, .v-table-body-noselection .v-table-row-odd { cursor: default; @@ -163,4 +151,17 @@ } .v-off { color: #ddd; -} \ No newline at end of file +} + +/* TODO remove important, replace with better anchors or order */ +.v-table-row-drag-middle .v-table-cell-content { + background-color: cyan; +} +/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ +.v-table-row-drag-top .v-table-cell-content { + border-top: 1px solid cyan ; +} +.v-table-row-drag-bottom .v-table-cell-content { + border-bottom: 1px solid cyan; +} + diff --git a/WebContent/VAADIN/themes/reindeer/styles.css b/WebContent/VAADIN/themes/reindeer/styles.css index 1be5ef5ac9..c2df4128e4 100644 --- a/WebContent/VAADIN/themes/reindeer/styles.css +++ b/WebContent/VAADIN/themes/reindeer/styles.css @@ -1,5 +1,5 @@ -.v-theme-version:after {content:"6_3_0_dev-20100217";} -.v-theme-version-6_3_0_dev-20100217 {display: none;} +.v-theme-version:after {content:"6_3_0_dev-20100304";} +.v-theme-version-6_3_0_dev-20100304 {display: none;} /* Automatically compiled css file from subdirectories. */ .v-absolutelayout-wrapper { @@ -1354,18 +1354,6 @@ div.v-progressindicator-indeterminate-disabled { cursor: pointer; } -/* TODO remove important, replace with better anchors or order */ -.v-table tr.v-table-row-drag-center { - background-color: cyan !important; -} -/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ -.v-table-row-drag-top .v-table-cell-content { - border-top: 1px solid cyan ; -} -.v-table-row-drag-bottom .v-table-cell-content { - border-bottom: 1px solid cyan; -} - .v-table-body-noselection .v-table-row, .v-table-body-noselection .v-table-row-odd { cursor: default; @@ -1432,6 +1420,19 @@ div.v-progressindicator-indeterminate-disabled { color: #ddd; } +/* TODO remove important, replace with better anchors or order */ +.v-table-row-drag-middle .v-table-cell-content { + background-color: cyan; +} +/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ +.v-table-row-drag-top .v-table-cell-content { + border-top: 1px solid cyan ; +} +.v-table-row-drag-bottom .v-table-cell-content { + border-bottom: 1px solid cyan; +} + + .v-tabsheet, .v-tabsheet-content, .v-tabsheet-deco { diff --git a/WebContent/VAADIN/themes/runo/styles.css b/WebContent/VAADIN/themes/runo/styles.css index 843a89bcde..cf6236a886 100644 --- a/WebContent/VAADIN/themes/runo/styles.css +++ b/WebContent/VAADIN/themes/runo/styles.css @@ -1,5 +1,5 @@ -.v-theme-version:after {content:"6_3_0_dev-20100217";} -.v-theme-version-6_3_0_dev-20100217 {display: none;} +.v-theme-version:after {content:"6_3_0_dev-20100304";} +.v-theme-version-6_3_0_dev-20100304 {display: none;} /* Automatically compiled css file from subdirectories. */ .v-absolutelayout-wrapper { @@ -1354,18 +1354,6 @@ div.v-progressindicator-indeterminate-disabled { cursor: pointer; } -/* TODO remove important, replace with better anchors or order */ -.v-table tr.v-table-row-drag-center { - background-color: cyan !important; -} -/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ -.v-table-row-drag-top .v-table-cell-content { - border-top: 1px solid cyan ; -} -.v-table-row-drag-bottom .v-table-cell-content { - border-bottom: 1px solid cyan; -} - .v-table-body-noselection .v-table-row, .v-table-body-noselection .v-table-row-odd { cursor: default; @@ -1432,6 +1420,19 @@ div.v-progressindicator-indeterminate-disabled { color: #ddd; } +/* TODO remove important, replace with better anchors or order */ +.v-table-row-drag-middle .v-table-cell-content { + background-color: cyan; +} +/* TODO consider using height neutral styling (scrollbar issues when pagelength = table.length ) */ +.v-table-row-drag-top .v-table-cell-content { + border-top: 1px solid cyan ; +} +.v-table-row-drag-bottom .v-table-cell-content { + border-bottom: 1px solid cyan; +} + + .v-tabsheet, .v-tabsheet-content, .v-tabsheet-deco { diff --git a/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java index d516c870a2..80065f9254 100644 --- a/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java +++ b/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java @@ -387,7 +387,7 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, if (newParentId == null) { // Remove from old parents children list - final LinkedList l = children.get(itemId); + final LinkedList l = children.get(oldParentId); if (l != null) { l.remove(itemId); if (l.isEmpty()) { diff --git a/src/com/vaadin/event/dd/acceptCriteria/DragSourceIs.java b/src/com/vaadin/event/dd/acceptCriteria/DragSourceIs.java new file mode 100644 index 0000000000..6a097fcb03 --- /dev/null +++ b/src/com/vaadin/event/dd/acceptCriteria/DragSourceIs.java @@ -0,0 +1,51 @@ +/** + * + */ +package com.vaadin.event.dd.acceptCriteria; + +import com.vaadin.event.TransferableImpl; +import com.vaadin.event.dd.DragAndDropEvent; +import com.vaadin.terminal.PaintException; +import com.vaadin.terminal.PaintTarget; +import com.vaadin.terminal.gwt.client.ui.dd.VDragSourceIs; +import com.vaadin.ui.Component; + +/** + * Client side criteria that checks if the drag source is one of the given + * components. + * + * @since 6.3 + */ +@ClientCriterion(VDragSourceIs.class) +public class DragSourceIs extends ClientSideCriterion { + + private Component[] component; + + public DragSourceIs(Component... component) { + this.component = component; + } + + @Override + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + target.addAttribute("c", component.length); + for (int i = 0; i < component.length; i++) { + target.addAttribute("component" + i, component[i]); + } + } + + public boolean accepts(DragAndDropEvent dragEvent) { + if (dragEvent.getTransferable() instanceof TransferableImpl) { + Component sourceComponent = ((TransferableImpl) dragEvent + .getTransferable()).getSourceComponent(); + for (Component c : component) { + if (c == sourceComponent) { + return true; + } + } + } + + return false; + } + +} \ No newline at end of file diff --git a/src/com/vaadin/event/dd/acceptCriteria/IsDragSource.java b/src/com/vaadin/event/dd/acceptCriteria/IsDragSource.java deleted file mode 100644 index f1b4d420a4..0000000000 --- a/src/com/vaadin/event/dd/acceptCriteria/IsDragSource.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - */ -package com.vaadin.event.dd.acceptCriteria; - -import com.vaadin.event.TransferableImpl; -import com.vaadin.event.dd.DragAndDropEvent; -import com.vaadin.terminal.PaintException; -import com.vaadin.terminal.PaintTarget; -import com.vaadin.terminal.gwt.client.ui.dd.VIsDragSource; -import com.vaadin.ui.Component; - -/** - * Client side criteria that checks if the drag source is one of the given - * components. - * - * @since 6.3 - */ -@ClientCriterion(VIsDragSource.class) -public class IsDragSource extends ClientSideCriterion { - - private Component[] component; - - public IsDragSource(Component... component) { - this.component = component; - } - - @Override - public void paintContent(PaintTarget target) throws PaintException { - super.paintContent(target); - target.addAttribute("c", component.length); - for (int i = 0; i < component.length; i++) { - target.addAttribute("component" + i, component[i]); - } - } - - public boolean accepts(DragAndDropEvent dragEvent) { - if (dragEvent.getTransferable() instanceof TransferableImpl) { - Component sourceComponent = ((TransferableImpl) dragEvent - .getTransferable()).getSourceComponent(); - for (Component c : component) { - if (c == sourceComponent) { - return true; - } - } - } - - return false; - } - -} \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 46f16b0d6c..34e3580608 100755 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -1325,6 +1325,8 @@ public class ApplicationConnection { return 'd'; } else if (value instanceof Long) { return 'l'; + } else if (value instanceof Enum) { + return 's'; // transported as string representation } return 'u'; } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 8b75cfa761..59c5d252fe 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -2510,15 +2510,6 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, case Event.ONMOUSEDOWN: if (dragmode != 0) { mDown = true; - event.preventDefault(); - event.stopPropagation(); - } - break; - case Event.ONMOUSEOUT: - mDown = false; - break; - case Event.ONMOUSEMOVE: - if (mDown && dragmode != 0) { VTransferable transferable = new VTransferable(); transferable.setDragSource(VScrollTable.this); transferable.setData("itemId", "" + rowKey); @@ -2527,12 +2518,13 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, VDragEvent ev = VDragAndDropManager.get() .startDrag(transferable, event, true); ev.createDragImage(getElement(), true); - - mDown = false; - // prevent text selection event.preventDefault(); event.stopPropagation(); } + break; + case Event.ONMOUSEOUT: + mDown = false; + break; default: break; } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index dc6f914389..5b2cc0c035 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -67,10 +67,10 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { private boolean rendering; - private int dragMode = 0; - private VAbstractDropHandler dropHandler; + private int dragMode; + public VTree() { super(); setStyleName(CLASSNAME); @@ -123,6 +123,9 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { disabled = uidl.getBooleanAttribute("disabled"); readonly = uidl.getBooleanAttribute("readonly"); + dragMode = uidl.hasAttribute("dragMode") ? uidl + .getIntAttribute("dragMode") : 0; + isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect"); clear(); @@ -150,12 +153,6 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { selectedIds = uidl.getStringArrayVariableAsSet("selected"); - if (uidl.hasAttribute("dragMode")) { - dragMode = uidl.getIntAttribute("dragMode"); - } else { - dragMode = 0; - } - rendering = false; } @@ -164,16 +161,16 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { currentMouseOverKey = findCurrentMouseOverKey(drag.getElementOver()); - drag.getDropDetails().put("itemIdOver", currentMouseOverKey); - if (currentMouseOverKey != null) { - String detail = getDropDetail(drag.getCurrentGwtEvent()); + VerticalDropLocation detail = getDropDetail(drag + .getCurrentGwtEvent()); Boolean overTreeNode = null; TreeNode treeNode = keyToNode.get(currentMouseOverKey); if (treeNode != null && !treeNode.isLeaf() - && "MIDDLE".equals(detail)) { + && detail == VerticalDropLocation.MIDDLE) { overTreeNode = true; } + drag.getDropDetails().put("itemIdOver", currentMouseOverKey); drag.getDropDetails().put("itemIdOverIsNode", overTreeNode); drag.getDropDetails().put("detail", detail); @@ -202,16 +199,15 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { public void dragOver(final VDragEvent currentDrag) { final Object oldIdOver = currentDrag.getDropDetails().get( "itemIdOver"); - final String oldDetail = (String) currentDrag + final VerticalDropLocation oldDetail = (VerticalDropLocation) currentDrag .getDropDetails().get("detail"); updateTreeRelatedDragData(currentDrag); - final String detail = getDropDetail(currentDrag + final VerticalDropLocation detail = getDropDetail(currentDrag .getCurrentGwtEvent()); boolean nodeHasChanged = (currentMouseOverKey != null && currentMouseOverKey != oldIdOver) || (currentMouseOverKey == null && oldIdOver != null); - boolean detailHasChanded = (detail != null && !detail - .equals(oldDetail)) + boolean detailHasChanded = (detail != null && detail != oldDetail) || (detail == null && oldDetail != null); if (nodeHasChanged || detailHasChanded) { @@ -219,13 +215,6 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { "Change in Transferable " + currentMouseOverKey + " " + detail); final String newKey = currentMouseOverKey; - validate(new VAcceptCallback() { - public void accepted(VDragEvent event) { - if (newKey != null) { - keyToNode.get(newKey).emphasis(detail); - } - } - }, currentDrag); if (oldIdOver != null && oldIdOver != currentMouseOverKey) { TreeNode treeNode = keyToNode.get(oldIdOver); @@ -233,6 +222,13 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { treeNode.emphasis(null); } } + validate(new VAcceptCallback() { + public void accepted(VDragEvent event) { + if (newKey != null) { + keyToNode.get(newKey).emphasis(detail); + } + } + }, currentDrag); } } @@ -269,14 +265,14 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { dropHandler.updateAcceptRules(childUidl); } - public String getDropDetail(NativeEvent event) { + public VerticalDropLocation getDropDetail(NativeEvent event) { TreeNode treeNode = keyToNode.get(currentMouseOverKey); if (treeNode == null) { return null; } VerticalDropLocation verticalDropLocation = VerticalDropLocation.get( treeNode.nodeCaptionDiv, event.getClientY(), 0.2); - return verticalDropLocation.toString(); + return verticalDropLocation; } private void handleUpdate(UIDL uidl) { @@ -325,11 +321,11 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { return selectedIds.contains(treeNode.key); } - protected class TreeNode extends SimplePanel implements ActionOwner { + public class TreeNode extends SimplePanel implements ActionOwner { public static final String CLASSNAME = "v-tree-node"; - String key; + public String key; private String[] actionKeys = null; @@ -355,21 +351,66 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { | Event.ONCONTEXTMENU); } - public void emphasis(String string) { + protected void emphasis(VerticalDropLocation detail) { String base = "v-tree-node-drag-"; - UIObject.setStyleName(getElement(), base + "top", "TOP" - .equals(string)); - UIObject.setStyleName(getElement(), base + "bottom", "BOTTOM" - .equals(string)); - UIObject.setStyleName(getElement(), base + "center", "MIDDLE" - .equals(string)); + UIObject.setStyleName(getElement(), base + "top", + VerticalDropLocation.TOP == detail); + UIObject.setStyleName(getElement(), base + "bottom", + VerticalDropLocation.BOTTOM == detail); + UIObject.setStyleName(getElement(), base + "center", + VerticalDropLocation.MIDDLE == detail); base = "v-tree-node-caption-drag-"; - UIObject.setStyleName(nodeCaptionDiv, base + "top", "TOP" - .equals(string)); - UIObject.setStyleName(nodeCaptionDiv, base + "bottom", "BOTTOM" - .equals(string)); - UIObject.setStyleName(nodeCaptionDiv, base + "center", "MIDDLE" - .equals(string)); + UIObject.setStyleName(nodeCaptionDiv, base + "top", + VerticalDropLocation.TOP == detail); + UIObject.setStyleName(nodeCaptionDiv, base + "bottom", + VerticalDropLocation.BOTTOM == detail); + UIObject.setStyleName(nodeCaptionDiv, base + "center", + VerticalDropLocation.MIDDLE == detail); + + // also add classname to "folder node" into which the drag is + // targeted + + TreeNode folder = null; + /* Possible parent of this TreeNode will be stored here */ + TreeNode parentFolder = getParentNode(); + + // TODO fix my bugs + if (isLeaf()) { + folder = parentFolder; + // note, parent folder may be null if this is root node => no + // folder target exists + } else { + if (detail == VerticalDropLocation.TOP) { + folder = parentFolder; + } else { + folder = this; + } + // ensure we remove the dragfolder classname from the previous + // folder node + setDragFolderStyleName(this, false); + setDragFolderStyleName(parentFolder, false); + } + if (folder != null) { + setDragFolderStyleName(folder, detail != null); + } + + } + + private TreeNode getParentNode() { + Widget parent2 = getParent().getParent(); + if (parent2 instanceof TreeNode) { + return (TreeNode) parent2; + } + return null; + } + + private void setDragFolderStyleName(TreeNode folder, boolean add) { + if (folder != null) { + UIObject.setStyleName(folder.getElement(), + "v-tree-node-dragfolder", add); + UIObject.setStyleName(folder.nodeCaptionDiv, + "v-tree-node-caption-dragfolder", add); + } } @Override @@ -401,10 +442,13 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { if (dragMode != 0 || dropHandler != null) { if (type == Event.ONMOUSEDOWN) { if (nodeCaptionDiv.isOrHasChild(event.getTarget())) { - ApplicationConnection.getConsole().log( - "TreeNode m down"); - event.preventDefault(); // prevent text selection - mouseDownEvent = event; + if (dragMode > 0) { + + ApplicationConnection.getConsole().log( + "TreeNode m down"); + event.preventDefault(); // prevent text selection + mouseDownEvent = event; + } } } else if (type == Event.ONMOUSEMOVE || type == Event.ONMOUSEOUT) { @@ -691,4 +735,8 @@ public class VTree extends FlowPanel implements Paintable, VHasDropHandler { public VDropHandler getDropHandler() { return dropHandler; } + + public TreeNode getNodeByKey(String key) { + return keyToNode.get(key); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java index 6b58d36b90..21129e0b51 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java @@ -634,6 +634,9 @@ public class VDragAndDropManager { *

* Using this method may be handy if criterion that uses lazy initialization * are used. Check + *

+ * TODO Optimization: consider if we actually only need to keep the last + * command in queue here. * * @param command */ diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java new file mode 100644 index 0000000000..6805ba467e --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java @@ -0,0 +1,32 @@ +package com.vaadin.terminal.gwt.client.ui.dd; + +import com.vaadin.terminal.gwt.client.Paintable; +import com.vaadin.terminal.gwt.client.UIDL; + +/** + * TODO Javadoc! + * + * @since 6.3 + */ +final public class VDragSourceIs extends VAcceptCriterion { + + @Override + public boolean validates(VDragEvent drag, UIDL configuration) { + try { + Paintable component = drag.getTransferable().getDragSource(); + int c = configuration.getIntAttribute("c"); + for (int i = 0; i < c; i++) { + String requiredPid = configuration + .getStringAttribute("component" + i); + Paintable paintable = VDragAndDropManager.get() + .getCurrentDropHandler().getApplicationConnection() + .getPaintable(requiredPid); + if (paintable == component) { + return true; + } + } + } catch (Exception e) { + } + return false; + } +} \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsDragSource.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsDragSource.java deleted file mode 100644 index 5c98f736fe..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsDragSource.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.vaadin.terminal.gwt.client.ui.dd; - -import com.vaadin.terminal.gwt.client.Paintable; -import com.vaadin.terminal.gwt.client.UIDL; - -/** - * TODO Javadoc! - * - * @since 6.3 - */ -final public class VIsDragSource extends VAcceptCriterion { - - @Override - public boolean validates(VDragEvent drag, UIDL configuration) { - try { - Paintable component = drag.getTransferable().getDragSource(); - int c = configuration.getIntAttribute("c"); - for (int i = 0; i < c; i++) { - String requiredPid = configuration - .getStringAttribute("component" + i); - Paintable paintable = VDragAndDropManager.get() - .getCurrentDropHandler().getApplicationConnection() - .getPaintable(requiredPid); - if (paintable == component) { - return true; - } - } - } catch (Exception e) { - } - return false; - } -} \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java index 5a49d9dbe0..108d85de27 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java @@ -9,9 +9,7 @@ import com.vaadin.terminal.gwt.client.UIDL; /** * - * @deprecated example class testing custom behavior */ -@Deprecated final public class VLazyInitItemIdentifiers extends VAcceptCriterion { private boolean loaded = false; private HashSet hashSet; diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetNodeIsChildOf.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetNodeIsChildOf.java new file mode 100644 index 0000000000..70c8e45190 --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetNodeIsChildOf.java @@ -0,0 +1,37 @@ +/** + * + */ +package com.vaadin.terminal.gwt.client.ui.dd; + +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.ui.VTree; +import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode; + +final public class VTargetNodeIsChildOf extends VAcceptCriterion { + + @Override + public boolean validates(VDragEvent drag, UIDL configuration) { + + VTree tree = (VTree) VDragAndDropManager.get().getCurrentDropHandler() + .getPaintable(); + TreeNode treeNode = tree.getNodeByKey((String) drag.getDropDetails() + .get("itemIdOver")); + if (treeNode != null) { + Widget parent2 = treeNode.getParent().getParent(); + int depth = configuration.getIntAttribute("depth"); + if (depth < 0) { + depth = Integer.MAX_VALUE; + } + for (int i = 0; i < depth && parent2 instanceof TreeNode; i++) { + if (configuration.getStringAttribute("key").equals( + ((TreeNode) parent2).key)) { + return true; + } + parent2 = parent2.getParent().getParent(); + } + } + + return false; + } +} \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriterionGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriterionGenerator.java index fbdcb07a2e..8c357937d3 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriterionGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriterionGenerator.java @@ -102,6 +102,8 @@ public class AcceptCriterionGenerator extends Generator { .getCriterion(); for (Class class1 : clientSideVerifiableCriterion) { + logger.log(Type.INFO, "creating mapping for " + + class1.getCanonicalName()); String canonicalName = class1.getCanonicalName(); Class clientClass = class1 .getAnnotation(ClientCriterion.class).value(); diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java index 6b4136fd4e..aa084ec61b 100644 --- a/src/com/vaadin/ui/AbstractSelect.java +++ b/src/com/vaadin/ui/AbstractSelect.java @@ -30,7 +30,7 @@ import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; import com.vaadin.terminal.gwt.client.ui.dd.VIsOverId; import com.vaadin.terminal.gwt.client.ui.dd.VItemIdIs; -import com.vaadin.ui.Tree.Location; +import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; /** *

@@ -1775,7 +1775,10 @@ public abstract class AbstractSelect extends AbstractField implements */ public class AbstractSelectDropTargetDetails extends DropTargetDetailsImpl { - private Object idOver; + /** + * The treenode id over which the drag event happened. + */ + protected Object idOver; /** * TODO Javadoc! @@ -1791,7 +1794,8 @@ public abstract class AbstractSelect extends AbstractField implements } /** - * TODO Javadoc! + * If the drag operation is currently over an Item, this method returns + * the identifier of the Item. * */ public Object getItemIdOver() { @@ -1801,17 +1805,11 @@ public abstract class AbstractSelect extends AbstractField implements /** * TODO Javadoc! * - * @since 6.3 */ - public Location getDropLocation() { - String s = (String) getData("detail"); - if ("TOP".equals(s)) { - return Location.TOP; - } else if ("BOTTOM".equals(s)) { - return Location.BOTTOM; - } else { - return Location.MIDDLE; - } + public VerticalDropLocation getDropLocation() { + VerticalDropLocation valueOf = VerticalDropLocation + .valueOf((String) getData("detail")); + return valueOf; } } diff --git a/src/com/vaadin/ui/DragDropPane.java b/src/com/vaadin/ui/DragDropPane.java index 22a1eedc72..8fd0f8a8d4 100644 --- a/src/com/vaadin/ui/DragDropPane.java +++ b/src/com/vaadin/ui/DragDropPane.java @@ -2,7 +2,6 @@ package com.vaadin.ui; import java.util.Map; -import com.vaadin.event.TransferableImpl; import com.vaadin.event.DataBoundTransferable; import com.vaadin.event.Transferable; import com.vaadin.event.dd.DragAndDropEvent; @@ -77,10 +76,10 @@ public class DragDropPane extends AbsoluteLayout implements DropTarget { DragDropPane pane = (DragDropPane) event.getDropTargetDetails() .getTarget(); - DragEventDetails ed = (DragEventDetails) event.getDropTargetDetails(); - Transferable transferable = event.getTransferable(); - if (transferable instanceof TransferableImpl) { - TransferableImpl ctr = (TransferableImpl) transferable; + DragEventDetails ed = (DragEventDetails) event + .getDropTargetDetails(); + Transferable ctr = event.getTransferable(); + if (ctr.getSourceComponent() != null) { // use "component" (from DragDropPane) if available, else take // the source component Component component = (Component) ctr.getData("component"); @@ -89,14 +88,13 @@ public class DragDropPane extends AbsoluteLayout implements DropTarget { } if (component.getParent() != pane) { - if (transferable instanceof DataBoundTransferable) { + if (ctr instanceof DataBoundTransferable) { // Item has been dragged, construct a Label from // Item id Label l = new Label(); l.setSizeUndefined(); l.setValue("ItemId : " - + ((DataBoundTransferable) transferable) - .getItemId()); + + ((DataBoundTransferable) ctr).getItemId()); pane.addComponent(l); component = l; @@ -140,9 +138,9 @@ public class DragDropPane extends AbsoluteLayout implements DropTarget { } else { // drag coming outside of Vaadin - String object = (String) transferable.getData("text/plain"); + String object = (String) ctr.getData("text/plain"); - String content = (String) transferable.getData("fileContents"); + String content = (String) ctr.getData("fileContents"); Label l = new Label(); l.setCaption("Generated from HTML5 drag:"); diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 56c2cac421..665e98cfee 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -43,6 +43,8 @@ import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VTree; import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers; import com.vaadin.terminal.gwt.client.ui.dd.VOverTreeNode; +import com.vaadin.terminal.gwt.client.ui.dd.VTargetNodeIsChildOf; +import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; /** * Tree component. A Tree can be used to select an item (or multiple items) from @@ -113,16 +115,16 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, */ private boolean initialPaint = true; - private DragMode dragMode = DragMode.NONE; - /** * Supported drag modes for Tree. */ - public enum DragMode { - NONE, NODES; - + public enum TreeDragMode { + NONE, NODE + // , SUBTREE } + private TreeDragMode dragMode = TreeDragMode.NONE; + /* Tree constructors */ /** @@ -456,7 +458,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, target.addAttribute("nullselect", true); } - if (dragMode != DragMode.NONE) { + if (dragMode != TreeDragMode.NONE) { target.addAttribute("dragMode", dragMode.ordinal()); } @@ -1115,10 +1117,6 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, this.dropHandler = dropHandler; } - public enum Location { - TOP, BOTTOM, MIDDLE; - } - /** * TODO Javadoc! * @@ -1135,6 +1133,34 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, return (Tree) super.getTarget(); } + /** + * If the event is on a node that can not have children (see + * {@link Tree#areChildrenAllowed(Object)}), this method returns the + * parent item id of the target item (see {@link #getItemIdOver()} ). + * The identifier of the parent node is also returned if the cursor is + * on the top part of node. Else this method returns the same as + * {@link #getItemIdOver()}. + *

+ * In other words this method returns the identifier of the "folder" + * into the drag operation is targeted. + *

+ * If the method returns null, the current target is on a root node or + * on other undefined area over the tree component. + *

+ * The default Tree implementation marks the targetted tree node with + * CSS classnames v-tree-node-dragfolder and + * v-tree-node-caption-dragfolder (for the caption element). + */ + public Object getItemIdInto() { + + Object itemIdOver = getItemIdOver(); + if (areChildrenAllowed(itemIdOver) + && getDropLocation() != VerticalDropLocation.TOP) { + return itemIdOver; + } + return getParent(itemIdOver); + } + } /** @@ -1157,6 +1183,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, return itemIdMapper.key(itemId); } + public void setDragMode(TreeDragMode dragMode) { + this.dragMode = dragMode; + } + + public TreeDragMode getDragMode() { + return dragMode; + } + /** * TODO Javadoc! * @@ -1269,17 +1303,20 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, * Accepts transferable only on tree Node (middle of the node + can has * child) * + * TODO replace by composition of itemIdIs + drop property + * * @since 6.3 */ @ClientCriterion(VOverTreeNode.class) - public static class OverTreeNode extends ClientSideCriterion { + public static class OverFolderNode extends ClientSideCriterion { private static final long serialVersionUID = 1L; public boolean accepts(DragAndDropEvent dragEvent) { try { // must be over tree node and in the middle of it (not top or - // bottom part) + // bottom + // part) TreeDropTargetDetails eventDetails = (TreeDropTargetDetails) dragEvent .getDropTargetDetails(); @@ -1287,12 +1324,76 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, if (!eventDetails.getTarget().areChildrenAllowed(itemIdOver)) { return false; } + // return true if directly over + return eventDetails.getDropLocation() == VerticalDropLocation.MIDDLE; + } catch (Exception e) { + return false; + } + } + } + + /** + * Checks to parent (or parent hierarchy) for the item identifier given in + * constructor. If the parent is found, content is accepted. + */ + @ClientCriterion(VTargetNodeIsChildOf.class) + public class TargetNodeIsChildOf extends ClientSideCriterion { + + private Object parentItemId; + private int depthToCheck = 1; - return eventDetails.getDropLocation() == Location.MIDDLE; + /** + * + * @param parentItemId + */ + public TargetNodeIsChildOf(Object parentItemId) { + this.parentItemId = parentItemId; + } + + /** + * + * @param parentItemId + * @param depthToCheck + * the depth that tree is traversed upwards to seek for the + * parent, -1 means that the whole structure should be + * checked + */ + public TargetNodeIsChildOf(Object parentItemId, int depthToCheck) { + this.parentItemId = parentItemId; + this.depthToCheck = depthToCheck; + } + + private static final long serialVersionUID = 1L; + + public boolean accepts(DragAndDropEvent dragEvent) { + try { + TreeDropTargetDetails eventDetails = (TreeDropTargetDetails) dragEvent + .getDropTargetDetails(); + + if (eventDetails.getItemIdOver() != null) { + Object itemIdOver = eventDetails.getItemIdOver(); + Object parent2 = getParent(itemIdOver); + int i = 0; + while (parent2 != null && i < depthToCheck) { + if (parent2.equals(parentItemId)) { + return true; + } + i++; + } + } + return false; } catch (Exception e) { return false; } } + @Override + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + target.addAttribute("depth", depthToCheck); + target.addAttribute("key", key(parentItemId)); + } + } + } diff --git a/tests/src/com/vaadin/tests/dd/DDTest1.java b/tests/src/com/vaadin/tests/dd/DDTest1.java index 51568cbae0..e51f9fa1bc 100644 --- a/tests/src/com/vaadin/tests/dd/DDTest1.java +++ b/tests/src/com/vaadin/tests/dd/DDTest1.java @@ -4,7 +4,6 @@ import java.util.Collection; import com.vaadin.data.Item; import com.vaadin.data.util.HierarchicalContainer; -import com.vaadin.event.TransferableImpl; import com.vaadin.event.DataBoundTransferable; import com.vaadin.event.Transferable; import com.vaadin.event.dd.DragAndDropEvent; @@ -13,6 +12,7 @@ import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; import com.vaadin.event.dd.acceptCriteria.IsDataBound; import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; import com.vaadin.terminal.ExternalResource; +import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Component; import com.vaadin.ui.DragDropPane; @@ -22,9 +22,9 @@ import com.vaadin.ui.Layout; import com.vaadin.ui.Link; import com.vaadin.ui.Table; import com.vaadin.ui.Tree; -import com.vaadin.ui.AbstractSelect.AbstractSelectDropTargetDetails; import com.vaadin.ui.Table.DragModes; -import com.vaadin.ui.Tree.Location; +import com.vaadin.ui.Tree.TreeDragMode; +import com.vaadin.ui.Tree.TreeDropTargetDetails; /** * DD playground. Better quality example/prototype codes in {@link DDTest2}. @@ -64,22 +64,23 @@ public class DDTest1 extends TestBase { Transferable transferable = dragEvent.getTransferable(); // System.out.println("Simulating 500ms processing..."); // try { - // Thread.sleep(9000); + // Thread.sleep(200); // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // System.out.println("Done get to work."); - if (transferable instanceof TransferableImpl) { - TransferableImpl ct = (TransferableImpl) transferable; - - Component component = (Component) ct - .getData("component"); - if (component != null) { - if (component.toString() != null - && component.toString().contains("Bar")) { - return true; - } + + Component component = (Component) transferable + .getData("component"); + if (component == null) { + component = transferable.getSourceComponent(); + } + + if (component != null) { + if (component.toString() != null + && component.toString().contains("Bar")) { + return true; } } return false; @@ -116,6 +117,7 @@ public class DDTest1 extends TestBase { t.addItem("Child"); t.setParent("Child", "Foo"); t.setSizeFull(); + t.setDragMode(TreeDragMode.NODE); /* * Moves items in tree (and could work in Table too). Also supports @@ -187,7 +189,7 @@ public class DDTest1 extends TestBase { } public void drop(DragAndDropEvent event) { - AbstractSelectDropTargetDetails details = (AbstractSelectDropTargetDetails) event + TreeDropTargetDetails details = (TreeDropTargetDetails) event .getDropTargetDetails(); // TODO set properties, so same sorter could be used in Table Transferable transferable = event.getTransferable(); @@ -198,12 +200,16 @@ public class DDTest1 extends TestBase { Object itemIdOver = details.getItemIdOver(); - Location dropLocation = details.getDropLocation(); + // TODO could use the "folder" node id to make the drop + // logic simpler + Object itemIdInto = details.getItemIdInto(); + VerticalDropLocation dropLocation = details + .getDropLocation(); - if (dropLocation == Location.MIDDLE) { + if (dropLocation == VerticalDropLocation.MIDDLE) { t.setParent(itemId, itemIdOver); return; - } else if (Location.TOP == dropLocation) { + } else if (VerticalDropLocation.TOP == dropLocation) { // if on top of the caption area, add before itemIdOver = idx.prevItemId(itemIdOver); } diff --git a/tests/src/com/vaadin/tests/dd/DDTest2.java b/tests/src/com/vaadin/tests/dd/DDTest2.java index 58057aa29d..929542b175 100644 --- a/tests/src/com/vaadin/tests/dd/DDTest2.java +++ b/tests/src/com/vaadin/tests/dd/DDTest2.java @@ -13,7 +13,7 @@ import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; import com.vaadin.event.dd.acceptCriteria.And; -import com.vaadin.event.dd.acceptCriteria.IsDragSource; +import com.vaadin.event.dd.acceptCriteria.DragSourceIs; import com.vaadin.event.dd.acceptCriteria.IsDataBound; import com.vaadin.event.dd.acceptCriteria.Or; import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; @@ -26,7 +26,8 @@ import com.vaadin.ui.Table; import com.vaadin.ui.Tree; import com.vaadin.ui.Window; import com.vaadin.ui.AbstractSelect.AbstractSelectDropTargetDetails; -import com.vaadin.ui.Tree.OverTreeNode; +import com.vaadin.ui.Tree.OverFolderNode; +import com.vaadin.ui.Tree.TreeDragMode; import com.vaadin.ui.Tree.TreeDropTargetDetails; public class DDTest2 extends TestBase { @@ -45,6 +46,10 @@ public class DDTest2 extends TestBase { Window w = getLayout().getWindow(); /* darn reindeer has no icons */ + /* Make all trees (their nodes actually) draggable */ + tree1.setDragMode(TreeDragMode.NODE); + tree2.setDragMode(TreeDragMode.NODE); + hl.addComponent(tree1); hl.addComponent(table); hl.addComponent(tree2); @@ -59,6 +64,7 @@ public class DDTest2 extends TestBase { tree3 = new Tree( "Tree with lazy loading criteria, of first server visit caches accept rules for all captions"); + tree3.setDragMode(TreeDragMode.NODE); tree3.addItem("Drag on me"); tree3.addItem("Or me"); @@ -112,11 +118,15 @@ public class DDTest2 extends TestBase { */ table.setDragMode(Table.DragModes.ROWS); - OverTreeNode onNode = new OverTreeNode(); - IsDragSource fromTable = new IsDragSource(table); + OverFolderNode onNode = new OverFolderNode(); + DragSourceIs fromTable = new DragSourceIs(table); - IsDragSource fromTree = new IsDragSource(tree1); + DragSourceIs fromTree = new DragSourceIs(tree1); final Or fromTree1OrTable = new Or(fromTable, fromTree); + // Or could in the case be replaced with, keeping here as an example and + // test + DragSourceIs treeOrTable = new DragSourceIs(table, tree1); + final And and = new And(fromTree1OrTable, onNode); DropHandler dropHandler = new DropHandler() { diff --git a/tests/src/com/vaadin/tests/dd/DDTest4.java b/tests/src/com/vaadin/tests/dd/DDTest4.java index 905aef5381..f2f0ab73d7 100644 --- a/tests/src/com/vaadin/tests/dd/DDTest4.java +++ b/tests/src/com/vaadin/tests/dd/DDTest4.java @@ -8,15 +8,15 @@ import com.vaadin.event.DataBoundTransferable; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.acceptCriteria.AcceptCriterion; -import com.vaadin.event.dd.acceptCriteria.IsDragSource; +import com.vaadin.event.dd.acceptCriteria.DragSourceIs; import com.vaadin.terminal.ThemeResource; +import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.TestUtils; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Table; -import com.vaadin.ui.Tree; import com.vaadin.ui.Window; import com.vaadin.ui.AbstractSelect.AbstractSelectDropTargetDetails; -import com.vaadin.ui.Tree.Location; public class DDTest4 extends TestBase { @@ -25,11 +25,16 @@ public class DDTest4 extends TestBase { HorizontalLayout hl = new HorizontalLayout(); Table table = new Table("Drag and drop sortable table"); - private Tree tree3; - @Override protected void setup() { Window w = getLayout().getWindow(); + + TestUtils + .injectCSS( + w, + ".v-table-row-drag-middle .v-table-cell-content {" + + " background-color: inherit ; border-bottom: 1px solid cyan;" + + "}"); /* darn reindeer has no icons */ // hl.addComponent(tree1); @@ -40,6 +45,8 @@ public class DDTest4 extends TestBase { hl.setExpandRatio(table, 1); table.setWidth("100%"); table.setPageLength(10); + table.setRowHeaderMode(Table.ROW_HEADER_MODE_ID); + table.setSelectable(true); populateTable(); addComponent(hl); @@ -50,7 +57,7 @@ public class DDTest4 extends TestBase { table.setDropHandler(new DropHandler() { // accept only drags from this table - AcceptCriterion crit = new IsDragSource(table); + AcceptCriterion crit = new DragSourceIs(table); public AcceptCriterion getAcceptCriterion() { return crit; @@ -74,10 +81,13 @@ public class DDTest4 extends TestBase { IndexedContainer clone = null; try { clone = (IndexedContainer) containerDataSource.clone(); - int newIndex = containerDataSource.indexOfId(itemIdOver); - if (dropTargetData.getDropLocation() != Location.TOP) { + int newIndex = containerDataSource.indexOfId(itemIdOver) - 1; + if (dropTargetData.getDropLocation() != VerticalDropLocation.TOP) { newIndex++; } + if (newIndex < 0) { + newIndex = 0; + } containerDataSource.removeItem(itemId); Item newItem = containerDataSource.addItemAt(newIndex, itemId); diff --git a/tests/src/com/vaadin/tests/dd/DDTest5.java b/tests/src/com/vaadin/tests/dd/DDTest5.java index 052cb0ca83..5514402074 100644 --- a/tests/src/com/vaadin/tests/dd/DDTest5.java +++ b/tests/src/com/vaadin/tests/dd/DDTest5.java @@ -15,8 +15,8 @@ import com.vaadin.ui.DragAndDropWrapper; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Window; -import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable; import com.vaadin.ui.DragAndDropWrapper.DragStartMode; +import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable; public class DDTest5 extends TestBase { diff --git a/tests/src/com/vaadin/tests/dd/DDTest6.java b/tests/src/com/vaadin/tests/dd/DDTest6.java new file mode 100644 index 0000000000..599fa113ff --- /dev/null +++ b/tests/src/com/vaadin/tests/dd/DDTest6.java @@ -0,0 +1,143 @@ +package com.vaadin.tests.dd; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.event.DataBoundTransferable; +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.terminal.Resource; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.TestUtils; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.SplitPanel; +import com.vaadin.ui.Tree; +import com.vaadin.ui.Tree.TreeDragMode; +import com.vaadin.ui.Tree.TreeDropTargetDetails; + +public class DDTest6 extends TestBase { + + java.util.Random r = new java.util.Random(1); + + File[] files = new File[] { new Folder("Docs"), new Folder("Music"), + new Folder("Images"), new File("document.doc"), + new File("song.mp3"), new File("photo.jpg") }; + + private DropHandler dh; + + private static int count; + + @Override + protected void setup() { + SplitPanel sp = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); + + CssLayout l = new CssLayout(); + sp.setFirstComponent(l); + CssLayout l2 = new CssLayout(); + sp.setSecondComponent(l2); + + final Tree tree1 = new Tree("Volume 1"); + + BeanItemContainer fs1 = new BeanItemContainer(File.class); + tree1.setContainerDataSource(fs1); + for (int i = 0; i < files.length; i++) { + fs1.addBean(files[i]); + if (files[i] instanceof Folder) { + tree1.setChildrenAllowed(files[i], true); + } else { + tree1.setChildrenAllowed(files[i], false); + } + if (i >= files.length / 2) { + tree1.setParent(files[i], files[i - files.length / 2]); + } + } + tree1.setItemCaptionPropertyId("name"); + tree1.setItemIconPropertyId("icon"); + + tree1.setDragMode(TreeDragMode.NODE); + + DropHandler dropHandler = new DropHandler() { + public AcceptCriterion getAcceptCriterion() { + return AcceptAll.get(); + } + + public void drop(DragAndDropEvent dropEvent) { + DataBoundTransferable transferable = (DataBoundTransferable) dropEvent + .getTransferable(); + TreeDropTargetDetails dropTargetData = (TreeDropTargetDetails) dropEvent + .getDropTargetDetails(); + + tree1.setParent(transferable.getItemId(), dropTargetData + .getItemIdInto()); + + } + }; + + tree1.setDropHandler(dropHandler); + + l.addComponent(tree1); + + getLayout().setSizeFull(); + getLayout().addComponent(sp); + TestUtils + .injectCSS( + getLayout().getWindow(), + "" + + ".v-tree-node-caption-drag-top {/*border-top: none;*/} " + + ".v-tree-node-caption-drag-bottom {border-bottom: none ;} " + + ".v-tree-node-caption-drag-center {background-color: transparent;}" + + ".v-tree-node-caption-dragfolder { background-color: cyan;} "); + + } + + private final static ThemeResource FOLDER = new ThemeResource( + "../runo/icons/16/folder.png"); + private final static ThemeResource DOC = new ThemeResource( + "../runo/icons/16/document.png"); + + public static class File { + private Resource icon = DOC; + private String name; + + public File(String fileName) { + name = fileName; + } + + public void setIcon(Resource icon) { + this.icon = icon; + } + + public Resource getIcon() { + return icon; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + public static class Folder extends File { + + public Folder(String fileName) { + super(fileName); + setIcon(FOLDER); + } + + } + + @Override + protected String getDescription() { + return "dd: tree and web desktop tests. TODO add traditional icon area on right side with DragAndDropWrapper and absolutelayouts + more files, auto-opening folders"; + } + + @Override + protected Integer getTicketNumber() { + return 119; + } + +} diff --git a/tests/src/com/vaadin/tests/util/TestUtils.java b/tests/src/com/vaadin/tests/util/TestUtils.java new file mode 100644 index 0000000000..71ef6abbd1 --- /dev/null +++ b/tests/src/com/vaadin/tests/util/TestUtils.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.util; + +import com.vaadin.ui.Window; + +public class TestUtils { + + /** + * Crossbrowser hack to dynamically add css current window. Can be used to + * keep tests css in source files. + * + * @param cssString + */ + public static void injectCSS(Window w, String cssString) { + String script = "if ('\\v'=='v') /* ie only */ {\n" + + " document.createStyleSheet().cssText = '" + + cssString + + "';\n" + + " } else {var tag = document.createElement('style'); tag.type = 'text/css';" + + " document.getElementsByTagName('head')[0].appendChild(tag);tag[ (typeof " + + "document.body.style.WebkitAppearance=='string') /* webkit only */ ? 'innerText' " + + ": 'innerHTML'] = '" + cssString + "';}"; + + w.executeJavaScript(script); + } + +}