diff options
author | Johannes Tuikkala <johannes@vaadin.com> | 2015-01-12 10:18:42 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2015-01-21 11:04:19 +0200 |
commit | 3a664059d5f7b28930ca50ba70026c3595dfea2d (patch) | |
tree | 441ea682b85db45b447c2cb5ea2a25a17cf31012 | |
parent | c72d60ba1ff38db9ede283f91ed657419dc79619 (diff) | |
download | vaadin-framework-3a664059d5f7b28930ca50ba70026c3595dfea2d.tar.gz vaadin-framework-3a664059d5f7b28930ca50ba70026c3595dfea2d.zip |
Fix for: TreeTable with ContainerHierarchicalWrapper not correctly
displaying child items (#15421)
Change-Id: Iadf1faa979fbae412b55551c6622b0429039a21c
3 files changed, 151 insertions, 0 deletions
diff --git a/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java index 0bfec33957..199d186fab 100644 --- a/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java +++ b/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java @@ -450,6 +450,8 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, // Update parent parent.remove(itemId); + fireItemSetChangeIfAbstractContainer(); + return true; } @@ -490,10 +492,22 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, } } + fireItemSetChangeIfAbstractContainer(); + return true; } /** + * inform container (if it is instance of AbstractContainer) about the + * change in hierarchy (#15421) + */ + private void fireItemSetChangeIfAbstractContainer() { + if (container instanceof AbstractContainer) { + ((AbstractContainer) container).fireItemSetChange(); + } + } + + /** * Creates a new Item into the Container, assigns it an automatic ID, and * adds it to the hierarchy. * diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableContainerHierarchicalWrapper.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableContainerHierarchicalWrapper.java new file mode 100644 index 0000000000..95f8c54e9e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableContainerHierarchicalWrapper.java @@ -0,0 +1,82 @@ +package com.vaadin.tests.components.treetable; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.data.util.ContainerHierarchicalWrapper; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Tree.ExpandEvent; +import com.vaadin.ui.Tree.ExpandListener; +import com.vaadin.ui.TreeTable; + +@SuppressWarnings("serial") +public class TreeTableContainerHierarchicalWrapper extends AbstractTestUI { + + TreeTable treetable = new TreeTable(); + BeanItemContainer<Bean> beanContainer = new BeanItemContainer<Bean>( + Bean.class); + ContainerHierarchicalWrapper hierarchicalWrapper = new ContainerHierarchicalWrapper( + beanContainer); + + @Override + protected void setup(VaadinRequest request) { + treetable = new TreeTable(); + treetable.setImmediate(true); + treetable.setWidth("100%"); + treetable.setHeight(null); + treetable.setPageLength(0); + treetable.setContainerDataSource(hierarchicalWrapper); + + treetable.addExpandListener(new ExpandListener() { + @Override + public void nodeExpand(ExpandEvent event) { + Bean parent = ((Bean) event.getItemId()); + if (!hierarchicalWrapper.hasChildren(parent)) { + for (int i = 1; i <= 5; i++) { + Bean newChild = new Bean(parent.getId() + "-" + i); + beanContainer.addBean(newChild); + hierarchicalWrapper.setParent(newChild, parent); + } + } + + } + }); + + for (int i = 0; i < 3; i++) { + beanContainer.addBean(new Bean("Item " + i)); + } + + addComponent(treetable); + } + + public class Bean { + public static final String PROP_ID = "id"; + private String id; + + public Bean() { + // empty + } + + public Bean(String id) { + this.id = id; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + } + + @Override + protected String getTestDescription() { + return "Tests that TreeTable with ContainerHierarchicalWrapper is updated correctly when the setParent() is called for the item just added"; + } + + @Override + protected Integer getTicketNumber() { + return 15421; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableContainerHierarchicalWrapperTest.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableContainerHierarchicalWrapperTest.java new file mode 100644 index 0000000000..f767e5fd52 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableContainerHierarchicalWrapperTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.treetable; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.TreeTableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that TreeTable with ContainerHierarchicalWrapper is updated correctly + * when the setParent() is called for the item just added + * + * @author Vaadin Ltd + */ +public class TreeTableContainerHierarchicalWrapperTest extends MultiBrowserTest { + + @Test + public void testStructure() throws InterruptedException { + openTestURL(); + + TreeTableElement treeTable = $(TreeTableElement.class).first(); + WebElement findElement = treeTable.getCell(0, 0).findElement( + By.className("v-treetable-treespacer")); + findElement.click(); + + TestBenchElement cell = treeTable.getCell(5, 0); + WebElement findElement2 = cell.findElement(By + .className("v-treetable-treespacer")); + assertEquals("Item 0-5", cell.getText()); + findElement2.click(); + + TestBenchElement cell2 = treeTable.getCell(10, 0); + assertEquals("Item 0-5-5", cell2.getText()); + } + +} |