}
}
+ /**
+ * 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;
+ }
}
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;
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> {
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";