summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-02-22 16:23:49 +0200
committerArtur Signell <artur@vaadin.com>2013-02-22 16:24:06 +0200
commitfbdc52551e258d938db2e230366ca0e21d35c5bc (patch)
tree640740bcb63c2757facc9f19748a65eb46b50174 /server
parentd9a8a21a62b977e32b65bcf436bbd229c9b798f4 (diff)
parent7af5b3fceb75b6f505a9a6d0a843b788bb06d9a7 (diff)
downloadvaadin-framework-fbdc52551e258d938db2e230366ca0e21d35c5bc.tar.gz
vaadin-framework-fbdc52551e258d938db2e230366ca0e21d35c5bc.zip
Merge remote-tracking branch 'origin/7.0'
Change-Id: Id48ccb3c400a78cddb8bb5c7bbcf2d65174e59d0
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/CheckBox.java7
-rw-r--r--server/src/com/vaadin/ui/ProgressIndicator.java15
-rw-r--r--server/src/com/vaadin/ui/Slider.java16
-rw-r--r--server/src/com/vaadin/ui/Tree.java27
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java62
5 files changed, 127 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java
index 22b90b224f..0ace0a4f26 100644
--- a/server/src/com/vaadin/ui/CheckBox.java
+++ b/server/src/com/vaadin/ui/CheckBox.java
@@ -110,6 +110,13 @@ public class CheckBox extends AbstractField<Boolean> {
return (CheckBoxState) super.getState();
}
+ /*
+ * Overridden to keep the shared state in sync with the AbstractField
+ * internal value. Should be removed once AbstractField is refactored to use
+ * shared state.
+ *
+ * See tickets #10921 and #11064.
+ */
@Override
protected void setInternalValue(Boolean newValue) {
super.setInternalValue(newValue);
diff --git a/server/src/com/vaadin/ui/ProgressIndicator.java b/server/src/com/vaadin/ui/ProgressIndicator.java
index 96c2d2814a..c481aa1e8f 100644
--- a/server/src/com/vaadin/ui/ProgressIndicator.java
+++ b/server/src/com/vaadin/ui/ProgressIndicator.java
@@ -157,4 +157,19 @@ public class ProgressIndicator extends AbstractField<Float> implements
return getState().pollingInterval;
}
+ /*
+ * Overridden to keep the shared state in sync with the AbstractField
+ * internal value. Should be removed once AbstractField is refactored to use
+ * shared state.
+ *
+ * See tickets #10921 and #11064.
+ */
+ @Override
+ protected void setInternalValue(Float newValue) {
+ super.setInternalValue(newValue);
+ if (newValue == null) {
+ newValue = 0.0f;
+ }
+ getState().state = newValue;
+ }
}
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java
index 2bf05f895c..e63fdc5e10 100644
--- a/server/src/com/vaadin/ui/Slider.java
+++ b/server/src/com/vaadin/ui/Slider.java
@@ -263,6 +263,22 @@ public class Slider extends AbstractField<Double> {
getState().value = newFieldValue;
}
+ /*
+ * Overridden to keep the shared state in sync with the AbstractField
+ * internal value. Should be removed once AbstractField is refactored to use
+ * shared state.
+ *
+ * See tickets #10921 and #11064.
+ */
+ @Override
+ protected void setInternalValue(Double newValue) {
+ super.setInternalValue(newValue);
+ if (newValue == null) {
+ newValue = 0.0;
+ }
+ getState().value = newValue;
+ }
+
/**
* Thrown when the value of the slider is about to be set to a value that is
* outside the valid range of the slider.
diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java
index 608c947d59..32c5712f0f 100644
--- a/server/src/com/vaadin/ui/Tree.java
+++ b/server/src/com/vaadin/ui/Tree.java
@@ -414,6 +414,9 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
final Object id = itemIdMapper.get(keys[i]);
if (id != null && isExpanded(id)) {
expanded.remove(id);
+ if (expandedItemId == id) {
+ expandedItemId = null;
+ }
fireCollapseEvent(id);
}
}
@@ -841,6 +844,10 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
super.setContainerDataSource(new ContainerHierarchicalWrapper(
newDataSource));
}
+
+ // Ensure previous expanded items are cleaned up if they don't exist in
+ // the new container
+ cleanupExpandedItems();
}
/* Expand event and listener */
@@ -1670,4 +1677,24 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
return itemDescriptionGenerator;
}
+ @Override
+ public void containerItemSetChange(
+ com.vaadin.data.Container.ItemSetChangeEvent event) {
+
+ // Ensure removed items are cleaned up from expanded list
+ cleanupExpandedItems();
+
+ super.containerItemSetChange(event);
+ }
+
+ private void cleanupExpandedItems() {
+ for (Object expandedItemId : expanded) {
+ if (getItem(expandedItemId) == null) {
+ expanded.remove(expandedItemId);
+ if (this.expandedItemId == expandedItemId) {
+ this.expandedItemId = null;
+ }
+ }
+ }
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java
index 16a7091947..c1d7653c01 100644
--- a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java
@@ -1,5 +1,8 @@
package com.vaadin.tests.server.component.tree;
+import java.lang.reflect.Field;
+import java.util.HashSet;
+
import junit.framework.TestCase;
import com.vaadin.data.Container;
@@ -71,4 +74,63 @@ public class TreeTest extends TestCase {
assertTrue(Container.Hierarchical.class.isAssignableFrom(tree4
.getContainerDataSource().getClass()));
}
+
+ public void testRemoveExpandedItems() throws Exception {
+ tree.expandItem("parent");
+ tree.expandItem("child");
+
+ Field expandedField = tree.getClass()
+ .getDeclaredField("expanded");
+ Field expandedItemIdField = tree.getClass().getDeclaredField(
+ "expandedItemId");
+
+ expandedField.setAccessible(true);
+ expandedItemIdField.setAccessible(true);
+
+ HashSet<Object> expanded = (HashSet<Object>) expandedField.get(tree);
+ Object expandedItemId = expandedItemIdField.get(tree);
+
+ assertEquals(2, expanded.size());
+ assertTrue("Contains parent", expanded.contains("parent"));
+ assertTrue("Contains child", expanded.contains("child"));
+ assertEquals("child", expandedItemId);
+
+ tree.removeItem("parent");
+
+ expanded = (HashSet<Object>) expandedField.get(tree);
+ expandedItemId = expandedItemIdField.get(tree);
+
+ assertEquals(1, expanded.size());
+ assertTrue("Contains child", expanded.contains("child"));
+ assertEquals("child", expandedItemId);
+
+ tree.removeItem("child");
+
+ expanded = (HashSet<Object>) expandedField.get(tree);
+ expandedItemId = expandedItemIdField.get(tree);
+
+ assertEquals(0, expanded.size());
+ assertNull(expandedItemId);
+ }
+
+ public void testRemoveExpandedItemsOnContainerChange() throws Exception {
+ tree.expandItem("parent");
+ tree.expandItem("child");
+
+ tree.setContainerDataSource(new HierarchicalContainer());
+
+ Field expandedField = tree.getClass().getDeclaredField("expanded");
+ Field expandedItemIdField = tree.getClass().getDeclaredField(
+ "expandedItemId");
+
+ expandedField.setAccessible(true);
+ expandedItemIdField.setAccessible(true);
+
+ HashSet<Object> expanded = (HashSet<Object>) expandedField.get(tree);
+ assertEquals(0, expanded.size());
+
+ Object expandedItemId = expandedItemIdField.get(tree);
+ assertNull(expandedItemId);
+ }
+
}