diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-18 14:49:50 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-18 14:49:50 +0000 |
commit | 0013d489752f07d53ab958ee31d8cb654aa13db1 (patch) | |
tree | 5f028551864c4697c2e730c62dfa72b9b3c192c4 /src | |
parent | 3e7cf2ff53df12946c5fe5fe3a5944931a40b415 (diff) | |
download | vaadin-framework-0013d489752f07d53ab958ee31d8cb654aa13db1.tar.gz vaadin-framework-0013d489752f07d53ab958ee31d8cb654aa13db1.zip |
added TableDropCriterion, quite similar to TreeDropCriterion and uses same client side criterion
svn changeset:11971/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/ui/Table.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index facf31d66f..6ae1362e9a 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -28,15 +28,19 @@ import com.vaadin.event.ItemClickEvent; import com.vaadin.event.Action.Handler; import com.vaadin.event.ItemClickEvent.ItemClickListener; import com.vaadin.event.ItemClickEvent.ItemClickSource; +import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DragSource; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.DropTarget; +import com.vaadin.event.dd.acceptCriteria.ClientCriterion; +import com.vaadin.event.dd.acceptCriteria.ServerSideCriterion; import com.vaadin.terminal.KeyMapper; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VScrollTable; +import com.vaadin.terminal.gwt.client.ui.dd.VLazyInitItemIdentifiers; /** * <p> @@ -3418,4 +3422,98 @@ public class Table extends AbstractSelect implements Action.Container, Map<String, Object> clientVariables) { return new AbstractSelectDropTargetDetails(clientVariables); } + + /** + * Lazy loading accept criterion for Table. Accepted target rows are loaded + * from server once per drag and drop operation. Developer must override one + * method that decides on which rows the currently dragged data can be + * dropped. + * + * <p> + * 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 TableDropCriterion extends ServerSideCriterion { + + private Table table; + + private Set<Object> allowedItemIds; + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.event.dd.acceptCriteria.ServerSideCriterion#getIdentifier + * () + */ + @Override + protected String getIdentifier() { + return TableDropCriterion.class.getCanonicalName(); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.event.dd.acceptCriteria.AcceptCriterion#accepts(com.vaadin + * .event.dd.DragAndDropEvent) + */ + public boolean accepts(DragAndDropEvent dragEvent) { + AbstractSelectDropTargetDetails dropTargetData = (AbstractSelectDropTargetDetails) dragEvent + .getDropTargetDetails(); + table = (Table) dragEvent.getDropTargetDetails().getTarget(); + ArrayList<Object> visibleItemIds = new ArrayList<Object>(table + .getPageLength()); + visibleItemIds.size(); + Object id = table.getCurrentPageFirstItemId(); + for (int i = 0; i < table.getPageLength() && id != null; i++) { + visibleItemIds.add(id); + id = table.nextItemId(id); + } + allowedItemIds = getAllowedItemIds(dragEvent, table, visibleItemIds); + + return allowedItemIds.contains(dropTargetData.getItemIdOver()); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.event.dd.acceptCriteria.AcceptCriterion#paintResponse( + * com.vaadin.terminal.PaintTarget) + */ + @Override + public void paintResponse(PaintTarget target) throws PaintException { + /* + * send allowed nodes to client so subsequent requests can be + * avoided + */ + Object[] array = allowedItemIds.toArray(); + for (int i = 0; i < array.length; i++) { + String key = table.itemIdMapper.key(array[i]); + array[i] = key; + } + target.addAttribute("allowedIds", array); + } + + /** + * @param dragEvent + * @param table + * the table for which the allowed item identifiers are + * defined + * @param visibleItemIds + * the list of currently rendered item identifiers, accepted + * item id's need to be detected only for these visible items + * @return the set of identifiers for items on which the dragEvent will + * be accepted + */ + protected abstract Set<Object> getAllowedItemIds( + DragAndDropEvent dragEvent, Table table, + Collection<Object> visibleItemIds); + + } + } |