aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com
diff options
context:
space:
mode:
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>2014-10-02 16:02:55 +0400
committerVaadin Code Review <review@vaadin.com>2014-10-07 14:44:05 +0000
commit0abf13890b8c2391a609d63995a862b831e2f078 (patch)
tree4666e9a2535a8d2d2c38b1d82935a626d7bc0c21 /server/src/com
parente2c9102b296a5a24ecc7b6b53411082d2c6bbfda (diff)
downloadvaadin-framework-0abf13890b8c2391a609d63995a862b831e2f078.tar.gz
vaadin-framework-0abf13890b8c2391a609d63995a862b831e2f078.zip
Re-adding content in Table causes table to lose scroll position (#14581)
At this moment behavior of restoring scroll position more like as in 7.2.6. But restoring is only in case of removeAll() - addAll() (or add() one time - then restore index is reset). In 7.2.6 restoring of scroll position was the result of client defect (scrolling in lazyScroller was not changed if variable "firstvisible" fromserver was 0). This "defect" was fixed in one of the patches. Change-Id: I2e2fb8749ec95f3409caeacafff46c4c29159e74
Diffstat (limited to 'server/src/com')
-rw-r--r--server/src/com/vaadin/ui/Table.java82
1 files changed, 18 insertions, 64 deletions
diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java
index 3a1ab82be5..34d48a9b18 100644
--- a/server/src/com/vaadin/ui/Table.java
+++ b/server/src/com/vaadin/ui/Table.java
@@ -422,61 +422,11 @@ public class Table extends AbstractSelect implements Action.Container,
private Object currentPageFirstItemId = null;
/*
- * This class stores the hashcode and scroll position of the previous
- * container so that the scroll position can be restored if the same
- * container is removed and then re-added. This resolves #14581.
+ * If all rows get removed then scroll position of the previous container
+ * can be restored after re-adding/replacing rows via addAll(). This
+ * resolves #14581.
*/
- protected static class ScrollPositionRepairOnReAddAllRowsData implements
- Serializable {
-
- private static final long serialVersionUID = 1L;
- // current page first item index (to repair scroll position)
- private int itemIndex;
- /*
- * hashCode() of container before it was cleared via
- * container.removeAllItems();
- */
- private int containerHashCode;
-
- public ScrollPositionRepairOnReAddAllRowsData() {
- itemIndex = -1;
- containerHashCode = -1;
- }
-
- public int getItemId() {
- return itemIndex;
- }
-
- public void setItemId(int itemId) {
- itemIndex = itemId;
- }
-
- public void resetItemId() {
- itemIndex = -1;
- }
-
- public void setContainerData(Container container) {
- if (container != null) {
- containerHashCode = container.hashCode();
- } else {
- containerHashCode = -1;
- }
- }
-
- public boolean needRepairScrollPosition(Container newContainer) {
- return (itemIndex != -1) && isTheSameContainer(newContainer);
- }
-
- private boolean isTheSameContainer(Container newContainer) {
- boolean theSame = false;
- if (newContainer != null) {
- theSame = (newContainer.hashCode() == containerHashCode);
- }
- return theSame;
- }
- }
-
- private final ScrollPositionRepairOnReAddAllRowsData scrollRepairOnReAdding = new ScrollPositionRepairOnReAddAllRowsData();
+ private int repairOnReAddAllRowsDataScrollPositionItemIndex = -1;
/**
* Index of the first item on the current page.
@@ -2734,10 +2684,6 @@ public class Table extends AbstractSelect implements Action.Container,
newDataSource = new IndexedContainer();
}
- if (scrollRepairOnReAdding != null) {
- // this is important if container is set for table after filling
- scrollRepairOnReAdding.setContainerData(newDataSource);
- }
Collection<Object> generated;
if (columnGenerators != null) {
generated = columnGenerators.keySet();
@@ -4571,14 +4517,22 @@ public class Table extends AbstractSelect implements Action.Container,
int currentFirstItemIndex = getCurrentPageFirstItemIndex();
if (event.getContainer().size() == 0) {
- scrollRepairOnReAdding.setItemId(getCurrentPageFirstItemIndex());
+ repairOnReAddAllRowsDataScrollPositionItemIndex = getCurrentPageFirstItemIndex();
} else {
- if (scrollRepairOnReAdding.needRepairScrollPosition(event
- .getContainer())) {
- currentFirstItemIndex = scrollRepairOnReAdding.getItemId();
+ if (repairOnReAddAllRowsDataScrollPositionItemIndex != -1) {
+ currentFirstItemIndex = repairOnReAddAllRowsDataScrollPositionItemIndex;
+ /*
+ * Reset repairOnReAddAllRowsDataScrollPositionItemIndex.
+ *
+ * Next string should be commented (removed) if we want to have
+ * possibility to restore scroll position during adding items to
+ * container one by one via add() but not only addAll(). The
+ * problem in this case: we cannot track what happened between
+ * add() and add()... So it is ambiguous where to stop restore
+ * scroll position.
+ */
+ repairOnReAddAllRowsDataScrollPositionItemIndex = -1;
}
- scrollRepairOnReAdding.resetItemId();
- scrollRepairOnReAdding.setContainerData(event.getContainer());
}
// ensure that page still has first item in page, ignore buffer refresh