diff options
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java | 13 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 16 | ||||
-rw-r--r-- | src/com/vaadin/ui/Tree.java | 13 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/dd/DDTest2.java | 30 |
4 files changed, 48 insertions, 24 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index fb95cc86d3..2ac0f04966 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -2531,8 +2531,19 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, VTransferable transferable = new VTransferable(); transferable.setDragSource(VScrollTable.this); transferable.setData("itemId", "" + rowKey); + NodeList<TableCellElement> cells = rowElement + .getCells(); + for (int i = 0; i < cells.getLength(); i++) { + if (cells.getItem(i).isOrHasChild( + targetTdOrTr)) { + HeaderCell headerCell = tHead + .getHeaderCell(i); + transferable.setData("propertyId", + headerCell.cid); + break; + } + } - // TODO propertyId VDragEvent ev = VDragAndDropManager.get() .startDrag(transferable, event, true); if (selectMode == SELECT_MODE_MULTI diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index c0ac21b274..5940046acf 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -3348,14 +3348,18 @@ public class Table extends AbstractSelect implements Action.Container, * * @since 6.3 */ - protected class TableTransferable extends DataBoundTransferable { + public class TableTransferable extends DataBoundTransferable { - public TableTransferable(Map<String, Object> rawVariables) { + protected TableTransferable(Map<String, Object> rawVariables) { super(Table.this, rawVariables); Object object = rawVariables.get("itemId"); if (object != null) { setData("itemId", itemIdMapper.get((String) object)); } + object = rawVariables.get("propertyId"); + if (object != null) { + setData("propertyId", columnIdMap.get((String) object)); + } } @Override @@ -3365,8 +3369,12 @@ public class Table extends AbstractSelect implements Action.Container, @Override public Object getPropertyId() { - // FIXME incorrect implementation, drag can also concern a cell - return getItemCaptionPropertyId(); + return getData("propertyId"); + } + + @Override + public Table getSourceComponent() { + return (Table) super.getSourceComponent(); } } diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index 018cc61985..f8a51cb8e4 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -1286,12 +1286,15 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, } /** - * An example of lazy initializing criterion. Initially pretty much no data - * is sent to client, on first accepts set (per drag request) the client - * side data structure is initialized and no subsequent requests requests - * are needed during that drag and drop operation. + * Lazy loading accept criterion for Tree. Accepted target nodes are loaded + * from server once per drag and drop operation. Developer must override one + * method that decides accepted tree nodes for the whole Tree. + * * <p> - * See client side counterpart + * Initially pretty much no data is sent to client. On first required + * criterion check (per drag request) the client side data structure is + * initialized from server and no subsequent requests requests are needed + * during that drag and drop operation. */ @ClientCriterion(VLazyInitItemIdentifiers.class) public static abstract class TreeDropCriterion extends ServerSideCriterion { diff --git a/tests/src/com/vaadin/tests/dd/DDTest2.java b/tests/src/com/vaadin/tests/dd/DDTest2.java index 3a3fad5d54..0f777b1214 100644 --- a/tests/src/com/vaadin/tests/dd/DDTest2.java +++ b/tests/src/com/vaadin/tests/dd/DDTest2.java @@ -1,6 +1,8 @@ package com.vaadin.tests.dd; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import com.vaadin.data.Container; import com.vaadin.data.Item; @@ -16,7 +18,6 @@ import com.vaadin.event.dd.acceptCriteria.And; 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; import com.vaadin.terminal.Resource; import com.vaadin.terminal.ThemeResource; import com.vaadin.tests.components.TestBase; @@ -26,9 +27,9 @@ 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.Table.TableTransferable; import com.vaadin.ui.Tree.OverFolderNode; import com.vaadin.ui.Tree.TreeDragMode; -import com.vaadin.ui.Tree.TreeDropTargetDetails; public class DDTest2 extends TestBase { @@ -76,26 +77,27 @@ public class DDTest2 extends TestBase { * explicitly defining them here), but demonstrates lazy initialization * option if rules are heavy. */ - final AcceptCriterion crit = new ServerSideCriterion() { - public boolean accepts(DragAndDropEvent dragEvent) { + final AcceptCriterion crit = new Tree.TreeDropCriterion() { - TreeDropTargetDetails dropTargetData = (TreeDropTargetDetails) dragEvent - .getDropTargetDetails(); - - Object itemIdOver = dropTargetData.getItemIdOver(); - - int i = r.nextInt(); - if (i % 2 == 0) { - return true; - } - return false; + @Override + protected Set<Object> getAllowedItemIds(DragAndDropEvent dragEvent, + Tree tree) { + return new HashSet(tree.getItemIds()); } }; tree3.setDropHandler(new DropHandler() { public void drop(DragAndDropEvent dropEvent) { Transferable transferable = dropEvent.getTransferable(); + String data = (String) transferable.getData("Text"); + if (transferable instanceof TableTransferable) { + TableTransferable tr = (TableTransferable) transferable; + System.out.println("From table row" + tr.getPropertyId()); + data = tr.getSourceContainer().getItem(tr.getItemId()) + .getItemProperty(tr.getPropertyId()).toString(); + + } if (data == null) { data = "-no Text data flawor-"; } |