From: Denis Anisimov Date: Thu, 13 Mar 2014 06:56:31 +0000 (+0200) Subject: Set explicit left alignment instead of removing text-align style (#13399). X-Git-Tag: 7.2.0~13^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c98286e22c32b56a75b21d629c8b5968856d1ae1;p=vaadin-framework.git Set explicit left alignment instead of removing text-align style (#13399). Change-Id: I3407555739ff443055e2e61aa14327d44a65cd8e --- diff --git a/WebContent/VAADIN/themes/tests-table/styles.css b/WebContent/VAADIN/themes/tests-table/styles.css new file mode 100644 index 0000000000..78193c0982 --- /dev/null +++ b/WebContent/VAADIN/themes/tests-table/styles.css @@ -0,0 +1,5 @@ +@import url(../reindeer/legacy-styles.css); + +.v-table-footer-container, .v-table-cell-wrapper { + text-align: center; +} diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 38f8ff8644..b0cd614e42 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3843,7 +3843,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, "right"); break; default: - DOM.setStyleAttribute(captionContainer, "textAlign", ""); + DOM.setStyleAttribute(captionContainer, "textAlign", "left"); break; } } @@ -5407,17 +5407,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } else { container.setInnerText(text); } - if (align != ALIGN_LEFT) { - switch (align) { - case ALIGN_CENTER: - container.getStyle().setProperty("textAlign", "center"); - break; - case ALIGN_RIGHT: - default: - container.getStyle().setProperty("textAlign", "right"); - break; - } - } + setAlign(align, container); setTooltip(td, description); td.appendChild(container); @@ -5455,6 +5445,21 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } + private void setAlign(char align, final Element container) { + switch (align) { + case ALIGN_CENTER: + container.getStyle().setProperty("textAlign", "center"); + break; + case ALIGN_LEFT: + container.getStyle().setProperty("textAlign", "left"); + break; + case ALIGN_RIGHT: + default: + container.getStyle().setProperty("textAlign", "right"); + break; + } + } + protected void initCellWithWidget(Widget w, char align, String style, boolean sorted, final TableCellElement td) { final Element container = DOM.createDiv(); @@ -5471,21 +5476,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, td.setClassName(className); container.setClassName(VScrollTable.this.getStylePrimaryName() + "-cell-wrapper"); - // TODO most components work with this, but not all (e.g. - // Select) - // Old comment: make widget cells respect align. - // text-align:center for IE, margin: auto for others - if (align != ALIGN_LEFT) { - switch (align) { - case ALIGN_CENTER: - container.getStyle().setProperty("textAlign", "center"); - break; - case ALIGN_RIGHT: - default: - container.getStyle().setProperty("textAlign", "right"); - break; - } - } + setAlign(align, container); td.appendChild(container); getElement().appendChild(td); // ensure widget not attached to another element (possible tBody diff --git a/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java b/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java new file mode 100644 index 0000000000..e783951d86 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignment.java @@ -0,0 +1,90 @@ +/* + * 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 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.Button.ClickListener; +import com.vaadin.ui.Table; +import com.vaadin.ui.Table.Align; + +/** + * Test UI for issue #13399 : Left alignment should not be set explicitly + * instead of relying on default behavior + * + * @author Vaadin Ltd + */ +@Theme("tests-table") +public class LeftColumnAlignment extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Table table = new Table(); + + BeanItemContainer container = new BeanItemContainer( + Bean.class); + Bean bean = new Bean(); + bean.setName("property"); + container.addBean(bean); + table.setContainerDataSource(container); + + table.setFooterVisible(true); + + table.setWidth(100, Unit.PIXELS); + + table.setColumnAlignment("name", Align.RIGHT); + + addComponent(table); + + Button button = new Button("Align to Left"); + button.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + table.setColumnAlignment("name", Align.LEFT); + } + }); + addComponent(button); + } + + @Override + protected String getTestDescription() { + return "Left alignment should not be set explicitly instead of relying on default behavior"; + } + + @Override + protected Integer getTicketNumber() { + return 13399; + } + + public static class Bean { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + } + +} diff --git a/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignmentTest.java b/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignmentTest.java new file mode 100644 index 0000000000..3d613fd726 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/LeftColumnAlignmentTest.java @@ -0,0 +1,58 @@ +/* + * 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 org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test class for issue #13399 : Left alignment should not be set explicitly + * instead of relying on default behavior + * + * @author Vaadin Ltd + */ +public class LeftColumnAlignmentTest extends MultiBrowserTest { + + @Test + public void testLeftColumnAlignment() throws Exception { + openTestURL(); + + // Do align columns to the left + WebElement webElement = driver.findElement(By.className("v-button")); + webElement.click(); + + Assert.assertTrue("Table caption is not aligned to the left", + isElementPresent(By + .className("v-table-caption-container-align-left"))); + + WebElement footer = driver.findElement(By + .className("v-table-footer-container")); + + Assert.assertEquals("Table footer is not aligned to the left", "left", + footer.getCssValue("text-align")); + + WebElement cell = driver.findElement(By + .className("v-table-cell-wrapper")); + + Assert.assertEquals("Table cell is not aligned to the left", "left", + cell.getCssValue("text-align")); + } + +}