summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSara Seppola <sara@vaadin.com>2014-10-28 16:42:35 +0200
committerVaadin Code Review <review@vaadin.com>2014-10-29 15:37:43 +0000
commit7237b88645a27b157bc85d62292dc93faddd19f9 (patch)
tree31404f96d2b1379b8b857dc030dde97a21a7a464
parentf7aac96eeba4c2731d2188f7fe93068ff44ed2f7 (diff)
downloadvaadin-framework-7237b88645a27b157bc85d62292dc93faddd19f9.tar.gz
vaadin-framework-7237b88645a27b157bc85d62292dc93faddd19f9.zip
Table column width can be changed from defined to expandratio (#15101)
Change-Id: I8dead7fd77b44c8adc5e973f29d5e14bae6fb293
-rw-r--r--client/src/com/vaadin/client/ui/VScrollTable.java1
-rw-r--r--uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java110
-rw-r--r--uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java88
3 files changed, 199 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java
index 42fef9f0c0..9c02d30a04 100644
--- a/client/src/com/vaadin/client/ui/VScrollTable.java
+++ b/client/src/com/vaadin/client/ui/VScrollTable.java
@@ -3630,6 +3630,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
c.setWidth(widthWithoutAddedIndent, true);
}
} else if (col.hasAttribute("er")) {
+ c.setUndefinedWidth();
c.setExpandRatio(col.getFloatAttribute("er"));
} else if (recalcWidths) {
diff --git a/uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java b/uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java
new file mode 100644
index 0000000000..92c9b8d988
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java
@@ -0,0 +1,110 @@
+/*
+ * 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 java.util.Arrays;
+
+import com.vaadin.annotations.PreserveOnRefresh;
+import com.vaadin.annotations.Theme;
+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.Button.ClickEvent;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+@PreserveOnRefresh
+@Theme("valo")
+public class TableExpandRatio extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ BeanItemContainer<MyItem> container = new BeanItemContainer<TableExpandRatio.MyItem>(
+ MyItem.class, Arrays.asList(new MyItem("one", 1), new MyItem(
+ "two", 2)));
+
+ final Table table = new Table(null, container);
+
+ table.setWidth("800px");
+ table.setImmediate(true);
+
+ Button widthButton = new Button("Set Width",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ table.setColumnWidth("value", 300);
+
+ }
+ });
+
+ Button expandButton = new Button("Set Expand Ratio",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ table.setColumnExpandRatio("value", 1);
+
+ }
+ });
+
+ widthButton.setId("widthbutton");
+ expandButton.setId("expandbutton");
+
+ VerticalLayout layout = new VerticalLayout(widthButton, expandButton,
+ table);
+ addComponent(layout);
+ }
+
+ public class MyItem {
+
+ private String name;
+ private Integer value;
+
+ public MyItem(String name, Integer value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Integer getValue() {
+ return value;
+ }
+
+ public void setValue(Integer value) {
+ this.value = value;
+ }
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "When a column has fixed width and it is changed to expand ratio, the width should update accordingly";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15101;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java b/uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java
new file mode 100644
index 0000000000..3cf66d4e4b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.number.IsCloseTo.closeTo;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TableExpandRatioTest extends MultiBrowserTest {
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+
+ openTestURL();
+ }
+
+ /*
+ * Needed for IE to get focus when button is clicked
+ */
+ @Override
+ protected boolean requireWindowFocusForIE() {
+
+ return true;
+ }
+
+ @Test
+ public void cellWidthUpdatesWhenExpandRatioSetAfterDefinedWidth() {
+
+ // test that after setting defined size to the second column, the first
+ // column will have correct size
+
+ setDefinedWidth();
+
+ assertThat(getFirstCellWidth(), closeTo(500, 10));
+
+ // test that after setting expandratio to the second column, it is
+ // correct
+
+ setExpandRatio();
+
+ assertThat(getFirstCellWidth(), closeTo(65, 5));
+
+ }
+
+ private void setExpandRatio() {
+ $(ButtonElement.class).id("expandbutton").click();
+ }
+
+ private void setDefinedWidth() {
+ $(ButtonElement.class).id("widthbutton").click();
+ }
+
+ private double getFirstCellWidth() {
+
+ List<WebElement> rows = $(TableElement.class).first()
+ .findElement(By.className("v-table-body"))
+ .findElements(By.tagName("tr"));
+ WebElement firstrow = rows.get(0);
+ List<WebElement> cells = firstrow.findElements(By
+ .className("v-table-cell-content"));
+
+ int cellwidth = cells.get(0).getSize().getWidth();
+ return cellwidth;
+ }
+}