--- /dev/null
+package com.vaadin.tests.components.table;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+public class ColumnWidthsAfterChangeTableColumnsCountOrOrder extends
+ AbstractTestUI {
+
+ protected static final String BUTTON_CHANGE_ORDER_AND_WIDTH_ID = "buttonChangeOrderAndWidth";
+ protected static final String BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH = "buttonChangeColumnCountAndWidth";
+ protected static final int NEW_COLUMN_WIDTH = 17;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ List<TestBean> beanList = new ArrayList<TestBean>();
+ beanList.add(new TestBean(1, "name1", "descr1"));
+ beanList.add(new TestBean(2, "name2", "descr2"));
+ beanList.add(new TestBean(3, "name3", "descr3"));
+ beanList.add(new TestBean(4, "name4", "descr4"));
+ beanList.add(new TestBean(5, "name5", "descr5"));
+
+ BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
+ TestBean.class, beanList);
+
+ VerticalLayout layout = new VerticalLayout();
+
+ final Table table = new Table("Test Table");
+ table.setContainerDataSource(container);
+ table.setVisibleColumns(new Object[] { "id", "name", "descr" });
+ layout.addComponent(table);
+
+ Button buttonChangeOrderAndWidth = new Button("Change order and width",
+ new Button.ClickListener() {
+ @Override
+ public void buttonClick(Button.ClickEvent clickEvent) {
+ table.setVisibleColumns(new Object[] { "name", "descr",
+ "id" });
+ table.setColumnWidth("descr", NEW_COLUMN_WIDTH);
+ }
+ });
+ buttonChangeOrderAndWidth.setId(BUTTON_CHANGE_ORDER_AND_WIDTH_ID);
+
+ Button buttonChangeColumnCountAndWidth = new Button(
+ "Change columns count and width", new Button.ClickListener() {
+ @Override
+ public void buttonClick(Button.ClickEvent clickEvent) {
+ table.setVisibleColumns(new Object[] { "name", "descr" });
+ table.setColumnWidth("descr", NEW_COLUMN_WIDTH);
+ }
+ });
+ buttonChangeColumnCountAndWidth
+ .setId(BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH);
+
+ layout.addComponent(buttonChangeOrderAndWidth);
+ layout.addComponent(buttonChangeColumnCountAndWidth);
+
+ addComponents(layout);
+ }
+
+ public class TestBean {
+ private int id;
+ private String name;
+ private String descr;
+
+ public TestBean(int id, String name, String descr) {
+ this.id = id;
+ this.name = name;
+ this.descr = descr;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescr() {
+ return descr;
+ }
+
+ public void setDescr(String descr) {
+ this.descr = descr;
+ }
+
+ @Override
+ public String toString() {
+ return "TestBean{" + "id=" + id + ", name='" + name + '\''
+ + ", descr='" + descr + '\'' + '}';
+ }
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Tests that properties of columns are changed correctly after changing column's order/count";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 9781;
+ }
+
+}
--- /dev/null
+/*
+ * 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.table;
+
+import static com.vaadin.tests.components.table.ColumnWidthsAfterChangeTableColumnsCountOrOrder.BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH;
+import static com.vaadin.tests.components.table.ColumnWidthsAfterChangeTableColumnsCountOrOrder.BUTTON_CHANGE_ORDER_AND_WIDTH_ID;
+import static com.vaadin.tests.components.table.ColumnWidthsAfterChangeTableColumnsCountOrOrder.NEW_COLUMN_WIDTH;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ColumnWidthsAfterChangeTableColumnsCountOrOrderTest extends
+ MultiBrowserTest {
+
+ @Test
+ public void testColumnWidthAfterChangeTableColumnsOrder() {
+ openTestURL();
+
+ getButtonChangeOrderAndWidth().click();
+
+ waitForElementPresent(By.className("v-table"));
+
+ assertEquals("The width of descr column should be " + NEW_COLUMN_WIDTH,
+ NEW_COLUMN_WIDTH, getDescriptionColumnWidth());
+ }
+
+ @Test
+ public void testColumnWidthAfterChangeTableColumnsCount() {
+ openTestURL();
+
+ getButtonChangeColumnCountAndWidth().click();
+
+ waitForElementPresent(By.className("v-table"));
+
+ assertEquals("The width of descr column should be " + NEW_COLUMN_WIDTH,
+ NEW_COLUMN_WIDTH, getDescriptionColumnWidth());
+ }
+
+ private WebElement getButtonChangeOrderAndWidth() {
+ return vaadinElementById(BUTTON_CHANGE_ORDER_AND_WIDTH_ID);
+ }
+
+ private WebElement getButtonChangeColumnCountAndWidth() {
+ return vaadinElementById(BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH);
+ }
+
+ private int getDescriptionColumnWidth() {
+ return driver
+ .findElement(
+ By.xpath("//div[@class='v-table-cell-wrapper'"
+ + " and text() = 'descr1']")).getSize()
+ .getWidth();
+ }
+
+}