--- /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.grid.basicfeatures;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.UI;
+
+/**
+ * Initializer shell for GridClientBasicFeatures test application
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+@Widgetset(TestingWidgetSet.NAME)
+public class GridBasicClientFeatures extends UI {
+
+ public class GridTestComponent extends AbstractComponent {
+ }
+
+ @Override
+ protected void init(VaadinRequest request) {
+ setContent(new GridTestComponent());
+ }
+
+}
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
-import com.vaadin.tests.widgetset.server.grid.GridBasicClientFeatures;
-
/**
* Variant of GridBasicFeaturesTest to be used with GridBasicClientFeatures.
*
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeatures;
-
-public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest {
-
- @Test
- public void initialColumnWidths() {
- openTestURL();
-
- for (int col = 0; col < GridBasicClientFeatures.COLUMNS; col++) {
- int width = getGridElement().getCell(0, col).getSize().getWidth();
- if (col <= 6) {
- // Growing column widths
- assertEquals(50 + col * 25, width);
- } else {
- assertEquals(100, width);
- }
- }
- }
-
- @Test
- public void testChangingColumnWidth() {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
- int width = getGridElement().getCell(0, 0).getSize().getWidth();
- assertEquals(50, width);
-
- selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
- width = getGridElement().getCell(0, 0).getSize().getWidth();
- assertEquals(200, width);
-
- selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
- width = getGridElement().getCell(0, 0).getSize().getWidth();
- assertEquals(100, width);
- }
-
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
-
- @Test
- public void testChangeSelectionMode() {
- openTestURL();
-
- selectMenuPath("Component", "State", "Selection mode", "none");
- assertTrue("First column was selection column", getGridElement()
- .getCell(0, 0).getText().equals("(0, 0)"));
- selectMenuPath("Component", "State", "Selection mode", "multi");
- assertTrue("First column was not selection column", getGridElement()
- .getCell(0, 1).getText().equals("(0, 0)"));
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.WebElement;
-
-import com.vaadin.tests.components.grid.GridElement.GridCellElement;
-
-public class GridFooterTest extends GridStaticSectionTest {
-
- @Test
- public void testDefaultFooter() {
- openTestURL();
-
- // Footer should have zero rows by default
- assertFooterCount(0);
- }
-
- @Test
- public void testFooterVisibility() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Visible");
-
- assertFooterCount(0);
-
- selectMenuPath("Component", "Footer", "Append row");
-
- assertFooterCount(0);
-
- selectMenuPath("Component", "Footer", "Visible");
-
- assertFooterCount(1);
- }
-
- @Test
- public void testAddRows() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- assertFooterCount(1);
- assertFooterTexts(0, 0);
-
- selectMenuPath("Component", "Footer", "Prepend row");
-
- assertFooterCount(2);
- assertFooterTexts(1, 0);
- assertFooterTexts(0, 1);
-
- selectMenuPath("Component", "Footer", "Append row");
-
- assertFooterCount(3);
- assertFooterTexts(1, 0);
- assertFooterTexts(0, 1);
- assertFooterTexts(2, 2);
- }
-
- @Test
- public void testRemoveRows() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Prepend row");
- selectMenuPath("Component", "Footer", "Append row");
-
- selectMenuPath("Component", "Footer", "Remove top row");
-
- assertFooterCount(1);
- assertFooterTexts(1, 0);
-
- selectMenuPath("Component", "Footer", "Remove bottom row");
- assertFooterCount(0);
- }
-
- @Test
- public void joinColumnsByCells() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- selectMenuPath("Component", "Footer", "Row 1", "Join column cells 0, 1");
-
- GridCellElement spannedCell = getGridElement().getFooterCell(0, 0);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("2", spannedCell.getAttribute("colspan"));
-
- GridCellElement hiddenCell = getGridElement().getFooterCell(0, 1);
- assertFalse(hiddenCell.isDisplayed());
- }
-
- @Test
- public void joinColumnsByColumns() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2");
-
- GridCellElement spannedCell = getGridElement().getFooterCell(0, 1);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("2", spannedCell.getAttribute("colspan"));
-
- GridCellElement hiddenCell = getGridElement().getFooterCell(0, 2);
- assertFalse(hiddenCell.isDisplayed());
- }
-
- @Test
- public void joinAllColumnsInRow() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- selectMenuPath("Component", "Footer", "Row 1", "Join all columns");
-
- GridCellElement spannedCell = getGridElement().getFooterCell(0, 0);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("" + GridBasicFeatures.COLUMNS,
- spannedCell.getAttribute("colspan"));
-
- for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) {
- GridCellElement hiddenCell = getGridElement().getFooterCell(0,
- columnIndex);
- assertFalse(hiddenCell.isDisplayed());
- }
- }
-
- @Test
- public void testInitialCellTypes() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- GridCellElement textCell = getGridElement().getFooterCell(0, 0);
- assertEquals("Footer (0,0)", textCell.getText());
-
- GridCellElement widgetCell = getGridElement().getFooterCell(0, 1);
- assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML")));
-
- GridCellElement htmlCell = getGridElement().getFooterCell(0, 2);
- assertHTML("<b>Footer (0,2)</b>", htmlCell);
- }
-
- @Test
- public void testDynamicallyChangingCellType() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- selectMenuPath("Component", "Columns", "Column 0", "Footer Type",
- "Widget Footer");
- GridCellElement widgetCell = getGridElement().getFooterCell(0, 0);
- assertTrue(widgetCell.isElementPresent(By.className("gwt-Button")));
-
- selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
- "HTML Footer");
- GridCellElement htmlCell = getGridElement().getFooterCell(0, 1);
- assertHTML("<b>HTML Footer</b>", htmlCell);
-
- selectMenuPath("Component", "Columns", "Column 2", "Footer Type",
- "Text Footer");
- GridCellElement textCell = getGridElement().getFooterCell(0, 2);
- assertEquals("Text Footer", textCell.getText());
- }
-
- @Test
- public void testCellWidgetInteraction() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Append row");
-
- selectMenuPath("Component", "Columns", "Column 0", "Footer Type",
- "Widget Footer");
- GridCellElement widgetCell = getGridElement().getFooterCell(0, 0);
- WebElement button = widgetCell.findElement(By.className("gwt-Button"));
-
- assertNotEquals("Clicked", button.getText());
-
- button.click();
-
- assertEquals("Clicked", button.getText());
- }
-
- private void assertFooterCount(int count) {
- assertEquals("footer count", count, getGridElement().getFooterCount());
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.WebElement;
-
-import com.vaadin.testbench.TestBenchElement;
-import com.vaadin.tests.components.grid.GridElement.GridCellElement;
-
-public class GridHeaderTest extends GridStaticSectionTest {
-
- @Test
- public void testDefaultHeader() throws Exception {
- openTestURL();
-
- assertHeaderCount(1);
- assertHeaderTexts(0, 0);
- }
-
- @Test
- public void testHeaderVisibility() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Visible");
-
- assertHeaderCount(0);
-
- selectMenuPath("Component", "Header", "Append row");
-
- assertHeaderCount(0);
-
- selectMenuPath("Component", "Header", "Visible");
-
- assertHeaderCount(2);
- }
-
- @Test
- public void testHeaderCaptions() throws Exception {
- openTestURL();
-
- assertHeaderTexts(0, 0);
- }
-
- @Test
- public void testHeadersWithInvisibleColumns() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 1", "Visible");
- selectMenuPath("Component", "Columns", "Column 3", "Visible");
-
- List<TestBenchElement> cells = getGridHeaderRowCells();
- assertEquals(GridBasicFeatures.COLUMNS - 2, cells.size());
-
- assertText("Header (0,0)", cells.get(0));
- assertHTML("<b>Header (0,2)</b>", cells.get(1));
- assertHTML("<b>Header (0,4)</b>", cells.get(2));
-
- selectMenuPath("Component", "Columns", "Column 3", "Visible");
-
- cells = getGridHeaderRowCells();
- assertEquals(GridBasicFeatures.COLUMNS - 1, cells.size());
-
- assertText("Header (0,0)", cells.get(0));
- assertHTML("<b>Header (0,2)</b>", cells.get(1));
- assertText("Header (0,3)", cells.get(2));
- assertHTML("<b>Header (0,4)</b>", cells.get(3));
- }
-
- @Test
- public void testAddRows() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Append row");
-
- assertHeaderCount(2);
- assertHeaderTexts(0, 0);
- assertHeaderTexts(1, 1);
-
- selectMenuPath("Component", "Header", "Prepend row");
-
- assertHeaderCount(3);
- assertHeaderTexts(2, 0);
- assertHeaderTexts(0, 1);
- assertHeaderTexts(1, 2);
-
- selectMenuPath("Component", "Header", "Append row");
-
- assertHeaderCount(4);
- assertHeaderTexts(2, 0);
- assertHeaderTexts(0, 1);
- assertHeaderTexts(1, 2);
- assertHeaderTexts(3, 3);
- }
-
- @Test
- public void testRemoveRows() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Prepend row");
- selectMenuPath("Component", "Header", "Append row");
-
- selectMenuPath("Component", "Header", "Remove top row");
-
- assertHeaderCount(2);
- assertHeaderTexts(0, 0);
- assertHeaderTexts(2, 1);
-
- selectMenuPath("Component", "Header", "Remove bottom row");
- assertHeaderCount(1);
- assertHeaderTexts(0, 0);
- }
-
- @Test
- public void testDefaultRow() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 0", "Sortable");
-
- GridCellElement headerCell = getGridElement().getHeaderCell(0, 0);
-
- headerCell.click();
-
- assertTrue(hasClassName(headerCell, "sort-asc"));
-
- headerCell.click();
-
- assertFalse(hasClassName(headerCell, "sort-asc"));
- assertTrue(hasClassName(headerCell, "sort-desc"));
-
- selectMenuPath("Component", "Header", "Prepend row");
- selectMenuPath("Component", "Header", "Default row", "Top");
-
- assertFalse(hasClassName(headerCell, "sort-desc"));
- headerCell = getGridElement().getHeaderCell(0, 0);
- assertTrue(hasClassName(headerCell, "sort-desc"));
-
- selectMenuPath("Component", "Header", "Default row", "Unset");
-
- assertFalse(hasClassName(headerCell, "sort-desc"));
- }
-
- @Test
- public void joinHeaderColumnsByCells() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Append row");
-
- selectMenuPath("Component", "Header", "Row 2", "Join column cells 0, 1");
-
- GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("2", spannedCell.getAttribute("colspan"));
-
- GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 1);
- assertFalse(hiddenCell.isDisplayed());
- }
-
- @Test
- public void joinHeaderColumnsByColumns() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Append row");
-
- selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2");
-
- GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("2", spannedCell.getAttribute("colspan"));
-
- GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 2);
- assertFalse(hiddenCell.isDisplayed());
- }
-
- @Test
- public void joinAllColumnsInHeaderRow() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Append row");
-
- selectMenuPath("Component", "Header", "Row 2", "Join all columns");
-
- GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("" + GridBasicFeatures.COLUMNS,
- spannedCell.getAttribute("colspan"));
-
- for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) {
- GridCellElement hiddenCell = getGridElement().getHeaderCell(1,
- columnIndex);
- assertFalse(hiddenCell.isDisplayed());
- }
- }
-
- @Test
- public void hideFirstColumnInColspan() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Append row");
-
- selectMenuPath("Component", "Header", "Row 2", "Join all columns");
-
- int visibleColumns = GridBasicFeatures.COLUMNS;
-
- GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("" + visibleColumns, spannedCell.getAttribute("colspan"));
-
- selectMenuPath("Component", "Columns", "Column 0", "Visible");
- visibleColumns--;
-
- spannedCell = getGridElement().getHeaderCell(1, 0);
- assertTrue(spannedCell.isDisplayed());
- assertEquals("" + visibleColumns, spannedCell.getAttribute("colspan"));
- }
-
- @Test
- public void multipleColspanAndMultipleHiddenColumns() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Header", "Append row");
-
- // Join columns [1,2] and [3,4,5]
- selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2");
- GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1);
- assertEquals("2", spannedCell.getAttribute("colspan"));
-
- selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5");
- spannedCell = getGridElement().getHeaderCell(1, 3);
- assertEquals("3", spannedCell.getAttribute("colspan"));
-
- selectMenuPath("Component", "Columns", "Column 2", "Visible");
- spannedCell = getGridElement().getHeaderCell(1, 1);
- assertEquals("1", spannedCell.getAttribute("colspan"));
-
- // Ensure the second colspan is preserved (shifts one index to the left)
- spannedCell = getGridElement().getHeaderCell(1, 2);
- assertEquals("3", spannedCell.getAttribute("colspan"));
-
- selectMenuPath("Component", "Columns", "Column 4", "Visible");
-
- // First reduced colspan is reduced
- spannedCell = getGridElement().getHeaderCell(1, 1);
- assertEquals("1", spannedCell.getAttribute("colspan"));
-
- // Second colspan is also now reduced
- spannedCell = getGridElement().getHeaderCell(1, 2);
- assertEquals("2", spannedCell.getAttribute("colspan"));
-
- // Show columns again
- selectMenuPath("Component", "Columns", "Column 2", "Visible");
- selectMenuPath("Component", "Columns", "Column 4", "Visible");
-
- spannedCell = getGridElement().getHeaderCell(1, 1);
- assertEquals("2", spannedCell.getAttribute("colspan"));
- spannedCell = getGridElement().getHeaderCell(1, 3);
- assertEquals("3", spannedCell.getAttribute("colspan"));
-
- }
-
- @Test
- public void testInitialCellTypes() throws Exception {
- openTestURL();
-
- GridCellElement textCell = getGridElement().getHeaderCell(0, 0);
- assertEquals("Header (0,0)", textCell.getText());
-
- GridCellElement widgetCell = getGridElement().getHeaderCell(0, 1);
- assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML")));
-
- GridCellElement htmlCell = getGridElement().getHeaderCell(0, 2);
- assertHTML("<b>Header (0,2)</b>", htmlCell);
- }
-
- @Test
- public void testDynamicallyChangingCellType() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 0", "Header Type",
- "Widget Header");
- GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
- assertTrue(widgetCell.isElementPresent(By.className("gwt-Button")));
-
- selectMenuPath("Component", "Columns", "Column 1", "Header Type",
- "HTML Header");
- GridCellElement htmlCell = getGridElement().getHeaderCell(0, 1);
- assertHTML("<b>HTML Header</b>", htmlCell);
-
- selectMenuPath("Component", "Columns", "Column 2", "Header Type",
- "Text Header");
- GridCellElement textCell = getGridElement().getHeaderCell(0, 2);
- assertEquals("Text Header", textCell.getText());
- }
-
- @Test
- public void testCellWidgetInteraction() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 0", "Header Type",
- "Widget Header");
- GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
- WebElement button = widgetCell.findElement(By.className("gwt-Button"));
-
- button.click();
-
- assertEquals("Clicked", button.getText());
- }
-
- @Test
- public void widgetInSortableCellInteraction() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 0", "Header Type",
- "Widget Header");
-
- selectMenuPath("Component", "Columns", "Column 0", "Sortable");
-
- GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
- WebElement button = widgetCell.findElement(By.className("gwt-Button"));
-
- assertNotEquals("Clicked", button.getText());
-
- button.click();
-
- assertEquals("Clicked", button.getText());
- }
-
- private void assertHeaderCount(int count) {
- assertEquals("header count", count, getGridElement().getHeaderCount());
- }
-
- private boolean hasClassName(TestBenchElement element, String name) {
- return Arrays.asList(element.getAttribute("class").split(" "))
- .contains(name);
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.Keys;
-import org.openqa.selenium.interactions.Actions;
-
-import com.vaadin.tests.components.grid.GridElement;
-
-public class GridKeyboardNavigationTest extends GridBasicFeaturesTest {
-
- @Test
- public void testCellActiveOnClick() {
- openTestURL();
-
- GridElement grid = getGridElement();
- assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0)
- .isActive());
- grid.getCell(5, 2).click();
- assertFalse("Body cell 0, 0 was still active after clicking", grid
- .getCell(0, 0).isActive());
- assertTrue("Body cell 5, 2 is not active after clicking",
- grid.getCell(5, 2).isActive());
- }
-
- @Test
- public void testCellNotActiveWhenRendererHandlesEvent() {
- openTestURL();
-
- GridElement grid = getGridElement();
- assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0)
- .isActive());
- grid.getHeaderCell(0, 3).click();
- assertFalse("Body cell 0, 0 is active after click on header.", grid
- .getCell(0, 0).isActive());
- assertTrue("Header cell 0, 3 is not active after click on header.",
- grid.getHeaderCell(0, 3).isActive());
- }
-
- @Test
- public void testSimpleKeyboardNavigation() {
- openTestURL();
-
- GridElement grid = getGridElement();
- grid.getCell(0, 0).click();
-
- new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
- assertTrue("Body cell 1, 0 is not active after keyboard navigation.",
- grid.getCell(1, 0).isActive());
-
- new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT).perform();
- assertTrue("Body cell 1, 1 is not active after keyboard navigation.",
- grid.getCell(1, 1).isActive());
-
- int i;
- for (i = 1; i < 40; ++i) {
- new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
- }
-
- assertFalse("Grid has not scrolled with active cell",
- isElementPresent(By.xpath("//td[text() = '(0, 0)']")));
- assertTrue("Active cell is not visible",
- isElementPresent(By.xpath("//td[text() = '(" + i + ", 0)']")));
- assertTrue("Body cell " + i + ", 1 is not active", grid.getCell(i, 1)
- .isActive());
- }
-
- @Test
- public void testNavigateFromHeaderToBody() {
- openTestURL();
-
- GridElement grid = getGridElement();
- grid.scrollToRow(300);
- new Actions(driver).moveToElement(grid.getHeaderCell(0, 7)).click()
- .perform();
- grid.scrollToRow(280);
-
- assertTrue("Header cell is not active.", grid.getHeaderCell(0, 7)
- .isActive());
- new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
- assertTrue("Body cell 280, 7 is not active", grid.getCell(280, 7)
- .isActive());
- }
-
- @Test
- public void testNavigationFromFooterToBody() {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Visible");
-
- GridElement grid = getGridElement();
- grid.scrollToRow(300);
- grid.getFooterCell(0, 2).click();
-
- assertTrue("Footer cell is not active.", grid.getFooterCell(0, 2)
- .isActive());
- new Actions(getDriver()).sendKeys(Keys.ARROW_UP).perform();
- assertTrue("Body cell 300, 2 is not active", grid.getCell(300, 2)
- .isActive());
- }
-
- @Test
- public void testNavigateBetweenHeaderAndBodyWithTab() {
- openTestURL();
-
- GridElement grid = getGridElement();
- grid.getCell(10, 2).click();
-
- assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
- .isActive());
- new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB)
- .keyUp(Keys.SHIFT).perform();
- assertTrue("Header cell 0, 2 is not active", grid.getHeaderCell(0, 2)
- .isActive());
- new Actions(getDriver()).sendKeys(Keys.TAB).perform();
- assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
- .isActive());
-
- // Navigate out of the Grid and try to navigate with arrow keys.
- new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB)
- .sendKeys(Keys.TAB).keyUp(Keys.SHIFT).sendKeys(Keys.ARROW_DOWN)
- .perform();
- assertTrue("Header cell 0, 2 is not active", grid.getHeaderCell(0, 2)
- .isActive());
- }
-
- @Test
- public void testNavigateBetweenFooterAndBodyWithTab() {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Visible");
-
- GridElement grid = getGridElement();
- grid.getCell(10, 2).click();
-
- assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
- .isActive());
- new Actions(getDriver()).sendKeys(Keys.TAB).perform();
- assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2)
- .isActive());
- new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB)
- .keyUp(Keys.SHIFT).perform();
- assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
- .isActive());
-
- // Navigate out of the Grid and try to navigate with arrow keys.
- new Actions(getDriver()).sendKeys(Keys.TAB).sendKeys(Keys.TAB)
- .sendKeys(Keys.ARROW_UP).perform();
- assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2)
- .isActive());
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import com.vaadin.testbench.TestBenchElement;
-import com.vaadin.tests.components.grid.GridElement;
-import com.vaadin.tests.components.grid.GridElement.GridRowElement;
-
-public class GridSelectionTest extends GridBasicFeaturesTest {
-
- @Test
- public void testSelectOnOff() throws Exception {
- openTestURL();
-
- setSelectionModelMulti();
-
- assertFalse("row shouldn't start out as selected", getRow(0)
- .isSelected());
- toggleFirstRowSelection();
- assertTrue("row should become selected", getRow(0).isSelected());
- toggleFirstRowSelection();
- assertFalse("row shouldn't remain selected", getRow(0).isSelected());
- }
-
- @Test
- public void testSelectOnScrollOffScroll() throws Exception {
- openTestURL();
-
- setSelectionModelMulti();
-
- assertFalse("row shouldn't start out as selected", getRow(0)
- .isSelected());
- toggleFirstRowSelection();
- assertTrue("row should become selected", getRow(0).isSelected());
-
- scrollGridVerticallyTo(10000); // make sure the row is out of cache
- scrollGridVerticallyTo(0); // scroll it back into view
-
- assertTrue("row should still be selected when scrolling "
- + "back into view", getRow(0).isSelected());
- }
-
- @Test
- public void testSelectScrollOnScrollOff() throws Exception {
- openTestURL();
-
- setSelectionModelMulti();
-
- assertFalse("row shouldn't start out as selected", getRow(0)
- .isSelected());
-
- scrollGridVerticallyTo(10000); // make sure the row is out of cache
- toggleFirstRowSelection();
-
- scrollGridVerticallyTo(0); // scroll it back into view
- assertTrue("row should still be selected when scrolling "
- + "back into view", getRow(0).isSelected());
-
- toggleFirstRowSelection();
- assertFalse("row shouldn't remain selected", getRow(0).isSelected());
- }
-
- @Test
- public void testSelectScrollOnOffScroll() throws Exception {
- openTestURL();
-
- setSelectionModelMulti();
-
- assertFalse("row shouldn't start out as selected", getRow(0)
- .isSelected());
-
- scrollGridVerticallyTo(10000); // make sure the row is out of cache
- toggleFirstRowSelection();
- toggleFirstRowSelection();
-
- scrollGridVerticallyTo(0); // make sure the row is out of cache
- assertFalse("row shouldn't be selected when scrolling "
- + "back into view", getRow(0).isSelected());
- }
-
- @Test
- public void testSingleSelectionUpdatesFromServer() {
- openTestURL();
- setSelectionModelSingle();
-
- GridElement grid = getGridElement();
- assertFalse("First row was selected from start", grid.getRow(0)
- .isSelected());
- toggleFirstRowSelection();
- assertTrue("First row was not selected.", getRow(0).isSelected());
- grid.getCell(5, 0).click();
- assertTrue("Fifth row was not selected.", getRow(5).isSelected());
- assertFalse("First row was still selected.", getRow(0).isSelected());
- grid.getCell(0, 0).click();
- toggleFirstRowSelection();
- assertFalse("First row was still selected.", getRow(0).isSelected());
- assertFalse("Fifth row was still selected.", getRow(5).isSelected());
-
- grid.scrollToRow(600);
- grid.getCell(595, 0).click();
- assertTrue("Row 595 was not selected.", getRow(595).isSelected());
- toggleFirstRowSelection();
- assertFalse("Row 595 was still selected.", getRow(595).isSelected());
- assertTrue("First row was not selected.", getRow(0).isSelected());
- }
-
- private void setSelectionModelMulti() {
- selectMenuPath("Component", "State", "Selection mode", "multi");
- }
-
- private void setSelectionModelSingle() {
- selectMenuPath("Component", "State", "Selection mode", "single");
- }
-
- @SuppressWarnings("static-method")
- private boolean isSelected(TestBenchElement row) {
- /*
- * FIXME We probably should get a GridRow instead of a plain
- * TestBenchElement, that has an "isSelected" thing integrated. (henrik
- * paul 26.6.2014)
- */
- return row.getAttribute("class").contains("-row-selected");
- }
-
- private void toggleFirstRowSelection() {
- selectMenuPath("Component", "Body rows", "Select first row");
- }
-
- private GridRowElement getRow(int i) {
- return getGridElement().getRow(i);
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-
-import org.junit.Test;
-import org.openqa.selenium.Keys;
-import org.openqa.selenium.interactions.Actions;
-
-import com.vaadin.tests.components.grid.GridElement;
-
-public class GridSortingTest extends GridBasicFeaturesTest {
-
- @Test
- public void testProgrammaticSorting() throws IOException {
- openTestURL();
-
- GridElement grid = getGridElement();
-
- // Sorting by column 9 is sorting by row index that is represented as a
- // String.
- // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0)
- sortBy("Column 9, DESC");
-
- assertTrue("Column 9 should have the sort-desc stylename", grid
- .getHeaderCell(0, 9).getAttribute("class")
- .contains("sort-desc"));
-
- String row = "";
- for (int i = 0; i < 3; ++i) {
- row += "9";
- assertEquals(
- "Grid is not sorted by Column 9 using descending direction.",
- "(" + row + ", 0)", grid.getCell(i, 0).getText());
- }
-
- // Column 10 is random numbers from Random with seed 13334
- sortBy("Column 10, ASC");
-
- assertFalse(
- "Column 9 should no longer have the sort-desc stylename",
- grid.getHeaderCell(0, 9).getAttribute("class")
- .contains("sort-desc"));
- assertTrue("Column 10 should have the sort-asc stylename", grid
- .getHeaderCell(0, 10).getAttribute("class")
- .contains("sort-asc"));
-
- // Not cleaning up correctly causes exceptions when scrolling.
- grid.scrollToRow(50);
- assertFalse("Scrolling caused and exception when shuffled.",
- getLogRow(0).contains("Exception"));
-
- for (int i = 0; i < 5; ++i) {
- assertGreater(
- "Grid is not sorted by Column 10 using ascending direction",
- Integer.parseInt(grid.getCell(i + 1, 10).getText()),
- Integer.parseInt(grid.getCell(i, 10).getText()));
-
- }
-
- // Column 7 is row index as a number. Last three row are original rows
- // 2, 1 and 0.
- sortBy("Column 7, DESC");
- for (int i = 0; i < 3; ++i) {
- assertEquals(
- "Grid is not sorted by Column 7 using descending direction",
- "(" + i + ", 0)",
- grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText());
- }
-
- assertFalse(
- "Column 10 should no longer have the sort-asc stylename",
- grid.getHeaderCell(0, 10).getAttribute("class")
- .contains("sort-asc"));
- assertTrue("Column 7 should have the sort-desc stylename", grid
- .getHeaderCell(0, 7).getAttribute("class")
- .contains("sort-desc"));
-
- }
-
- @Test
- public void testUserSorting() throws InterruptedException {
- openTestURL();
-
- GridElement grid = getGridElement();
-
- // Sorting by column 9 is sorting by row index that is represented as a
- // String.
- // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0)
-
- // Click header twice to sort descending
- grid.getHeaderCell(0, 9).click();
- grid.getHeaderCell(0, 9).click();
- String row = "";
- for (int i = 0; i < 3; ++i) {
- row += "9";
- assertEquals(
- "Grid is not sorted by Column 9 using descending direction.",
- "(" + row + ", 0)", grid.getCell(i, 0).getText());
- }
-
- assertEquals("2. Sort order: [Column 9 ASCENDING]", getLogRow(2));
- assertEquals("4. Sort order: [Column 9 DESCENDING]", getLogRow(0));
-
- // Column 10 is random numbers from Random with seed 13334
- // Click header to sort ascending
- grid.getHeaderCell(0, 10).click();
-
- assertEquals("6. Sort order: [Column 10 ASCENDING]", getLogRow(0));
-
- // Not cleaning up correctly causes exceptions when scrolling.
- grid.scrollToRow(50);
- assertFalse("Scrolling caused and exception when shuffled.",
- getLogRow(0).contains("Exception"));
-
- for (int i = 0; i < 5; ++i) {
- assertGreater(
- "Grid is not sorted by Column 10 using ascending direction",
- Integer.parseInt(grid.getCell(i + 1, 10).getText()),
- Integer.parseInt(grid.getCell(i, 10).getText()));
-
- }
-
- // Column 7 is row index as a number. Last three row are original rows
- // 2, 1 and 0.
- // Click header twice to sort descending
- grid.getHeaderCell(0, 7).click();
- grid.getHeaderCell(0, 7).click();
- for (int i = 0; i < 3; ++i) {
- assertEquals(
- "Grid is not sorted by Column 7 using descending direction",
- "(" + i + ", 0)",
- grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText());
- }
-
- assertEquals("9. Sort order: [Column 7 ASCENDING]", getLogRow(3));
- assertEquals("11. Sort order: [Column 7 DESCENDING]", getLogRow(1));
- }
-
- @Test
- public void testUserMultiColumnSorting() {
- openTestURL();
-
- getGridElement().getHeaderCell(0, 0).click();
- new Actions(driver).keyDown(Keys.SHIFT).perform();
- getGridElement().getHeaderCell(0, 11).click();
- new Actions(driver).keyUp(Keys.SHIFT).perform();
-
- String prev = getGridElement().getCell(0, 11).getAttribute("innerHTML");
- for (int i = 1; i <= 6; ++i) {
- assertEquals("Column 11 should contain same values.", prev,
- getGridElement().getCell(i, 11).getAttribute("innerHTML"));
- }
-
- prev = getGridElement().getCell(0, 0).getText();
- for (int i = 1; i <= 6; ++i) {
- assertTrue(
- "Grid is not sorted by column 0.",
- prev.compareTo(getGridElement().getCell(i, 0).getText()) < 0);
- }
-
- }
-
- private void sortBy(String column) {
- selectMenuPath("Component", "State", "Sort by column", column);
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-
-import org.junit.Test;
-
-import com.vaadin.testbench.elements.ButtonElement;
-
-public class GridStaticSectionComponentTest extends GridBasicFeaturesTest {
-
- @Test
- public void testNativeButtonInHeader() throws IOException {
- openTestURL();
-
- selectMenuPath("Component", "Columns", "Column 1", "Header Type",
- "Widget Header");
-
- getGridElement().$(ButtonElement.class).first().click();
-
- // Clicking also triggers sorting
- assertEquals("2. Button clicked!", getLogRow(2));
- }
-
- @Test
- public void testNativeButtonInFooter() throws IOException {
- openTestURL();
-
- selectMenuPath("Component", "Footer", "Visible");
- selectMenuPath("Component", "Footer", "Append row");
- selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
- "Widget Footer");
-
- getGridElement().$(ButtonElement.class).first().click();
-
- assertEquals("4. Button clicked!", getLogRow(0));
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-
-import com.vaadin.testbench.TestBenchElement;
-
-/**
- * Abstract base class for header and footer tests.
- *
- * @since
- * @author Vaadin Ltd
- */
-public abstract class GridStaticSectionTest extends GridBasicClientFeaturesTest {
-
- protected void assertHeaderTexts(int headerId, int rowIndex) {
- int i = 0;
- for (TestBenchElement cell : getGridElement().getHeaderCells(rowIndex)) {
-
- if (i % 3 == 0) {
- assertText(String.format("Header (%d,%d)", headerId, i), cell);
- } else if (i % 2 == 0) {
- assertHTML(String.format("<b>Header (%d,%d)</b>", headerId, i),
- cell);
- } else {
- assertHTML(String.format(
- "<div class=\"gwt-HTML\">Header (%d,%d)</div>",
- headerId, i), cell);
- }
-
- i++;
- }
- assertEquals("number of header columns", GridBasicFeatures.COLUMNS, i);
- }
-
- protected void assertFooterTexts(int footerId, int rowIndex) {
- int i = 0;
- for (TestBenchElement cell : getGridElement().getFooterCells(rowIndex)) {
- if (i % 3 == 0) {
- assertText(String.format("Footer (%d,%d)", footerId, i), cell);
- } else if (i % 2 == 0) {
- assertHTML(String.format("<b>Footer (%d,%d)</b>", footerId, i),
- cell);
- } else {
- assertHTML(String.format(
- "<div class=\"gwt-HTML\">Footer (%d,%d)</div>",
- footerId, i), cell);
- }
- i++;
- }
- assertEquals("number of footer columns", GridBasicFeatures.COLUMNS, i);
- }
-
- protected static void assertText(String text, TestBenchElement e) {
- // TBE.getText returns "" if the element is scrolled out of view
- assertEquals(text, e.getAttribute("innerHTML"));
- }
-
- protected static void assertHTML(String text, TestBenchElement e) {
- String html = e.getAttribute("innerHTML");
-
- // IE 8 returns tags as upper case while other browsers do not, make the
- // comparison non-casesensive
- html = html.toLowerCase();
- text = text.toLowerCase();
-
- // IE 8 returns attributes without quotes, make the comparison without
- // quotes
- html = html.replaceAll("\"", "");
- text = html.replaceAll("\"", "");
-
- assertEquals(text, html);
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-
-import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.WebElement;
-
-import com.vaadin.testbench.TestBenchElement;
-
-public class GridStructureTest extends GridBasicFeaturesTest {
-
- @Test
- public void testHidingColumn() throws Exception {
- openTestURL();
-
- // Column 0 should be visible
- List<TestBenchElement> cells = getGridHeaderRowCells();
- assertEquals("Column 0", cells.get(0).getText());
-
- // Hide column 0
- selectMenuPath("Component", "Columns", "Column 0", "Visible");
-
- // Column 1 should now be the first cell
- cells = getGridHeaderRowCells();
- assertEquals("Column 1", cells.get(0).getText());
- }
-
- @Test
- public void testRemovingColumn() throws Exception {
- openTestURL();
-
- // Column 0 should be visible
- List<TestBenchElement> cells = getGridHeaderRowCells();
- assertEquals("Column 0", cells.get(0).getText());
-
- // Hide column 0
- selectMenuPath("Component", "Columns", "Column 0", "Remove");
-
- // Column 1 should now be the first cell
- cells = getGridHeaderRowCells();
- assertEquals("Column 1", cells.get(0).getText());
- }
-
- @Test
- public void testDataLoadingAfterRowRemoval() throws Exception {
- openTestURL();
-
- // Remove columns 2,3,4
- selectMenuPath("Component", "Columns", "Column 2", "Remove");
- selectMenuPath("Component", "Columns", "Column 3", "Remove");
- selectMenuPath("Component", "Columns", "Column 4", "Remove");
-
- // Scroll so new data is lazy loaded
- scrollGridVerticallyTo(1000);
-
- // Let lazy loading do its job
- sleep(1000);
-
- // Check that row is loaded
- assertThat(getGridElement().getCell(11, 0).getText(), not("..."));
- }
-
- @Test
- public void testFreezingColumn() throws Exception {
- openTestURL();
-
- // Freeze column 2
- selectMenuPath("Component", "Columns", "Column 2", "Freeze");
-
- WebElement cell = getGridElement().getCell(0, 0);
- assertTrue(cell.getAttribute("class").contains("frozen"));
-
- cell = getGridElement().getCell(0, 1);
- assertTrue(cell.getAttribute("class").contains("frozen"));
- }
-
- @Test
- public void testInitialColumnWidths() throws Exception {
- openTestURL();
-
- WebElement cell = getGridElement().getCell(0, 0);
- assertEquals(100, cell.getSize().getWidth());
-
- cell = getGridElement().getCell(0, 1);
- assertEquals(150, cell.getSize().getWidth());
-
- cell = getGridElement().getCell(0, 2);
- assertEquals(200, cell.getSize().getWidth());
- }
-
- @Test
- public void testColumnWidths() throws Exception {
- openTestURL();
-
- // Default column width is 100px
- WebElement cell = getGridElement().getCell(0, 0);
- assertEquals(100, cell.getSize().getWidth());
-
- // Set first column to be 200px wide
- selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
- "200px");
-
- cell = getGridElement().getCell(0, 0);
- assertEquals(200, cell.getSize().getWidth());
-
- // Set second column to be 150px wide
- selectMenuPath("Component", "Columns", "Column 1", "Column 1 Width",
- "150px");
- cell = getGridElement().getCell(0, 1);
- assertEquals(150, cell.getSize().getWidth());
-
- // Set first column to be auto sized (defaults to 100px currently)
- selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
- "Auto");
-
- cell = getGridElement().getCell(0, 0);
- assertEquals(100, cell.getSize().getWidth());
- }
-
- @Test
- public void testPrimaryStyleNames() throws Exception {
- openTestURL();
-
- // v-grid is default primary style namea
- assertPrimaryStylename("v-grid");
-
- selectMenuPath("Component", "State", "Primary style name",
- "v-escalator");
- assertPrimaryStylename("v-escalator");
-
- selectMenuPath("Component", "State", "Primary style name", "my-grid");
- assertPrimaryStylename("my-grid");
-
- selectMenuPath("Component", "State", "Primary style name", "v-grid");
- assertPrimaryStylename("v-grid");
- }
-
- /**
- * Test that the current view is updated when a server-side container change
- * occurs (without scrolling back and forth)
- */
- @Test
- public void testItemSetChangeEvent() throws Exception {
- openTestURL();
-
- final By newRow = By.xpath("//td[text()='newcell: 0']");
-
- assertTrue("Unexpected initial state", !isElementPresent(newRow));
-
- selectMenuPath("Component", "Body rows", "Add first row");
- assertTrue("Add row failed", isElementPresent(newRow));
-
- selectMenuPath("Component", "Body rows", "Remove first row");
- assertTrue("Remove row failed", !isElementPresent(newRow));
- }
-
- /**
- * Test that the current view is updated when a property's value is reflect
- * to the client, when the value is modified server-side.
- */
- @Test
- public void testPropertyValueChangeEvent() throws Exception {
- openTestURL();
-
- assertEquals("Unexpected cell initial state", "(0, 0)",
- getGridElement().getCell(0, 0).getText());
-
- selectMenuPath("Component", "Body rows",
- "Modify first row (getItemProperty)");
- assertEquals("(First) modification with getItemProperty failed",
- "modified: 0", getGridElement().getCell(0, 0).getText());
-
- selectMenuPath("Component", "Body rows",
- "Modify first row (getContainerProperty)");
- assertEquals("(Second) modification with getItemProperty failed",
- "modified: Column 0", getGridElement().getCell(0, 0).getText());
- }
-
- @Test
- public void testRemovingAllItems() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "Body rows", "Remove all rows");
-
- assertEquals(0, getGridElement().findElement(By.tagName("tbody"))
- .findElements(By.tagName("tr")).size());
- }
-
- private void assertPrimaryStylename(String stylename) {
- assertTrue(getGridElement().getAttribute("class").contains(stylename));
-
- String tableWrapperStyleName = getGridElement().getTableWrapper()
- .getAttribute("class");
- assertTrue(tableWrapperStyleName.contains(stylename + "-tablewrapper"));
-
- String hscrollStyleName = getGridElement().getHorizontalScroller()
- .getAttribute("class");
- assertTrue(hscrollStyleName.contains(stylename + "-scroller"));
- assertTrue(hscrollStyleName
- .contains(stylename + "-scroller-horizontal"));
-
- String vscrollStyleName = getGridElement().getVerticalScroller()
- .getAttribute("class");
- assertTrue(vscrollStyleName.contains(stylename + "-scroller"));
- assertTrue(vscrollStyleName.contains(stylename + "-scroller-vertical"));
- }
-}
+++ /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.grid.basicfeatures;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import com.vaadin.testbench.By;
-
-public class GridStylingTest extends GridStaticSectionTest {
-
- @Test
- public void testGridPrimaryStyle() throws Exception {
- openTestURL();
-
- validateStylenames("v-grid");
- }
-
- @Test
- public void testChangingPrimaryStyleName() throws Exception {
- openTestURL();
-
- selectMenuPath("Component", "State", "Primary Stylename",
- "v-custom-style");
-
- validateStylenames("v-custom-style");
- }
-
- private void validateStylenames(String stylename) {
-
- String classNames = getGridElement().getAttribute("class");
- assertEquals(stylename, classNames);
-
- classNames = getGridElement().getVerticalScroller().getAttribute(
- "class");
- assertTrue(classNames.contains(stylename + "-scroller"));
- assertTrue(classNames.contains(stylename + "-scroller-vertical"));
-
- classNames = getGridElement().getHorizontalScroller().getAttribute(
- "class");
- assertTrue(classNames.contains(stylename + "-scroller"));
- assertTrue(classNames.contains(stylename + "-scroller-horizontal"));
-
- classNames = getGridElement().getTableWrapper().getAttribute("class");
- assertEquals(stylename + "-tablewrapper", classNames);
-
- classNames = getGridElement().getHeader().getAttribute("class");
- assertEquals(stylename + "-header", classNames);
-
- for (int row = 0; row < getGridElement().getHeaderCount(); row++) {
- classNames = getGridElement().getHeaderRow(row).getAttribute(
- "class");
- assertEquals(stylename + "-row", classNames);
-
- for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
- classNames = getGridElement().getHeaderCell(row, col)
- .getAttribute("class");
- assertTrue(classNames.contains(stylename + "-cell"));
-
- if (row == 0 && col == 0) {
- assertTrue(classNames,
- classNames.contains(stylename + "-header-active"));
- }
- }
- }
-
- classNames = getGridElement().getBody().getAttribute("class");
- assertEquals(stylename + "-body", classNames);
-
- int rowsInBody = getGridElement().getBody()
- .findElements(By.tagName("tr")).size();
- for (int row = 0; row < rowsInBody; row++) {
- classNames = getGridElement().getRow(row).getAttribute("class");
- assertTrue(classNames.contains(stylename + "-row"));
- assertTrue(classNames.contains(stylename + "-row-has-data"));
-
- for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
- classNames = getGridElement().getCell(row, col).getAttribute(
- "class");
- assertTrue(classNames.contains(stylename + "-cell"));
-
- if (row == 0 && col == 0) {
- assertTrue(classNames.contains(stylename + "-cell-active"));
- }
- }
- }
-
- classNames = getGridElement().getFooter().getAttribute("class");
- assertEquals(stylename + "-footer", classNames);
-
- for (int row = 0; row < getGridElement().getFooterCount(); row++) {
- classNames = getGridElement().getFooterRow(row).getAttribute(
- "class");
- assertEquals(stylename + "-row", classNames);
-
- for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
- classNames = getGridElement().getFooterCell(row, col)
- .getAttribute("class");
- assertTrue(classNames.contains(stylename + "-cell"));
- }
- }
- }
-}
--- /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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
+import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget;
+
+public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest {
+
+ @Test
+ public void initialColumnWidths() {
+ openTestURL();
+
+ for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) {
+ int width = getGridElement().getCell(0, col).getSize().getWidth();
+ if (col <= 6) {
+ // Growing column widths
+ assertEquals(50 + col * 25, width);
+ } else {
+ assertEquals(100, width);
+ }
+ }
+ }
+
+ @Test
+ public void testChangingColumnWidth() {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
+ int width = getGridElement().getCell(0, 0).getSize().getWidth();
+ assertEquals(50, width);
+
+ selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
+ width = getGridElement().getCell(0, 0).getSize().getWidth();
+ assertEquals(200, width);
+
+ selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
+ width = getGridElement().getCell(0, 0).getSize().getWidth();
+ assertEquals(100, width);
+ }
+
+}
--- /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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
+
+public class GridClientSelectionTest extends GridBasicClientFeaturesTest {
+
+ @Test
+ public void testChangeSelectionMode() {
+ openTestURL();
+
+ selectMenuPath("Component", "State", "Selection mode", "none");
+ assertTrue("First column was selection column", getGridElement()
+ .getCell(0, 0).getText().equals("(0, 0)"));
+ selectMenuPath("Component", "State", "Selection mode", "multi");
+ assertTrue("First column was not selection column", getGridElement()
+ .getCell(0, 1).getText().equals("(0, 0)"));
+ }
+}
--- /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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.components.grid.GridElement.GridCellElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+
+public class GridFooterTest extends GridStaticSectionTest {
+
+ @Test
+ public void testDefaultFooter() {
+ openTestURL();
+
+ // Footer should have zero rows by default
+ assertFooterCount(0);
+ }
+
+ @Test
+ public void testFooterVisibility() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Visible");
+
+ assertFooterCount(0);
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ assertFooterCount(0);
+
+ selectMenuPath("Component", "Footer", "Visible");
+
+ assertFooterCount(1);
+ }
+
+ @Test
+ public void testAddRows() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ assertFooterCount(1);
+ assertFooterTexts(0, 0);
+
+ selectMenuPath("Component", "Footer", "Prepend row");
+
+ assertFooterCount(2);
+ assertFooterTexts(1, 0);
+ assertFooterTexts(0, 1);
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ assertFooterCount(3);
+ assertFooterTexts(1, 0);
+ assertFooterTexts(0, 1);
+ assertFooterTexts(2, 2);
+ }
+
+ @Test
+ public void testRemoveRows() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Prepend row");
+ selectMenuPath("Component", "Footer", "Append row");
+
+ selectMenuPath("Component", "Footer", "Remove top row");
+
+ assertFooterCount(1);
+ assertFooterTexts(1, 0);
+
+ selectMenuPath("Component", "Footer", "Remove bottom row");
+ assertFooterCount(0);
+ }
+
+ @Test
+ public void joinColumnsByCells() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ selectMenuPath("Component", "Footer", "Row 1", "Join column cells 0, 1");
+
+ GridCellElement spannedCell = getGridElement().getFooterCell(0, 0);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+
+ GridCellElement hiddenCell = getGridElement().getFooterCell(0, 1);
+ assertFalse(hiddenCell.isDisplayed());
+ }
+
+ @Test
+ public void joinColumnsByColumns() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2");
+
+ GridCellElement spannedCell = getGridElement().getFooterCell(0, 1);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+
+ GridCellElement hiddenCell = getGridElement().getFooterCell(0, 2);
+ assertFalse(hiddenCell.isDisplayed());
+ }
+
+ @Test
+ public void joinAllColumnsInRow() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ selectMenuPath("Component", "Footer", "Row 1", "Join all columns");
+
+ GridCellElement spannedCell = getGridElement().getFooterCell(0, 0);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("" + GridBasicFeatures.COLUMNS,
+ spannedCell.getAttribute("colspan"));
+
+ for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) {
+ GridCellElement hiddenCell = getGridElement().getFooterCell(0,
+ columnIndex);
+ assertFalse(hiddenCell.isDisplayed());
+ }
+ }
+
+ @Test
+ public void testInitialCellTypes() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ GridCellElement textCell = getGridElement().getFooterCell(0, 0);
+ assertEquals("Footer (0,0)", textCell.getText());
+
+ GridCellElement widgetCell = getGridElement().getFooterCell(0, 1);
+ assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML")));
+
+ GridCellElement htmlCell = getGridElement().getFooterCell(0, 2);
+ assertHTML("<b>Footer (0,2)</b>", htmlCell);
+ }
+
+ @Test
+ public void testDynamicallyChangingCellType() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ selectMenuPath("Component", "Columns", "Column 0", "Footer Type",
+ "Widget Footer");
+ GridCellElement widgetCell = getGridElement().getFooterCell(0, 0);
+ assertTrue(widgetCell.isElementPresent(By.className("gwt-Button")));
+
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "HTML Footer");
+ GridCellElement htmlCell = getGridElement().getFooterCell(0, 1);
+ assertHTML("<b>HTML Footer</b>", htmlCell);
+
+ selectMenuPath("Component", "Columns", "Column 2", "Footer Type",
+ "Text Footer");
+ GridCellElement textCell = getGridElement().getFooterCell(0, 2);
+ assertEquals("Text Footer", textCell.getText());
+ }
+
+ @Test
+ public void testCellWidgetInteraction() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Append row");
+
+ selectMenuPath("Component", "Columns", "Column 0", "Footer Type",
+ "Widget Footer");
+ GridCellElement widgetCell = getGridElement().getFooterCell(0, 0);
+ WebElement button = widgetCell.findElement(By.className("gwt-Button"));
+
+ assertNotEquals("Clicked", button.getText());
+
+ button.click();
+
+ assertEquals("Clicked", button.getText());
+ }
+
+ private void assertFooterCount(int count) {
+ assertEquals("footer count", count, getGridElement().getFooterCount());
+ }
+}
--- /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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.tests.components.grid.GridElement.GridCellElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+
+public class GridHeaderTest extends GridStaticSectionTest {
+
+ @Test
+ public void testDefaultHeader() throws Exception {
+ openTestURL();
+
+ assertHeaderCount(1);
+ assertHeaderTexts(0, 0);
+ }
+
+ @Test
+ public void testHeaderVisibility() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Visible");
+
+ assertHeaderCount(0);
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ assertHeaderCount(0);
+
+ selectMenuPath("Component", "Header", "Visible");
+
+ assertHeaderCount(2);
+ }
+
+ @Test
+ public void testHeaderCaptions() throws Exception {
+ openTestURL();
+
+ assertHeaderTexts(0, 0);
+ }
+
+ @Test
+ public void testHeadersWithInvisibleColumns() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 1", "Visible");
+ selectMenuPath("Component", "Columns", "Column 3", "Visible");
+
+ List<TestBenchElement> cells = getGridHeaderRowCells();
+ assertEquals(GridBasicFeatures.COLUMNS - 2, cells.size());
+
+ assertText("Header (0,0)", cells.get(0));
+ assertHTML("<b>Header (0,2)</b>", cells.get(1));
+ assertHTML("<b>Header (0,4)</b>", cells.get(2));
+
+ selectMenuPath("Component", "Columns", "Column 3", "Visible");
+
+ cells = getGridHeaderRowCells();
+ assertEquals(GridBasicFeatures.COLUMNS - 1, cells.size());
+
+ assertText("Header (0,0)", cells.get(0));
+ assertHTML("<b>Header (0,2)</b>", cells.get(1));
+ assertText("Header (0,3)", cells.get(2));
+ assertHTML("<b>Header (0,4)</b>", cells.get(3));
+ }
+
+ @Test
+ public void testAddRows() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ assertHeaderCount(2);
+ assertHeaderTexts(0, 0);
+ assertHeaderTexts(1, 1);
+
+ selectMenuPath("Component", "Header", "Prepend row");
+
+ assertHeaderCount(3);
+ assertHeaderTexts(2, 0);
+ assertHeaderTexts(0, 1);
+ assertHeaderTexts(1, 2);
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ assertHeaderCount(4);
+ assertHeaderTexts(2, 0);
+ assertHeaderTexts(0, 1);
+ assertHeaderTexts(1, 2);
+ assertHeaderTexts(3, 3);
+ }
+
+ @Test
+ public void testRemoveRows() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Prepend row");
+ selectMenuPath("Component", "Header", "Append row");
+
+ selectMenuPath("Component", "Header", "Remove top row");
+
+ assertHeaderCount(2);
+ assertHeaderTexts(0, 0);
+ assertHeaderTexts(2, 1);
+
+ selectMenuPath("Component", "Header", "Remove bottom row");
+ assertHeaderCount(1);
+ assertHeaderTexts(0, 0);
+ }
+
+ @Test
+ public void testDefaultRow() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 0", "Sortable");
+
+ GridCellElement headerCell = getGridElement().getHeaderCell(0, 0);
+
+ headerCell.click();
+
+ assertTrue(hasClassName(headerCell, "sort-asc"));
+
+ headerCell.click();
+
+ assertFalse(hasClassName(headerCell, "sort-asc"));
+ assertTrue(hasClassName(headerCell, "sort-desc"));
+
+ selectMenuPath("Component", "Header", "Prepend row");
+ selectMenuPath("Component", "Header", "Default row", "Top");
+
+ assertFalse(hasClassName(headerCell, "sort-desc"));
+ headerCell = getGridElement().getHeaderCell(0, 0);
+ assertTrue(hasClassName(headerCell, "sort-desc"));
+
+ selectMenuPath("Component", "Header", "Default row", "Unset");
+
+ assertFalse(hasClassName(headerCell, "sort-desc"));
+ }
+
+ @Test
+ public void joinHeaderColumnsByCells() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ selectMenuPath("Component", "Header", "Row 2", "Join column cells 0, 1");
+
+ GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+
+ GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 1);
+ assertFalse(hiddenCell.isDisplayed());
+ }
+
+ @Test
+ public void joinHeaderColumnsByColumns() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2");
+
+ GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+
+ GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 2);
+ assertFalse(hiddenCell.isDisplayed());
+ }
+
+ @Test
+ public void joinAllColumnsInHeaderRow() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ selectMenuPath("Component", "Header", "Row 2", "Join all columns");
+
+ GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("" + GridBasicFeatures.COLUMNS,
+ spannedCell.getAttribute("colspan"));
+
+ for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) {
+ GridCellElement hiddenCell = getGridElement().getHeaderCell(1,
+ columnIndex);
+ assertFalse(hiddenCell.isDisplayed());
+ }
+ }
+
+ @Test
+ public void hideFirstColumnInColspan() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ selectMenuPath("Component", "Header", "Row 2", "Join all columns");
+
+ int visibleColumns = GridBasicFeatures.COLUMNS;
+
+ GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("" + visibleColumns, spannedCell.getAttribute("colspan"));
+
+ selectMenuPath("Component", "Columns", "Column 0", "Visible");
+ visibleColumns--;
+
+ spannedCell = getGridElement().getHeaderCell(1, 0);
+ assertTrue(spannedCell.isDisplayed());
+ assertEquals("" + visibleColumns, spannedCell.getAttribute("colspan"));
+ }
+
+ @Test
+ public void multipleColspanAndMultipleHiddenColumns() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Header", "Append row");
+
+ // Join columns [1,2] and [3,4,5]
+ selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2");
+ GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1);
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+
+ selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5");
+ spannedCell = getGridElement().getHeaderCell(1, 3);
+ assertEquals("3", spannedCell.getAttribute("colspan"));
+
+ selectMenuPath("Component", "Columns", "Column 2", "Visible");
+ spannedCell = getGridElement().getHeaderCell(1, 1);
+ assertEquals("1", spannedCell.getAttribute("colspan"));
+
+ // Ensure the second colspan is preserved (shifts one index to the left)
+ spannedCell = getGridElement().getHeaderCell(1, 2);
+ assertEquals("3", spannedCell.getAttribute("colspan"));
+
+ selectMenuPath("Component", "Columns", "Column 4", "Visible");
+
+ // First reduced colspan is reduced
+ spannedCell = getGridElement().getHeaderCell(1, 1);
+ assertEquals("1", spannedCell.getAttribute("colspan"));
+
+ // Second colspan is also now reduced
+ spannedCell = getGridElement().getHeaderCell(1, 2);
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+
+ // Show columns again
+ selectMenuPath("Component", "Columns", "Column 2", "Visible");
+ selectMenuPath("Component", "Columns", "Column 4", "Visible");
+
+ spannedCell = getGridElement().getHeaderCell(1, 1);
+ assertEquals("2", spannedCell.getAttribute("colspan"));
+ spannedCell = getGridElement().getHeaderCell(1, 3);
+ assertEquals("3", spannedCell.getAttribute("colspan"));
+
+ }
+
+ @Test
+ public void testInitialCellTypes() throws Exception {
+ openTestURL();
+
+ GridCellElement textCell = getGridElement().getHeaderCell(0, 0);
+ assertEquals("Header (0,0)", textCell.getText());
+
+ GridCellElement widgetCell = getGridElement().getHeaderCell(0, 1);
+ assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML")));
+
+ GridCellElement htmlCell = getGridElement().getHeaderCell(0, 2);
+ assertHTML("<b>Header (0,2)</b>", htmlCell);
+ }
+
+ @Test
+ public void testDynamicallyChangingCellType() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 0", "Header Type",
+ "Widget Header");
+ GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
+ assertTrue(widgetCell.isElementPresent(By.className("gwt-Button")));
+
+ selectMenuPath("Component", "Columns", "Column 1", "Header Type",
+ "HTML Header");
+ GridCellElement htmlCell = getGridElement().getHeaderCell(0, 1);
+ assertHTML("<b>HTML Header</b>", htmlCell);
+
+ selectMenuPath("Component", "Columns", "Column 2", "Header Type",
+ "Text Header");
+ GridCellElement textCell = getGridElement().getHeaderCell(0, 2);
+ assertEquals("Text Header", textCell.getText());
+ }
+
+ @Test
+ public void testCellWidgetInteraction() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 0", "Header Type",
+ "Widget Header");
+ GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
+ WebElement button = widgetCell.findElement(By.className("gwt-Button"));
+
+ button.click();
+
+ assertEquals("Clicked", button.getText());
+ }
+
+ @Test
+ public void widgetInSortableCellInteraction() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 0", "Header Type",
+ "Widget Header");
+
+ selectMenuPath("Component", "Columns", "Column 0", "Sortable");
+
+ GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
+ WebElement button = widgetCell.findElement(By.className("gwt-Button"));
+
+ assertNotEquals("Clicked", button.getText());
+
+ button.click();
+
+ assertEquals("Clicked", button.getText());
+ }
+
+ private void assertHeaderCount(int count) {
+ assertEquals("header count", count, getGridElement().getHeaderCount());
+ }
+
+ private boolean hasClassName(TestBenchElement element, String name) {
+ return Arrays.asList(element.getAttribute("class").split(" "))
+ .contains(name);
+ }
+}
--- /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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertEquals;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+
+/**
+ * Abstract base class for header and footer tests.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public abstract class GridStaticSectionTest extends GridBasicClientFeaturesTest {
+
+ protected void assertHeaderTexts(int headerId, int rowIndex) {
+ int i = 0;
+ for (TestBenchElement cell : getGridElement().getHeaderCells(rowIndex)) {
+
+ if (i % 3 == 0) {
+ assertText(String.format("Header (%d,%d)", headerId, i), cell);
+ } else if (i % 2 == 0) {
+ assertHTML(String.format("<b>Header (%d,%d)</b>", headerId, i),
+ cell);
+ } else {
+ assertHTML(String.format(
+ "<div class=\"gwt-HTML\">Header (%d,%d)</div>",
+ headerId, i), cell);
+ }
+
+ i++;
+ }
+ assertEquals("number of header columns", GridBasicFeatures.COLUMNS, i);
+ }
+
+ protected void assertFooterTexts(int footerId, int rowIndex) {
+ int i = 0;
+ for (TestBenchElement cell : getGridElement().getFooterCells(rowIndex)) {
+ if (i % 3 == 0) {
+ assertText(String.format("Footer (%d,%d)", footerId, i), cell);
+ } else if (i % 2 == 0) {
+ assertHTML(String.format("<b>Footer (%d,%d)</b>", footerId, i),
+ cell);
+ } else {
+ assertHTML(String.format(
+ "<div class=\"gwt-HTML\">Footer (%d,%d)</div>",
+ footerId, i), cell);
+ }
+ i++;
+ }
+ assertEquals("number of footer columns", GridBasicFeatures.COLUMNS, i);
+ }
+
+ protected static void assertText(String text, TestBenchElement e) {
+ // TBE.getText returns "" if the element is scrolled out of view
+ assertEquals(text, e.getAttribute("innerHTML"));
+ }
+
+ protected static void assertHTML(String text, TestBenchElement e) {
+ String html = e.getAttribute("innerHTML");
+
+ // IE 8 returns tags as upper case while other browsers do not, make the
+ // comparison non-casesensive
+ html = html.toLowerCase();
+ text = text.toLowerCase();
+
+ // IE 8 returns attributes without quotes, make the comparison without
+ // quotes
+ html = html.replaceAll("\"", "");
+ text = html.replaceAll("\"", "");
+
+ assertEquals(text, html);
+ }
+}
--- /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.grid.basicfeatures.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+
+public class GridStylingTest extends GridStaticSectionTest {
+
+ @Test
+ public void testGridPrimaryStyle() throws Exception {
+ openTestURL();
+
+ validateStylenames("v-grid");
+ }
+
+ @Test
+ public void testChangingPrimaryStyleName() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "State", "Primary Stylename",
+ "v-custom-style");
+
+ validateStylenames("v-custom-style");
+ }
+
+ private void validateStylenames(String stylename) {
+
+ String classNames = getGridElement().getAttribute("class");
+ assertEquals(stylename, classNames);
+
+ classNames = getGridElement().getVerticalScroller().getAttribute(
+ "class");
+ assertTrue(classNames.contains(stylename + "-scroller"));
+ assertTrue(classNames.contains(stylename + "-scroller-vertical"));
+
+ classNames = getGridElement().getHorizontalScroller().getAttribute(
+ "class");
+ assertTrue(classNames.contains(stylename + "-scroller"));
+ assertTrue(classNames.contains(stylename + "-scroller-horizontal"));
+
+ classNames = getGridElement().getTableWrapper().getAttribute("class");
+ assertEquals(stylename + "-tablewrapper", classNames);
+
+ classNames = getGridElement().getHeader().getAttribute("class");
+ assertEquals(stylename + "-header", classNames);
+
+ for (int row = 0; row < getGridElement().getHeaderCount(); row++) {
+ classNames = getGridElement().getHeaderRow(row).getAttribute(
+ "class");
+ assertEquals(stylename + "-row", classNames);
+
+ for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
+ classNames = getGridElement().getHeaderCell(row, col)
+ .getAttribute("class");
+ assertTrue(classNames.contains(stylename + "-cell"));
+
+ if (row == 0 && col == 0) {
+ assertTrue(classNames,
+ classNames.contains(stylename + "-header-active"));
+ }
+ }
+ }
+
+ classNames = getGridElement().getBody().getAttribute("class");
+ assertEquals(stylename + "-body", classNames);
+
+ int rowsInBody = getGridElement().getBody()
+ .findElements(By.tagName("tr")).size();
+ for (int row = 0; row < rowsInBody; row++) {
+ classNames = getGridElement().getRow(row).getAttribute("class");
+ assertTrue(classNames.contains(stylename + "-row"));
+ assertTrue(classNames.contains(stylename + "-row-has-data"));
+
+ for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
+ classNames = getGridElement().getCell(row, col).getAttribute(
+ "class");
+ assertTrue(classNames.contains(stylename + "-cell"));
+
+ if (row == 0 && col == 0) {
+ assertTrue(classNames.contains(stylename + "-cell-active"));
+ }
+ }
+ }
+
+ classNames = getGridElement().getFooter().getAttribute("class");
+ assertEquals(stylename + "-footer", classNames);
+
+ for (int row = 0; row < getGridElement().getFooterCount(); row++) {
+ classNames = getGridElement().getFooterRow(row).getAttribute(
+ "class");
+ assertEquals(stylename + "-row", classNames);
+
+ for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) {
+ classNames = getGridElement().getFooterCell(row, col)
+ .getAttribute("class");
+ assertTrue(classNames.contains(stylename + "-cell"));
+ }
+ }
+ }
+}
--- /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.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.tests.components.grid.GridElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+public class GridKeyboardNavigationTest extends GridBasicFeaturesTest {
+
+ @Test
+ public void testCellActiveOnClick() {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+ assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0)
+ .isActive());
+ grid.getCell(5, 2).click();
+ assertFalse("Body cell 0, 0 was still active after clicking", grid
+ .getCell(0, 0).isActive());
+ assertTrue("Body cell 5, 2 is not active after clicking",
+ grid.getCell(5, 2).isActive());
+ }
+
+ @Test
+ public void testCellNotActiveWhenRendererHandlesEvent() {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+ assertTrue("Body cell 0, 0 is not active on init.", grid.getCell(0, 0)
+ .isActive());
+ grid.getHeaderCell(0, 3).click();
+ assertFalse("Body cell 0, 0 is active after click on header.", grid
+ .getCell(0, 0).isActive());
+ assertTrue("Header cell 0, 3 is not active after click on header.",
+ grid.getHeaderCell(0, 3).isActive());
+ }
+
+ @Test
+ public void testSimpleKeyboardNavigation() {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+ grid.getCell(0, 0).click();
+
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+ assertTrue("Body cell 1, 0 is not active after keyboard navigation.",
+ grid.getCell(1, 0).isActive());
+
+ new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT).perform();
+ assertTrue("Body cell 1, 1 is not active after keyboard navigation.",
+ grid.getCell(1, 1).isActive());
+
+ int i;
+ for (i = 1; i < 40; ++i) {
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+ }
+
+ assertFalse("Grid has not scrolled with active cell",
+ isElementPresent(By.xpath("//td[text() = '(0, 0)']")));
+ assertTrue("Active cell is not visible",
+ isElementPresent(By.xpath("//td[text() = '(" + i + ", 0)']")));
+ assertTrue("Body cell " + i + ", 1 is not active", grid.getCell(i, 1)
+ .isActive());
+ }
+
+ @Test
+ public void testNavigateFromHeaderToBody() {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+ grid.scrollToRow(300);
+ new Actions(driver).moveToElement(grid.getHeaderCell(0, 7)).click()
+ .perform();
+ grid.scrollToRow(280);
+
+ assertTrue("Header cell is not active.", grid.getHeaderCell(0, 7)
+ .isActive());
+ new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform();
+ assertTrue("Body cell 280, 7 is not active", grid.getCell(280, 7)
+ .isActive());
+ }
+
+ @Test
+ public void testNavigationFromFooterToBody() {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Visible");
+
+ GridElement grid = getGridElement();
+ grid.scrollToRow(300);
+ grid.getFooterCell(0, 2).click();
+
+ assertTrue("Footer cell is not active.", grid.getFooterCell(0, 2)
+ .isActive());
+ new Actions(getDriver()).sendKeys(Keys.ARROW_UP).perform();
+ assertTrue("Body cell 300, 2 is not active", grid.getCell(300, 2)
+ .isActive());
+ }
+
+ @Test
+ public void testNavigateBetweenHeaderAndBodyWithTab() {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+ grid.getCell(10, 2).click();
+
+ assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
+ .isActive());
+ new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB)
+ .keyUp(Keys.SHIFT).perform();
+ assertTrue("Header cell 0, 2 is not active", grid.getHeaderCell(0, 2)
+ .isActive());
+ new Actions(getDriver()).sendKeys(Keys.TAB).perform();
+ assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
+ .isActive());
+
+ // Navigate out of the Grid and try to navigate with arrow keys.
+ new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB)
+ .sendKeys(Keys.TAB).keyUp(Keys.SHIFT).sendKeys(Keys.ARROW_DOWN)
+ .perform();
+ assertTrue("Header cell 0, 2 is not active", grid.getHeaderCell(0, 2)
+ .isActive());
+ }
+
+ @Test
+ public void testNavigateBetweenFooterAndBodyWithTab() {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Visible");
+
+ GridElement grid = getGridElement();
+ grid.getCell(10, 2).click();
+
+ assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
+ .isActive());
+ new Actions(getDriver()).sendKeys(Keys.TAB).perform();
+ assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2)
+ .isActive());
+ new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB)
+ .keyUp(Keys.SHIFT).perform();
+ assertTrue("Body cell 10, 2 is not active", grid.getCell(10, 2)
+ .isActive());
+
+ // Navigate out of the Grid and try to navigate with arrow keys.
+ new Actions(getDriver()).sendKeys(Keys.TAB).sendKeys(Keys.TAB)
+ .sendKeys(Keys.ARROW_UP).perform();
+ assertTrue("Footer cell 0, 2 is not active", grid.getFooterCell(0, 2)
+ .isActive());
+ }
+}
--- /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.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.tests.components.grid.GridElement;
+import com.vaadin.tests.components.grid.GridElement.GridRowElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+public class GridSelectionTest extends GridBasicFeaturesTest {
+
+ @Test
+ public void testSelectOnOff() throws Exception {
+ openTestURL();
+
+ setSelectionModelMulti();
+
+ assertFalse("row shouldn't start out as selected", getRow(0)
+ .isSelected());
+ toggleFirstRowSelection();
+ assertTrue("row should become selected", getRow(0).isSelected());
+ toggleFirstRowSelection();
+ assertFalse("row shouldn't remain selected", getRow(0).isSelected());
+ }
+
+ @Test
+ public void testSelectOnScrollOffScroll() throws Exception {
+ openTestURL();
+
+ setSelectionModelMulti();
+
+ assertFalse("row shouldn't start out as selected", getRow(0)
+ .isSelected());
+ toggleFirstRowSelection();
+ assertTrue("row should become selected", getRow(0).isSelected());
+
+ scrollGridVerticallyTo(10000); // make sure the row is out of cache
+ scrollGridVerticallyTo(0); // scroll it back into view
+
+ assertTrue("row should still be selected when scrolling "
+ + "back into view", getRow(0).isSelected());
+ }
+
+ @Test
+ public void testSelectScrollOnScrollOff() throws Exception {
+ openTestURL();
+
+ setSelectionModelMulti();
+
+ assertFalse("row shouldn't start out as selected", getRow(0)
+ .isSelected());
+
+ scrollGridVerticallyTo(10000); // make sure the row is out of cache
+ toggleFirstRowSelection();
+
+ scrollGridVerticallyTo(0); // scroll it back into view
+ assertTrue("row should still be selected when scrolling "
+ + "back into view", getRow(0).isSelected());
+
+ toggleFirstRowSelection();
+ assertFalse("row shouldn't remain selected", getRow(0).isSelected());
+ }
+
+ @Test
+ public void testSelectScrollOnOffScroll() throws Exception {
+ openTestURL();
+
+ setSelectionModelMulti();
+
+ assertFalse("row shouldn't start out as selected", getRow(0)
+ .isSelected());
+
+ scrollGridVerticallyTo(10000); // make sure the row is out of cache
+ toggleFirstRowSelection();
+ toggleFirstRowSelection();
+
+ scrollGridVerticallyTo(0); // make sure the row is out of cache
+ assertFalse("row shouldn't be selected when scrolling "
+ + "back into view", getRow(0).isSelected());
+ }
+
+ @Test
+ public void testSingleSelectionUpdatesFromServer() {
+ openTestURL();
+ setSelectionModelSingle();
+
+ GridElement grid = getGridElement();
+ assertFalse("First row was selected from start", grid.getRow(0)
+ .isSelected());
+ toggleFirstRowSelection();
+ assertTrue("First row was not selected.", getRow(0).isSelected());
+ grid.getCell(5, 0).click();
+ assertTrue("Fifth row was not selected.", getRow(5).isSelected());
+ assertFalse("First row was still selected.", getRow(0).isSelected());
+ grid.getCell(0, 0).click();
+ toggleFirstRowSelection();
+ assertFalse("First row was still selected.", getRow(0).isSelected());
+ assertFalse("Fifth row was still selected.", getRow(5).isSelected());
+
+ grid.scrollToRow(600);
+ grid.getCell(595, 0).click();
+ assertTrue("Row 595 was not selected.", getRow(595).isSelected());
+ toggleFirstRowSelection();
+ assertFalse("Row 595 was still selected.", getRow(595).isSelected());
+ assertTrue("First row was not selected.", getRow(0).isSelected());
+ }
+
+ private void setSelectionModelMulti() {
+ selectMenuPath("Component", "State", "Selection mode", "multi");
+ }
+
+ private void setSelectionModelSingle() {
+ selectMenuPath("Component", "State", "Selection mode", "single");
+ }
+
+ @SuppressWarnings("static-method")
+ private boolean isSelected(TestBenchElement row) {
+ /*
+ * FIXME We probably should get a GridRow instead of a plain
+ * TestBenchElement, that has an "isSelected" thing integrated. (henrik
+ * paul 26.6.2014)
+ */
+ return row.getAttribute("class").contains("-row-selected");
+ }
+
+ private void toggleFirstRowSelection() {
+ selectMenuPath("Component", "Body rows", "Select first row");
+ }
+
+ private GridRowElement getRow(int i) {
+ return getGridElement().getRow(i);
+ }
+}
--- /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.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.tests.components.grid.GridElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+public class GridSortingTest extends GridBasicFeaturesTest {
+
+ @Test
+ public void testProgrammaticSorting() throws IOException {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+
+ // Sorting by column 9 is sorting by row index that is represented as a
+ // String.
+ // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0)
+ sortBy("Column 9, DESC");
+
+ assertTrue("Column 9 should have the sort-desc stylename", grid
+ .getHeaderCell(0, 9).getAttribute("class")
+ .contains("sort-desc"));
+
+ String row = "";
+ for (int i = 0; i < 3; ++i) {
+ row += "9";
+ assertEquals(
+ "Grid is not sorted by Column 9 using descending direction.",
+ "(" + row + ", 0)", grid.getCell(i, 0).getText());
+ }
+
+ // Column 10 is random numbers from Random with seed 13334
+ sortBy("Column 10, ASC");
+
+ assertFalse(
+ "Column 9 should no longer have the sort-desc stylename",
+ grid.getHeaderCell(0, 9).getAttribute("class")
+ .contains("sort-desc"));
+ assertTrue("Column 10 should have the sort-asc stylename", grid
+ .getHeaderCell(0, 10).getAttribute("class")
+ .contains("sort-asc"));
+
+ // Not cleaning up correctly causes exceptions when scrolling.
+ grid.scrollToRow(50);
+ assertFalse("Scrolling caused and exception when shuffled.",
+ getLogRow(0).contains("Exception"));
+
+ for (int i = 0; i < 5; ++i) {
+ assertGreater(
+ "Grid is not sorted by Column 10 using ascending direction",
+ Integer.parseInt(grid.getCell(i + 1, 10).getText()),
+ Integer.parseInt(grid.getCell(i, 10).getText()));
+
+ }
+
+ // Column 7 is row index as a number. Last three row are original rows
+ // 2, 1 and 0.
+ sortBy("Column 7, DESC");
+ for (int i = 0; i < 3; ++i) {
+ assertEquals(
+ "Grid is not sorted by Column 7 using descending direction",
+ "(" + i + ", 0)",
+ grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText());
+ }
+
+ assertFalse(
+ "Column 10 should no longer have the sort-asc stylename",
+ grid.getHeaderCell(0, 10).getAttribute("class")
+ .contains("sort-asc"));
+ assertTrue("Column 7 should have the sort-desc stylename", grid
+ .getHeaderCell(0, 7).getAttribute("class")
+ .contains("sort-desc"));
+
+ }
+
+ @Test
+ public void testUserSorting() throws InterruptedException {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+
+ // Sorting by column 9 is sorting by row index that is represented as a
+ // String.
+ // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0)
+
+ // Click header twice to sort descending
+ grid.getHeaderCell(0, 9).click();
+ grid.getHeaderCell(0, 9).click();
+ String row = "";
+ for (int i = 0; i < 3; ++i) {
+ row += "9";
+ assertEquals(
+ "Grid is not sorted by Column 9 using descending direction.",
+ "(" + row + ", 0)", grid.getCell(i, 0).getText());
+ }
+
+ assertEquals("2. Sort order: [Column 9 ASCENDING]", getLogRow(2));
+ assertEquals("4. Sort order: [Column 9 DESCENDING]", getLogRow(0));
+
+ // Column 10 is random numbers from Random with seed 13334
+ // Click header to sort ascending
+ grid.getHeaderCell(0, 10).click();
+
+ assertEquals("6. Sort order: [Column 10 ASCENDING]", getLogRow(0));
+
+ // Not cleaning up correctly causes exceptions when scrolling.
+ grid.scrollToRow(50);
+ assertFalse("Scrolling caused and exception when shuffled.",
+ getLogRow(0).contains("Exception"));
+
+ for (int i = 0; i < 5; ++i) {
+ assertGreater(
+ "Grid is not sorted by Column 10 using ascending direction",
+ Integer.parseInt(grid.getCell(i + 1, 10).getText()),
+ Integer.parseInt(grid.getCell(i, 10).getText()));
+
+ }
+
+ // Column 7 is row index as a number. Last three row are original rows
+ // 2, 1 and 0.
+ // Click header twice to sort descending
+ grid.getHeaderCell(0, 7).click();
+ grid.getHeaderCell(0, 7).click();
+ for (int i = 0; i < 3; ++i) {
+ assertEquals(
+ "Grid is not sorted by Column 7 using descending direction",
+ "(" + i + ", 0)",
+ grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText());
+ }
+
+ assertEquals("9. Sort order: [Column 7 ASCENDING]", getLogRow(3));
+ assertEquals("11. Sort order: [Column 7 DESCENDING]", getLogRow(1));
+ }
+
+ @Test
+ public void testUserMultiColumnSorting() {
+ openTestURL();
+
+ getGridElement().getHeaderCell(0, 0).click();
+ new Actions(driver).keyDown(Keys.SHIFT).perform();
+ getGridElement().getHeaderCell(0, 11).click();
+ new Actions(driver).keyUp(Keys.SHIFT).perform();
+
+ String prev = getGridElement().getCell(0, 11).getAttribute("innerHTML");
+ for (int i = 1; i <= 6; ++i) {
+ assertEquals("Column 11 should contain same values.", prev,
+ getGridElement().getCell(i, 11).getAttribute("innerHTML"));
+ }
+
+ prev = getGridElement().getCell(0, 0).getText();
+ for (int i = 1; i <= 6; ++i) {
+ assertTrue(
+ "Grid is not sorted by column 0.",
+ prev.compareTo(getGridElement().getCell(i, 0).getText()) < 0);
+ }
+
+ }
+
+ private void sortBy(String column) {
+ selectMenuPath("Component", "State", "Sort by column", column);
+ }
+}
--- /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.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+public class GridStaticSectionComponentTest extends GridBasicFeaturesTest {
+
+ @Test
+ public void testNativeButtonInHeader() throws IOException {
+ openTestURL();
+
+ selectMenuPath("Component", "Columns", "Column 1", "Header Type",
+ "Widget Header");
+
+ getGridElement().$(ButtonElement.class).first().click();
+
+ // Clicking also triggers sorting
+ assertEquals("2. Button clicked!", getLogRow(2));
+ }
+
+ @Test
+ public void testNativeButtonInFooter() throws IOException {
+ openTestURL();
+
+ selectMenuPath("Component", "Footer", "Visible");
+ selectMenuPath("Component", "Footer", "Append row");
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "Widget Footer");
+
+ getGridElement().$(ButtonElement.class).first().click();
+
+ assertEquals("4. Button clicked!", getLogRow(0));
+ }
+}
--- /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.grid.basicfeatures.server;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+public class GridStructureTest extends GridBasicFeaturesTest {
+
+ @Test
+ public void testHidingColumn() throws Exception {
+ openTestURL();
+
+ // Column 0 should be visible
+ List<TestBenchElement> cells = getGridHeaderRowCells();
+ assertEquals("Column 0", cells.get(0).getText());
+
+ // Hide column 0
+ selectMenuPath("Component", "Columns", "Column 0", "Visible");
+
+ // Column 1 should now be the first cell
+ cells = getGridHeaderRowCells();
+ assertEquals("Column 1", cells.get(0).getText());
+ }
+
+ @Test
+ public void testRemovingColumn() throws Exception {
+ openTestURL();
+
+ // Column 0 should be visible
+ List<TestBenchElement> cells = getGridHeaderRowCells();
+ assertEquals("Column 0", cells.get(0).getText());
+
+ // Hide column 0
+ selectMenuPath("Component", "Columns", "Column 0", "Remove");
+
+ // Column 1 should now be the first cell
+ cells = getGridHeaderRowCells();
+ assertEquals("Column 1", cells.get(0).getText());
+ }
+
+ @Test
+ public void testDataLoadingAfterRowRemoval() throws Exception {
+ openTestURL();
+
+ // Remove columns 2,3,4
+ selectMenuPath("Component", "Columns", "Column 2", "Remove");
+ selectMenuPath("Component", "Columns", "Column 3", "Remove");
+ selectMenuPath("Component", "Columns", "Column 4", "Remove");
+
+ // Scroll so new data is lazy loaded
+ scrollGridVerticallyTo(1000);
+
+ // Let lazy loading do its job
+ sleep(1000);
+
+ // Check that row is loaded
+ assertThat(getGridElement().getCell(11, 0).getText(), not("..."));
+ }
+
+ @Test
+ public void testFreezingColumn() throws Exception {
+ openTestURL();
+
+ // Freeze column 2
+ selectMenuPath("Component", "Columns", "Column 2", "Freeze");
+
+ WebElement cell = getGridElement().getCell(0, 0);
+ assertTrue(cell.getAttribute("class").contains("frozen"));
+
+ cell = getGridElement().getCell(0, 1);
+ assertTrue(cell.getAttribute("class").contains("frozen"));
+ }
+
+ @Test
+ public void testInitialColumnWidths() throws Exception {
+ openTestURL();
+
+ WebElement cell = getGridElement().getCell(0, 0);
+ assertEquals(100, cell.getSize().getWidth());
+
+ cell = getGridElement().getCell(0, 1);
+ assertEquals(150, cell.getSize().getWidth());
+
+ cell = getGridElement().getCell(0, 2);
+ assertEquals(200, cell.getSize().getWidth());
+ }
+
+ @Test
+ public void testColumnWidths() throws Exception {
+ openTestURL();
+
+ // Default column width is 100px
+ WebElement cell = getGridElement().getCell(0, 0);
+ assertEquals(100, cell.getSize().getWidth());
+
+ // Set first column to be 200px wide
+ selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
+ "200px");
+
+ cell = getGridElement().getCell(0, 0);
+ assertEquals(200, cell.getSize().getWidth());
+
+ // Set second column to be 150px wide
+ selectMenuPath("Component", "Columns", "Column 1", "Column 1 Width",
+ "150px");
+ cell = getGridElement().getCell(0, 1);
+ assertEquals(150, cell.getSize().getWidth());
+
+ // Set first column to be auto sized (defaults to 100px currently)
+ selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width",
+ "Auto");
+
+ cell = getGridElement().getCell(0, 0);
+ assertEquals(100, cell.getSize().getWidth());
+ }
+
+ @Test
+ public void testPrimaryStyleNames() throws Exception {
+ openTestURL();
+
+ // v-grid is default primary style namea
+ assertPrimaryStylename("v-grid");
+
+ selectMenuPath("Component", "State", "Primary style name",
+ "v-escalator");
+ assertPrimaryStylename("v-escalator");
+
+ selectMenuPath("Component", "State", "Primary style name", "my-grid");
+ assertPrimaryStylename("my-grid");
+
+ selectMenuPath("Component", "State", "Primary style name", "v-grid");
+ assertPrimaryStylename("v-grid");
+ }
+
+ /**
+ * Test that the current view is updated when a server-side container change
+ * occurs (without scrolling back and forth)
+ */
+ @Test
+ public void testItemSetChangeEvent() throws Exception {
+ openTestURL();
+
+ final By newRow = By.xpath("//td[text()='newcell: 0']");
+
+ assertTrue("Unexpected initial state", !isElementPresent(newRow));
+
+ selectMenuPath("Component", "Body rows", "Add first row");
+ assertTrue("Add row failed", isElementPresent(newRow));
+
+ selectMenuPath("Component", "Body rows", "Remove first row");
+ assertTrue("Remove row failed", !isElementPresent(newRow));
+ }
+
+ /**
+ * Test that the current view is updated when a property's value is reflect
+ * to the client, when the value is modified server-side.
+ */
+ @Test
+ public void testPropertyValueChangeEvent() throws Exception {
+ openTestURL();
+
+ assertEquals("Unexpected cell initial state", "(0, 0)",
+ getGridElement().getCell(0, 0).getText());
+
+ selectMenuPath("Component", "Body rows",
+ "Modify first row (getItemProperty)");
+ assertEquals("(First) modification with getItemProperty failed",
+ "modified: 0", getGridElement().getCell(0, 0).getText());
+
+ selectMenuPath("Component", "Body rows",
+ "Modify first row (getContainerProperty)");
+ assertEquals("(Second) modification with getItemProperty failed",
+ "modified: Column 0", getGridElement().getCell(0, 0).getText());
+ }
+
+ @Test
+ public void testRemovingAllItems() throws Exception {
+ openTestURL();
+
+ selectMenuPath("Component", "Body rows", "Remove all rows");
+
+ assertEquals(0, getGridElement().findElement(By.tagName("tbody"))
+ .findElements(By.tagName("tr")).size());
+ }
+
+ private void assertPrimaryStylename(String stylename) {
+ assertTrue(getGridElement().getAttribute("class").contains(stylename));
+
+ String tableWrapperStyleName = getGridElement().getTableWrapper()
+ .getAttribute("class");
+ assertTrue(tableWrapperStyleName.contains(stylename + "-tablewrapper"));
+
+ String hscrollStyleName = getGridElement().getHorizontalScroller()
+ .getAttribute("class");
+ assertTrue(hscrollStyleName.contains(stylename + "-scroller"));
+ assertTrue(hscrollStyleName
+ .contains(stylename + "-scroller-horizontal"));
+
+ String vscrollStyleName = getGridElement().getVerticalScroller()
+ .getAttribute("class");
+ assertTrue(vscrollStyleName.contains(stylename + "-scroller"));
+ assertTrue(vscrollStyleName.contains(stylename + "-scroller-vertical"));
+ }
+}
+++ /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.widgetset.client.grid;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Random;
-
-import com.google.gwt.core.client.Scheduler.ScheduledCommand;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.HTML;
-import com.vaadin.client.ui.grid.FlyweightCell;
-import com.vaadin.client.ui.grid.Grid;
-import com.vaadin.client.ui.grid.Grid.SelectionMode;
-import com.vaadin.client.ui.grid.GridColumn;
-import com.vaadin.client.ui.grid.GridFooter;
-import com.vaadin.client.ui.grid.GridFooter.FooterRow;
-import com.vaadin.client.ui.grid.GridHeader;
-import com.vaadin.client.ui.grid.GridHeader.HeaderRow;
-import com.vaadin.client.ui.grid.Renderer;
-import com.vaadin.client.ui.grid.datasources.ListDataSource;
-import com.vaadin.client.ui.grid.datasources.ListSorter;
-import com.vaadin.client.ui.grid.renderers.DateRenderer;
-import com.vaadin.client.ui.grid.renderers.HtmlRenderer;
-import com.vaadin.client.ui.grid.renderers.NumberRenderer;
-import com.vaadin.client.ui.grid.renderers.TextRenderer;
-import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeatures.Data;
-
-/**
- * Grid basic client features test application.
- *
- * @since
- * @author Vaadin Ltd
- */
-public class GridBasicClientFeatures extends
- PureGWTTestApplication<Grid<List<Data>>> {
-
- public static enum Renderers {
- TEXT_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER;
- }
-
- private static final int MANUALLY_FORMATTED_COLUMNS = 5;
- public static final int COLUMNS = 12;
- public static final int ROWS = 1000;
-
- private final Grid<List<Data>> grid;
- private final List<List<Data>> data;
- private final ListDataSource<List<Data>> ds;
- private final ListSorter<List<Data>> sorter;
-
- /**
- * Our basic data object
- */
- public final static class Data {
- Object value;
- }
-
- /**
- * Convenience method for creating a list of Data objects to be used as a
- * Row in the data source
- *
- * @param cols
- * number of columns (items) to include in the row
- * @return
- */
- private List<Data> createDataRow(int cols) {
- List<Data> list = new ArrayList<Data>(cols);
- for (int i = 0; i < cols; ++i) {
- list.add(new Data());
- }
- data.add(list);
- return list;
- }
-
- @SuppressWarnings("unchecked")
- public GridBasicClientFeatures() {
- super(new Grid<List<Data>>());
-
- // Initialize data source
- data = new ArrayList<List<Data>>();
- {
- Random rand = new Random();
- rand.setSeed(13334);
- long timestamp = 0;
- for (int row = 0; row < ROWS; row++) {
-
- List<Data> datarow = createDataRow(COLUMNS);
- Data d;
-
- int col = 0;
- for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) {
- d = datarow.get(col);
- d.value = "(" + row + ", " + col + ")";
- }
-
- d = datarow.get(col++);
- d.value = Integer.valueOf(row);
-
- d = datarow.get(col++);
- d.value = new Date(timestamp);
- timestamp += 91250000; // a bit over a day, just to get
- // variation
-
- d = datarow.get(col++);
- d.value = "<b>" + row + "</b>";
-
- d = datarow.get(col++);
- d.value = Integer.valueOf(rand.nextInt());
-
- d = datarow.get(col++);
- d.value = Integer.valueOf(rand.nextInt(5));
- }
- }
-
- ds = new ListDataSource<List<Data>>(data);
- grid = getTestedWidget();
- grid.getElement().setId("testComponent");
- grid.setDataSource(ds);
- grid.setSelectionMode(SelectionMode.NONE);
-
- sorter = new ListSorter<List<Data>>(grid);
-
- // Create a bunch of grid columns
-
- // Data source layout:
- // text (String) * (COLUMNS - MANUALLY_FORMATTED_COLUMNS + 1) |
- // rownumber (Integer) | some date (Date) | row number as HTML (String)
- // | random value (Integer)
-
- int col = 0;
-
- // Text times COLUMNS - MANUALLY_FORMATTED_COLUMNS
- for (col = 0; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) {
-
- final int c = col;
-
- GridColumn<String, List<Data>> column = new GridColumn<String, List<Data>>(
- createRenderer(Renderers.TEXT_RENDERER)) {
- @Override
- public String getValue(List<Data> row) {
- return (String) row.get(c).value;
- }
- };
-
- column.setWidth(50 + c * 25);
-
- grid.addColumn(column);
-
- }
-
- // Integer row number
- {
- final int c = col++;
- grid.addColumn(new GridColumn<Integer, List<Data>>(
- createRenderer(Renderers.NUMBER_RENDERER)) {
- @Override
- public Integer getValue(List<Data> row) {
- return (Integer) row.get(c).value;
- }
- });
- }
-
- // Some date
- {
- final int c = col++;
- grid.addColumn(new GridColumn<Date, List<Data>>(
- createRenderer(Renderers.DATE_RENDERER)) {
- @Override
- public Date getValue(List<Data> row) {
- return (Date) row.get(c).value;
- }
- });
- }
-
- // Row number as a HTML string
- {
- final int c = col++;
- grid.addColumn(new GridColumn<String, List<Data>>(
- createRenderer(Renderers.HTML_RENDERER)) {
- @Override
- public String getValue(List<Data> row) {
- return (String) row.get(c).value;
- }
- });
- }
-
- // Random integer value
- {
- final int c = col++;
- grid.addColumn(new GridColumn<Integer, List<Data>>(
- createRenderer(Renderers.NUMBER_RENDERER)) {
- @Override
- public Integer getValue(List<Data> row) {
- return (Integer) row.get(c).value;
- }
- });
- }
-
- // Random integer value between 0 and 5
- {
- final int c = col++;
- grid.addColumn(new GridColumn<Integer, List<Data>>(
- createRenderer(Renderers.NUMBER_RENDERER)) {
- @Override
- public Integer getValue(List<Data> row) {
- return (Integer) row.get(c).value;
- }
- });
- }
-
- setHeaderTexts(grid.getHeader().getRow(0));
-
- //
- // Populate the menu
- //
-
- createStateMenu();
- createColumnsMenu();
- createHeaderMenu();
- createFooterMenu();
-
- grid.getElement().getStyle().setZIndex(0);
- add(grid);
- }
-
- private void createStateMenu() {
- String[] selectionModePath = { "Component", "State", "Selection mode" };
- String[] primaryStyleNamePath = { "Component", "State",
- "Primary Stylename" };
-
- addMenuCommand("multi", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.MULTI);
- }
- }, selectionModePath);
-
- addMenuCommand("single", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- }
- }, selectionModePath);
-
- addMenuCommand("none", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.NONE);
- }
- }, selectionModePath);
-
- addMenuCommand("v-grid", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setStylePrimaryName("v-grid");
-
- }
- }, primaryStyleNamePath);
-
- addMenuCommand("v-escalator", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setStylePrimaryName("v-escalator");
-
- }
- }, primaryStyleNamePath);
-
- addMenuCommand("v-custom-style", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setStylePrimaryName("v-custom-style");
-
- }
- }, primaryStyleNamePath);
-
- }
-
- private void createColumnsMenu() {
-
- for (int i = 0; i < COLUMNS; i++) {
- final int index = i;
- addMenuCommand("Visible", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getColumn(index).setVisible(
- !grid.getColumn(index).isVisible());
- }
- }, "Component", "Columns", "Column " + i);
- addMenuCommand("Sortable", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getColumn(index).setSortable(
- !grid.getColumn(index).isSortable());
- }
- }, "Component", "Columns", "Column " + i);
-
- addMenuCommand("auto", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getColumn(index).setWidth(-1);
- }
- }, "Component", "Columns", "Column " + i, "Width");
- addMenuCommand("50px", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getColumn(index).setWidth(50);
- }
- }, "Component", "Columns", "Column " + i, "Width");
- addMenuCommand("200px", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getColumn(index).setWidth(200);
- }
- }, "Component", "Columns", "Column " + i, "Width");
-
- // Header types
- addMenuCommand("Text Header", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getHeader().getRow(0).getCell(index)
- .setText("Text Header");
- }
- }, "Component", "Columns", "Column " + i, "Header Type");
- addMenuCommand("HTML Header", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getHeader().getRow(0).getCell(index)
- .setHtml("<b>HTML Header</b>");
- }
- }, "Component", "Columns", "Column " + i, "Header Type");
- addMenuCommand("Widget Header", new ScheduledCommand() {
- @Override
- public void execute() {
- final Button button = new Button("Button Header");
- button.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
- button.setText("Clicked");
- }
- });
- grid.getHeader().getRow(0).getCell(index).setWidget(button);
- }
- }, "Component", "Columns", "Column " + i, "Header Type");
-
- // Footer types
- addMenuCommand("Text Footer", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getFooter().getRow(0).getCell(index)
- .setText("Text Footer");
- }
- }, "Component", "Columns", "Column " + i, "Footer Type");
- addMenuCommand("HTML Footer", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getFooter().getRow(0).getCell(index)
- .setHtml("<b>HTML Footer</b>");
- }
- }, "Component", "Columns", "Column " + i, "Footer Type");
- addMenuCommand("Widget Footer", new ScheduledCommand() {
- @Override
- public void execute() {
- final Button button = new Button("Button Footer");
- button.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
- button.setText("Clicked");
- }
- });
- grid.getFooter().getRow(0).getCell(index).setWidget(button);
- }
- }, "Component", "Columns", "Column " + i, "Footer Type");
- }
- }
-
- private int headerCounter = 0;
- private int footerCounter = 0;
-
- private void setHeaderTexts(HeaderRow row) {
- for (int i = 0; i < COLUMNS; ++i) {
- String caption = "Header (" + headerCounter + "," + i + ")";
-
- // Lets use some different cell types
- if (i % 3 == 0) {
- row.getCell(i).setText(caption);
- } else if (i % 2 == 0) {
- row.getCell(i).setHtml("<b>" + caption + "</b>");
- } else {
- row.getCell(i).setWidget(new HTML(caption));
- }
- }
- headerCounter++;
- }
-
- private void setFooterTexts(FooterRow row) {
- for (int i = 0; i < COLUMNS; ++i) {
- String caption = "Footer (" + footerCounter + "," + i + ")";
-
- // Lets use some different cell types
- if (i % 3 == 0) {
- row.getCell(i).setText(caption);
- } else if (i % 2 == 0) {
- row.getCell(i).setHtml("<b>" + caption + "</b>");
- } else {
- row.getCell(i).setWidget(new HTML(caption));
- }
- }
- footerCounter++;
- }
-
- private void createHeaderMenu() {
- final GridHeader header = grid.getHeader();
- final String[] menuPath = { "Component", "Header" };
-
- addMenuCommand("Visible", new ScheduledCommand() {
- @Override
- public void execute() {
- header.setVisible(!header.isVisible());
- }
- }, menuPath);
-
- addMenuCommand("Top", new ScheduledCommand() {
- @Override
- public void execute() {
- header.setDefaultRow(header.getRow(0));
- }
- }, "Component", "Header", "Default row");
- addMenuCommand("Bottom", new ScheduledCommand() {
- @Override
- public void execute() {
- header.setDefaultRow(header.getRow(header.getRowCount() - 1));
- }
- }, "Component", "Header", "Default row");
- addMenuCommand("Unset", new ScheduledCommand() {
- @Override
- public void execute() {
- header.setDefaultRow(null);
- }
- }, "Component", "Header", "Default row");
-
- addMenuCommand("Prepend row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureHeaderRow(header.prependRow());
- }
- }, menuPath);
- addMenuCommand("Append row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureHeaderRow(header.appendRow());
- }
- }, menuPath);
- addMenuCommand("Remove top row", new ScheduledCommand() {
- @Override
- public void execute() {
- header.removeRow(0);
- }
- }, menuPath);
- addMenuCommand("Remove bottom row", new ScheduledCommand() {
- @Override
- public void execute() {
- header.removeRow(header.getRowCount() - 1);
- }
- }, menuPath);
-
- }
-
- private void configureHeaderRow(final HeaderRow row) {
- final GridHeader header = grid.getHeader();
- setHeaderTexts(row);
- String rowTitle = "Row " + header.getRowCount();
- final String[] menuPath = { "Component", "Header", rowTitle };
-
- addMenuCommand("Join column cells 0, 1", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(row.getCell(0), row.getCell(1));
-
- }
- }, menuPath);
-
- addMenuCommand("Join columns 1, 2", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumn(1), grid.getColumn(2));
-
- }
- }, menuPath);
-
- addMenuCommand("Join columns 3, 4, 5", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumn(3), grid.getColumn(4),
- grid.getColumn(5));
-
- }
- }, menuPath);
-
- addMenuCommand("Join all columns", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumns().toArray(
- new GridColumn[grid.getColumnCount()]));
-
- }
- }, menuPath);
- }
-
- private void createFooterMenu() {
- final GridFooter footer = grid.getFooter();
- final String[] menuPath = { "Component", "Footer" };
-
- addMenuCommand("Visible", new ScheduledCommand() {
- @Override
- public void execute() {
- footer.setVisible(!footer.isVisible());
- }
- }, menuPath);
-
- addMenuCommand("Prepend row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureFooterRow(footer.prependRow());
- }
- }, menuPath);
- addMenuCommand("Append row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureFooterRow(footer.appendRow());
- }
- }, menuPath);
- addMenuCommand("Remove top row", new ScheduledCommand() {
- @Override
- public void execute() {
- footer.removeRow(0);
- }
- }, menuPath);
- addMenuCommand("Remove bottom row", new ScheduledCommand() {
- @Override
- public void execute() {
- assert footer.getRowCount() > 0;
- footer.removeRow(footer.getRowCount() - 1);
- }
- }, menuPath);
- }
-
- private void configureFooterRow(final FooterRow row) {
- final GridFooter footer = grid.getFooter();
- setFooterTexts(row);
- String rowTitle = "Row " + footer.getRowCount();
- final String[] menuPath = { "Component", "Footer", rowTitle };
-
- addMenuCommand("Join column cells 0, 1", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(row.getCell(0), row.getCell(1));
-
- }
- }, menuPath);
-
- addMenuCommand("Join columns 1, 2", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumn(1), grid.getColumn(2));
-
- }
- }, menuPath);
-
- addMenuCommand("Join all columns", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumns().toArray(
- new GridColumn[grid.getColumnCount()]));
-
- }
- }, menuPath);
- }
-
- /**
- * Creates a a renderer for a {@link Renderers}
- */
- @SuppressWarnings("rawtypes")
- private final Renderer createRenderer(Renderers renderer) {
- switch (renderer) {
- case TEXT_RENDERER:
- return new TextRenderer();
-
- case HTML_RENDERER:
- return new HtmlRenderer() {
-
- @Override
- public void render(FlyweightCell cell, String htmlString) {
- super.render(cell, "<b>" + htmlString + "</b>");
- }
- };
-
- case NUMBER_RENDERER:
- return new NumberRenderer<Integer>();
-
- case DATE_RENDERER:
- return new DateRenderer();
-
- default:
- return new TextRenderer();
- }
- }
-}
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeatures.GridTestComponent;
/**
* Connector for the GridClientBasicFeatures ApplicationWidget
- *
+ *
* @since
* @author Vaadin Ltd
*/
-@Connect(com.vaadin.tests.widgetset.server.grid.GridBasicClientFeatures.GridTestComponent.class)
+@Connect(GridTestComponent.class)
public class GridBasicClientFeaturesConnector extends
AbstractComponentConnector {
@Override
- public GridBasicClientFeatures getWidget() {
- return (GridBasicClientFeatures) super.getWidget();
+ public GridBasicClientFeaturesWidget getWidget() {
+ return (GridBasicClientFeaturesWidget) super.getWidget();
}
}
--- /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.widgetset.client.grid;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.client.ui.grid.FlyweightCell;
+import com.vaadin.client.ui.grid.Grid;
+import com.vaadin.client.ui.grid.Grid.SelectionMode;
+import com.vaadin.client.ui.grid.GridColumn;
+import com.vaadin.client.ui.grid.GridFooter;
+import com.vaadin.client.ui.grid.GridFooter.FooterRow;
+import com.vaadin.client.ui.grid.GridHeader;
+import com.vaadin.client.ui.grid.GridHeader.HeaderRow;
+import com.vaadin.client.ui.grid.Renderer;
+import com.vaadin.client.ui.grid.datasources.ListDataSource;
+import com.vaadin.client.ui.grid.datasources.ListSorter;
+import com.vaadin.client.ui.grid.renderers.DateRenderer;
+import com.vaadin.client.ui.grid.renderers.HtmlRenderer;
+import com.vaadin.client.ui.grid.renderers.NumberRenderer;
+import com.vaadin.client.ui.grid.renderers.TextRenderer;
+import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget.Data;
+
+/**
+ * Grid basic client features test application.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class GridBasicClientFeaturesWidget extends
+ PureGWTTestApplication<Grid<List<Data>>> {
+
+ public static enum Renderers {
+ TEXT_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER;
+ }
+
+ private static final int MANUALLY_FORMATTED_COLUMNS = 5;
+ public static final int COLUMNS = 12;
+ public static final int ROWS = 1000;
+
+ private final Grid<List<Data>> grid;
+ private final List<List<Data>> data;
+ private final ListDataSource<List<Data>> ds;
+ private final ListSorter<List<Data>> sorter;
+
+ /**
+ * Our basic data object
+ */
+ public final static class Data {
+ Object value;
+ }
+
+ /**
+ * Convenience method for creating a list of Data objects to be used as a
+ * Row in the data source
+ *
+ * @param cols
+ * number of columns (items) to include in the row
+ * @return
+ */
+ private List<Data> createDataRow(int cols) {
+ List<Data> list = new ArrayList<Data>(cols);
+ for (int i = 0; i < cols; ++i) {
+ list.add(new Data());
+ }
+ data.add(list);
+ return list;
+ }
+
+ @SuppressWarnings("unchecked")
+ public GridBasicClientFeaturesWidget() {
+ super(new Grid<List<Data>>());
+
+ // Initialize data source
+ data = new ArrayList<List<Data>>();
+ {
+ Random rand = new Random();
+ rand.setSeed(13334);
+ long timestamp = 0;
+ for (int row = 0; row < ROWS; row++) {
+
+ List<Data> datarow = createDataRow(COLUMNS);
+ Data d;
+
+ int col = 0;
+ for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) {
+ d = datarow.get(col);
+ d.value = "(" + row + ", " + col + ")";
+ }
+
+ d = datarow.get(col++);
+ d.value = Integer.valueOf(row);
+
+ d = datarow.get(col++);
+ d.value = new Date(timestamp);
+ timestamp += 91250000; // a bit over a day, just to get
+ // variation
+
+ d = datarow.get(col++);
+ d.value = "<b>" + row + "</b>";
+
+ d = datarow.get(col++);
+ d.value = Integer.valueOf(rand.nextInt());
+
+ d = datarow.get(col++);
+ d.value = Integer.valueOf(rand.nextInt(5));
+ }
+ }
+
+ ds = new ListDataSource<List<Data>>(data);
+ grid = getTestedWidget();
+ grid.getElement().setId("testComponent");
+ grid.setDataSource(ds);
+ grid.setSelectionMode(SelectionMode.NONE);
+
+ sorter = new ListSorter<List<Data>>(grid);
+
+ // Create a bunch of grid columns
+
+ // Data source layout:
+ // text (String) * (COLUMNS - MANUALLY_FORMATTED_COLUMNS + 1) |
+ // rownumber (Integer) | some date (Date) | row number as HTML (String)
+ // | random value (Integer)
+
+ int col = 0;
+
+ // Text times COLUMNS - MANUALLY_FORMATTED_COLUMNS
+ for (col = 0; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) {
+
+ final int c = col;
+
+ GridColumn<String, List<Data>> column = new GridColumn<String, List<Data>>(
+ createRenderer(Renderers.TEXT_RENDERER)) {
+ @Override
+ public String getValue(List<Data> row) {
+ return (String) row.get(c).value;
+ }
+ };
+
+ column.setWidth(50 + c * 25);
+
+ grid.addColumn(column);
+
+ }
+
+ // Integer row number
+ {
+ final int c = col++;
+ grid.addColumn(new GridColumn<Integer, List<Data>>(
+ createRenderer(Renderers.NUMBER_RENDERER)) {
+ @Override
+ public Integer getValue(List<Data> row) {
+ return (Integer) row.get(c).value;
+ }
+ });
+ }
+
+ // Some date
+ {
+ final int c = col++;
+ grid.addColumn(new GridColumn<Date, List<Data>>(
+ createRenderer(Renderers.DATE_RENDERER)) {
+ @Override
+ public Date getValue(List<Data> row) {
+ return (Date) row.get(c).value;
+ }
+ });
+ }
+
+ // Row number as a HTML string
+ {
+ final int c = col++;
+ grid.addColumn(new GridColumn<String, List<Data>>(
+ createRenderer(Renderers.HTML_RENDERER)) {
+ @Override
+ public String getValue(List<Data> row) {
+ return (String) row.get(c).value;
+ }
+ });
+ }
+
+ // Random integer value
+ {
+ final int c = col++;
+ grid.addColumn(new GridColumn<Integer, List<Data>>(
+ createRenderer(Renderers.NUMBER_RENDERER)) {
+ @Override
+ public Integer getValue(List<Data> row) {
+ return (Integer) row.get(c).value;
+ }
+ });
+ }
+
+ // Random integer value between 0 and 5
+ {
+ final int c = col++;
+ grid.addColumn(new GridColumn<Integer, List<Data>>(
+ createRenderer(Renderers.NUMBER_RENDERER)) {
+ @Override
+ public Integer getValue(List<Data> row) {
+ return (Integer) row.get(c).value;
+ }
+ });
+ }
+
+ setHeaderTexts(grid.getHeader().getRow(0));
+
+ //
+ // Populate the menu
+ //
+
+ createStateMenu();
+ createColumnsMenu();
+ createHeaderMenu();
+ createFooterMenu();
+
+ grid.getElement().getStyle().setZIndex(0);
+ add(grid);
+ }
+
+ private void createStateMenu() {
+ String[] selectionModePath = { "Component", "State", "Selection mode" };
+ String[] primaryStyleNamePath = { "Component", "State",
+ "Primary Stylename" };
+
+ addMenuCommand("multi", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ }
+ }, selectionModePath);
+
+ addMenuCommand("single", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ }
+ }, selectionModePath);
+
+ addMenuCommand("none", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ }
+ }, selectionModePath);
+
+ addMenuCommand("v-grid", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setStylePrimaryName("v-grid");
+
+ }
+ }, primaryStyleNamePath);
+
+ addMenuCommand("v-escalator", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setStylePrimaryName("v-escalator");
+
+ }
+ }, primaryStyleNamePath);
+
+ addMenuCommand("v-custom-style", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.setStylePrimaryName("v-custom-style");
+
+ }
+ }, primaryStyleNamePath);
+
+ }
+
+ private void createColumnsMenu() {
+
+ for (int i = 0; i < COLUMNS; i++) {
+ final int index = i;
+ addMenuCommand("Visible", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setVisible(
+ !grid.getColumn(index).isVisible());
+ }
+ }, "Component", "Columns", "Column " + i);
+ addMenuCommand("Sortable", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setSortable(
+ !grid.getColumn(index).isSortable());
+ }
+ }, "Component", "Columns", "Column " + i);
+
+ addMenuCommand("auto", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setWidth(-1);
+ }
+ }, "Component", "Columns", "Column " + i, "Width");
+ addMenuCommand("50px", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setWidth(50);
+ }
+ }, "Component", "Columns", "Column " + i, "Width");
+ addMenuCommand("200px", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getColumn(index).setWidth(200);
+ }
+ }, "Component", "Columns", "Column " + i, "Width");
+
+ // Header types
+ addMenuCommand("Text Header", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getHeader().getRow(0).getCell(index)
+ .setText("Text Header");
+ }
+ }, "Component", "Columns", "Column " + i, "Header Type");
+ addMenuCommand("HTML Header", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getHeader().getRow(0).getCell(index)
+ .setHtml("<b>HTML Header</b>");
+ }
+ }, "Component", "Columns", "Column " + i, "Header Type");
+ addMenuCommand("Widget Header", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ final Button button = new Button("Button Header");
+ button.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ button.setText("Clicked");
+ }
+ });
+ grid.getHeader().getRow(0).getCell(index).setWidget(button);
+ }
+ }, "Component", "Columns", "Column " + i, "Header Type");
+
+ // Footer types
+ addMenuCommand("Text Footer", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getFooter().getRow(0).getCell(index)
+ .setText("Text Footer");
+ }
+ }, "Component", "Columns", "Column " + i, "Footer Type");
+ addMenuCommand("HTML Footer", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ grid.getFooter().getRow(0).getCell(index)
+ .setHtml("<b>HTML Footer</b>");
+ }
+ }, "Component", "Columns", "Column " + i, "Footer Type");
+ addMenuCommand("Widget Footer", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ final Button button = new Button("Button Footer");
+ button.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ button.setText("Clicked");
+ }
+ });
+ grid.getFooter().getRow(0).getCell(index).setWidget(button);
+ }
+ }, "Component", "Columns", "Column " + i, "Footer Type");
+ }
+ }
+
+ private int headerCounter = 0;
+ private int footerCounter = 0;
+
+ private void setHeaderTexts(HeaderRow row) {
+ for (int i = 0; i < COLUMNS; ++i) {
+ String caption = "Header (" + headerCounter + "," + i + ")";
+
+ // Lets use some different cell types
+ if (i % 3 == 0) {
+ row.getCell(i).setText(caption);
+ } else if (i % 2 == 0) {
+ row.getCell(i).setHtml("<b>" + caption + "</b>");
+ } else {
+ row.getCell(i).setWidget(new HTML(caption));
+ }
+ }
+ headerCounter++;
+ }
+
+ private void setFooterTexts(FooterRow row) {
+ for (int i = 0; i < COLUMNS; ++i) {
+ String caption = "Footer (" + footerCounter + "," + i + ")";
+
+ // Lets use some different cell types
+ if (i % 3 == 0) {
+ row.getCell(i).setText(caption);
+ } else if (i % 2 == 0) {
+ row.getCell(i).setHtml("<b>" + caption + "</b>");
+ } else {
+ row.getCell(i).setWidget(new HTML(caption));
+ }
+ }
+ footerCounter++;
+ }
+
+ private void createHeaderMenu() {
+ final GridHeader header = grid.getHeader();
+ final String[] menuPath = { "Component", "Header" };
+
+ addMenuCommand("Visible", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ header.setVisible(!header.isVisible());
+ }
+ }, menuPath);
+
+ addMenuCommand("Top", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ header.setDefaultRow(header.getRow(0));
+ }
+ }, "Component", "Header", "Default row");
+ addMenuCommand("Bottom", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ header.setDefaultRow(header.getRow(header.getRowCount() - 1));
+ }
+ }, "Component", "Header", "Default row");
+ addMenuCommand("Unset", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ header.setDefaultRow(null);
+ }
+ }, "Component", "Header", "Default row");
+
+ addMenuCommand("Prepend row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ configureHeaderRow(header.prependRow());
+ }
+ }, menuPath);
+ addMenuCommand("Append row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ configureHeaderRow(header.appendRow());
+ }
+ }, menuPath);
+ addMenuCommand("Remove top row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ header.removeRow(0);
+ }
+ }, menuPath);
+ addMenuCommand("Remove bottom row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ header.removeRow(header.getRowCount() - 1);
+ }
+ }, menuPath);
+
+ }
+
+ private void configureHeaderRow(final HeaderRow row) {
+ final GridHeader header = grid.getHeader();
+ setHeaderTexts(row);
+ String rowTitle = "Row " + header.getRowCount();
+ final String[] menuPath = { "Component", "Header", rowTitle };
+
+ addMenuCommand("Join column cells 0, 1", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(row.getCell(0), row.getCell(1));
+
+ }
+ }, menuPath);
+
+ addMenuCommand("Join columns 1, 2", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(grid.getColumn(1), grid.getColumn(2));
+
+ }
+ }, menuPath);
+
+ addMenuCommand("Join columns 3, 4, 5", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(grid.getColumn(3), grid.getColumn(4),
+ grid.getColumn(5));
+
+ }
+ }, menuPath);
+
+ addMenuCommand("Join all columns", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(grid.getColumns().toArray(
+ new GridColumn[grid.getColumnCount()]));
+
+ }
+ }, menuPath);
+ }
+
+ private void createFooterMenu() {
+ final GridFooter footer = grid.getFooter();
+ final String[] menuPath = { "Component", "Footer" };
+
+ addMenuCommand("Visible", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ footer.setVisible(!footer.isVisible());
+ }
+ }, menuPath);
+
+ addMenuCommand("Prepend row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ configureFooterRow(footer.prependRow());
+ }
+ }, menuPath);
+ addMenuCommand("Append row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ configureFooterRow(footer.appendRow());
+ }
+ }, menuPath);
+ addMenuCommand("Remove top row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ footer.removeRow(0);
+ }
+ }, menuPath);
+ addMenuCommand("Remove bottom row", new ScheduledCommand() {
+ @Override
+ public void execute() {
+ assert footer.getRowCount() > 0;
+ footer.removeRow(footer.getRowCount() - 1);
+ }
+ }, menuPath);
+ }
+
+ private void configureFooterRow(final FooterRow row) {
+ final GridFooter footer = grid.getFooter();
+ setFooterTexts(row);
+ String rowTitle = "Row " + footer.getRowCount();
+ final String[] menuPath = { "Component", "Footer", rowTitle };
+
+ addMenuCommand("Join column cells 0, 1", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(row.getCell(0), row.getCell(1));
+
+ }
+ }, menuPath);
+
+ addMenuCommand("Join columns 1, 2", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(grid.getColumn(1), grid.getColumn(2));
+
+ }
+ }, menuPath);
+
+ addMenuCommand("Join all columns", new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ row.join(grid.getColumns().toArray(
+ new GridColumn[grid.getColumnCount()]));
+
+ }
+ }, menuPath);
+ }
+
+ /**
+ * Creates a a renderer for a {@link Renderers}
+ */
+ @SuppressWarnings("rawtypes")
+ private final Renderer createRenderer(Renderers renderer) {
+ switch (renderer) {
+ case TEXT_RENDERER:
+ return new TextRenderer();
+
+ case HTML_RENDERER:
+ return new HtmlRenderer() {
+
+ @Override
+ public void render(FlyweightCell cell, String htmlString) {
+ super.render(cell, "<b>" + htmlString + "</b>");
+ }
+ };
+
+ case NUMBER_RENDERER:
+ return new NumberRenderer<Integer>();
+
+ case DATE_RENDERER:
+ return new DateRenderer();
+
+ default:
+ return new TextRenderer();
+ }
+ }
+}
+++ /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.widgetset.server.grid;
-
-import com.vaadin.annotations.Widgetset;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.widgetset.TestingWidgetSet;
-import com.vaadin.ui.AbstractComponent;
-import com.vaadin.ui.UI;
-
-/**
- * Initializer shell for GridClientBasicFeatures test application
- *
- * @since
- * @author Vaadin Ltd
- */
-@Widgetset(TestingWidgetSet.NAME)
-public class GridBasicClientFeatures extends UI {
-
- public class GridTestComponent extends AbstractComponent {
- }
-
- @Override
- protected void init(VaadinRequest request) {
- setContent(new GridTestComponent());
- }
-
-}