diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-10-05 16:41:56 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-10-06 12:23:07 +0300 |
commit | 1d3fc17f38e8dbf3ee2328be221202e1774bd56b (patch) | |
tree | bc6c31972fcf2bccd02a9536404c9e49daa56e7f /server | |
parent | 5097095625403405d030575fcc1102f02aa3e327 (diff) | |
download | vaadin-framework-1d3fc17f38e8dbf3ee2328be221202e1774bd56b.tar.gz vaadin-framework-1d3fc17f38e8dbf3ee2328be221202e1774bd56b.zip |
Add API for data destruction to DataGenerator interface (#19038)
This patch provides destroyData implementation for all default data
generators.
Change-Id: I1458080ee0203a27b52e604d3a30c9e5240c0383
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/data/DataGenerator.java | 14 | ||||
-rw-r--r-- | server/src/com/vaadin/data/RpcDataProviderExtension.java | 44 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 10 |
3 files changed, 53 insertions, 15 deletions
diff --git a/server/src/com/vaadin/data/DataGenerator.java b/server/src/com/vaadin/data/DataGenerator.java index a5333b8523..5e301d8151 100644 --- a/server/src/com/vaadin/data/DataGenerator.java +++ b/server/src/com/vaadin/data/DataGenerator.java @@ -18,7 +18,6 @@ package com.vaadin.data; import java.io.Serializable; import com.vaadin.ui.Grid.AbstractGridExtension; -import com.vaadin.ui.Grid.AbstractRenderer; import elemental.json.JsonObject; @@ -26,8 +25,8 @@ import elemental.json.JsonObject; * Interface for {@link AbstractGridExtension}s that allows adding data to row * objects being sent to client by the {@link RpcDataProviderExtension}. * <p> - * {@link AbstractRenderer} implements this interface to provide encoded data to - * client for {@link Renderer}s automatically. + * This class also provides a way to remove any unneeded data once the data + * object is no longer used on the client-side. * * @since 7.6 * @author Vaadin Ltd @@ -46,4 +45,13 @@ public interface DataGenerator extends Serializable { */ public void generateData(Object itemId, Item item, JsonObject rowData); + /** + * Informs the DataGenerator that an item id has been dropped and is no + * longer needed. + * + * @param itemId + * removed item id + */ + public void destroyData(Object itemId); + } diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 78c87ab23d..45caf01587 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -98,7 +98,7 @@ public class RpcDataProviderExtension extends AbstractExtension { // Remove still active rows that were "dropped" droppedItems.removeAll(itemIds); - internalDropActiveItems(droppedItems); + internalDropItems(droppedItems); droppedItems.clear(); } @@ -115,15 +115,6 @@ public class RpcDataProviderExtension extends AbstractExtension { } } - private void internalDropActiveItems(Collection<Object> itemIds) { - for (Object itemId : droppedItems) { - assert activeItemMap.containsKey(itemId) : "Item ID should exist in the activeItemMap"; - - activeItemMap.remove(itemId).removeListener(); - keyMapper.remove(itemId); - } - } - /** * Gets a collection copy of currently active item ids. * @@ -147,6 +138,15 @@ public class RpcDataProviderExtension extends AbstractExtension { rowData.put(GridState.JSONKEY_ROWKEY, keyMapper.key(itemId)); } + @Override + public void destroyData(Object itemId) { + keyMapper.remove(itemId); + GridValueChangeListener removed = activeItemMap.remove(itemId); + + if (removed != null) { + removed.removeListener(); + } + } } /** @@ -372,6 +372,13 @@ public class RpcDataProviderExtension extends AbstractExtension { .getConnectorId() : "")); } } + + @Override + public void destroyData(Object itemId) { + if (visibleDetails.contains(itemId)) { + destroyDetails(itemId); + } + } } private final Indexed container; @@ -734,8 +741,7 @@ public class RpcDataProviderExtension extends AbstractExtension { public void setParent(ClientConnector parent) { if (parent == null) { // We're being detached, release various listeners - activeItemHandler.internalDropActiveItems(activeItemHandler - .getActiveItemIds()); + internalDropItems(activeItemHandler.getActiveItemIds()); if (container instanceof ItemSetChangeNotifier) { ((ItemSetChangeNotifier) container) @@ -750,6 +756,20 @@ public class RpcDataProviderExtension extends AbstractExtension { } /** + * Informs all DataGenerators than an item id has been dropped. + * + * @param droppedItemIds + * collection of dropped item ids + */ + private void internalDropItems(Collection<Object> droppedItemIds) { + for (Object itemId : droppedItemIds) { + for (DataGenerator generator : dataGenerators) { + generator.destroyData(itemId); + } + } + } + + /** * Informs this data provider that given columns have been removed from * grid. * diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index f0e7b664e0..cee045128f 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -1131,6 +1131,11 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } @Override + public void destroyData(Object itemId) { + // NO-OP + } + + @Override protected Object getItemId(String rowKey) { return rowKey != null ? super.getItemId(rowKey) : null; } @@ -1880,6 +1885,11 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, data.put(columnKeys.key(cell.getPropertyId()), AbstractRenderer .encodeValue(modelValue, renderer, converter, getLocale())); } + + @Override + public void destroyData(Object itemId) { + // NO-OP + } } /** |