summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/com/vaadin/ui/ComponentRootSetter.java20
-rw-r--r--server/src/main/java/com/vaadin/ui/declarative/Design.java4
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java29
3 files changed, 51 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/ui/ComponentRootSetter.java b/server/src/main/java/com/vaadin/ui/ComponentRootSetter.java
index 8deb2d91cb..aea60e0f41 100644
--- a/server/src/main/java/com/vaadin/ui/ComponentRootSetter.java
+++ b/server/src/main/java/com/vaadin/ui/ComponentRootSetter.java
@@ -51,4 +51,24 @@ public class ComponentRootSetter implements Serializable {
}
}
+ /**
+ * Checks if the given custom component or composite may accept a root component.
+ * <p>
+ * For internal use only.
+ *
+ * @param customComponent
+ * the custom component or composite
+ * @return
+ * @since
+ *
+ */
+ public static boolean canSetRoot(Component customComponent) {
+ if(customComponent instanceof CustomComponent) {
+ return true;
+ }
+ if(customComponent instanceof Composite) {
+ return ((Composite)customComponent).getCompositionRoot() == null;
+ }
+ return false;
+ }
}
diff --git a/server/src/main/java/com/vaadin/ui/declarative/Design.java b/server/src/main/java/com/vaadin/ui/declarative/Design.java
index b7be276ec0..789f6c8a7b 100644
--- a/server/src/main/java/com/vaadin/ui/declarative/Design.java
+++ b/server/src/main/java/com/vaadin/ui/declarative/Design.java
@@ -495,8 +495,8 @@ public class Design implements Serializable {
designContext.addComponentCreationListener(creationListener);
// create subtree
- if (componentRoot instanceof CustomComponent
- || componentRoot instanceof Composite) {
+
+ if (ComponentRootSetter.canSetRoot(componentRoot)) {
Component rootComponent = designContext.readDesign(element);
ComponentRootSetter.setRoot(componentRoot, rootComponent);
} else {
diff --git a/server/src/test/java/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java
index b2c0c8ae21..0e51c93d1d 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java
@@ -1,9 +1,13 @@
package com.vaadin.tests.server.component.tree;
+import java.io.ByteArrayInputStream;
+
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import com.vaadin.data.SelectionModel;
import com.vaadin.data.TreeData;
import com.vaadin.data.provider.HierarchicalQuery;
import com.vaadin.shared.ui.ContentMode;
@@ -13,6 +17,7 @@ import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.IconGenerator;
import com.vaadin.ui.ItemCaptionGenerator;
import com.vaadin.ui.Tree;
+import com.vaadin.ui.declarative.Design;
public class TreeDeclarativeTest
extends AbstractComponentDeclarativeTestBase<Tree> {
@@ -140,6 +145,30 @@ public class TreeDeclarativeTest
testWrite(design, tree);
}
+ @Test
+ public void testUpdateExisting() {
+ Tree tree = new Tree();
+
+ String treeDesign =
+ "<vaadin-tree selection-mode=\"MULTI\">" +
+ "<node item=\"A\">A</node>" +
+ "<node item=\"B\">B</node>" +
+ "<node item=\"AA\" parent=\"A\">AA</node>" +
+ "</vaadin-tree>";
+
+ Design.read(new ByteArrayInputStream(treeDesign.getBytes()), tree);
+ Object[] items = tree.getDataProvider().
+ fetchChildren(new HierarchicalQuery(null, null)).toArray();
+ assertArrayEquals(new Object[]{"A", "B"}, items);
+ Object[] itemsA = tree.getDataProvider().
+ fetchChildren(new HierarchicalQuery(null, "A")).toArray();
+ assertArrayEquals(new Object[]{"AA"}, itemsA);
+ long countB = tree.getDataProvider().
+ fetchChildren(new HierarchicalQuery(null, "B")).count();
+ assertEquals(0L, countB);
+ assertTrue(tree.getSelectionModel() instanceof SelectionModel.Multi);
+ }
+
@Override
protected String getComponentTag() {
return "vaadin-tree";