aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-11-16 11:19:09 +0200
committerVaadin Code Review <review@vaadin.com>2016-11-18 12:28:58 +0000
commit848feaaf30762204cb4d9c7bf8b76fbb8bb675da (patch)
tree510e6c209096d85257f2be388fe44094ab59726a
parent9d6baef98851d0cd5092581f954f9b3ee6908003 (diff)
downloadvaadin-framework-848feaaf30762204cb4d9c7bf8b76fbb8bb675da.tar.gz
vaadin-framework-848feaaf30762204cb4d9c7bf8b76fbb8bb675da.zip
Add HTML/Component support to Grid Footers
Change-Id: Iaffe3214163f66c0617a5bea4b79f4ae39d0bc08
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java30
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java48
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java15
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java69
4 files changed, 154 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
index f5d95dfa80..b7b2fb957d 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
@@ -52,6 +52,7 @@ import com.vaadin.client.widget.grid.sort.SortEvent;
import com.vaadin.client.widget.grid.sort.SortOrder;
import com.vaadin.client.widgets.Grid;
import com.vaadin.client.widgets.Grid.Column;
+import com.vaadin.client.widgets.Grid.FooterCell;
import com.vaadin.client.widgets.Grid.FooterRow;
import com.vaadin.client.widgets.Grid.HeaderCell;
import com.vaadin.client.widgets.Grid.HeaderRow;
@@ -279,11 +280,38 @@ public class GridConnector extends AbstractListingConnector
FooterRow row = grid.appendFooterRow();
rowState.cells.forEach((columnId, cellState) -> {
- row.getCell(getColumn(columnId)).setText(cellState.text);
+ updateFooterCellFromState(row.getCell(getColumn(columnId)),
+ cellState);
});
}
}
+ private void updateFooterCellFromState(FooterCell cell,
+ CellState cellState) {
+ switch (cellState.type) {
+ case TEXT:
+ cell.setText(cellState.text);
+ break;
+ case HTML:
+ cell.setHtml(cellState.html);
+ break;
+ case WIDGET:
+ ComponentConnector connector = (ComponentConnector) cellState.connector;
+ if (connector != null) {
+ cell.setWidget(connector.getWidget());
+ } else {
+ // This happens if you do setVisible(false) on the component on
+ // the server side
+ cell.setWidget(null);
+ }
+ break;
+ default:
+ throw new IllegalStateException(
+ "unexpected cell type: " + cellState.type);
+ }
+ cell.setStyleName(cellState.styleName);
+ }
+
@Override
public void setDataSource(DataSource<JsonObject> dataSource) {
super.setDataSource(dataSource);
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 42aab6a7e4..29c97af24a 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -1647,6 +1647,44 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents {
* the footer caption to set, not null
*/
public void setText(String text);
+
+ /**
+ * Returns the HTML content displayed in this cell.
+ *
+ * @return the html
+ *
+ */
+ public String getHtml();
+
+ /**
+ * Sets the HTML content displayed in this cell.
+ *
+ * @param html
+ * the html to set
+ */
+ public void setHtml(String html);
+
+ /**
+ * Returns the component displayed in this cell.
+ *
+ * @return the component
+ */
+ public Component getComponent();
+
+ /**
+ * Sets the component displayed in this cell.
+ *
+ * @param component
+ * the component to set
+ */
+ public void setComponent(Component component);
+
+ /**
+ * Returns the type of content stored in this cell.
+ *
+ * @return cell content type
+ */
+ public GridStaticCellType getCellType();
}
private class HeaderImpl extends Header {
@@ -1932,6 +1970,16 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents {
}
});
}
+ Footer footer = getFooter();
+ for (int i = 0; i < footer.getRowCount(); ++i) {
+ FooterRow row = footer.getRow(i);
+ getColumns().forEach(column -> {
+ FooterCell cell = row.getCell(column);
+ if (cell.getCellType() == GridStaticCellType.WIDGET) {
+ componentSet.add(cell.getComponent());
+ }
+ });
+ }
return Collections.unmodifiableSet(componentSet).iterator();
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
index 59368b198b..7b48acd400 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
@@ -187,7 +187,8 @@ public class GridBasics extends AbstractTestUIWithLog {
new ProgressBarRenderer()).setCaption(COLUMN_CAPTIONS[7]);
((SingleSelectionModel<DataObject>) grid.getSelectionModel())
- .addSelectionChangeListener(e -> log("Selected: " + e.getValue()));
+ .addSelectionChangeListener(
+ e -> log("Selected: " + e.getValue()));
layout.addComponent(createMenu());
layout.addComponent(grid);
@@ -244,6 +245,18 @@ public class GridBasics extends AbstractTestUIWithLog {
grid.getDefaultHeaderRow().getCell(col).setComponent(button);
});
+ MenuItem footerTypeMenu = columnMenu.addItem("Footer Type", null);
+ footerTypeMenu.addItem("Text Footer", selectedItem -> grid
+ .getFooterRow(0).getCell(col).setText("Text Footer"));
+ footerTypeMenu.addItem("HTML Footer",
+ selectedItem -> grid.getFooterRow(0).getCell(col)
+ .setHtml("<b>HTML Footer</b>"));
+ footerTypeMenu.addItem("Widget Footer", selectedItem -> {
+ final Button button = new Button("Button Footer");
+ button.addClickListener(clickEvent -> log("Button clicked!"));
+ grid.getFooterRow(0).getCell(col).setComponent(button);
+ });
+
columnMenu
.addItem("Sortable",
selectedItem -> col
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java
index 2d0be2a733..bff780ee75 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridHeaderFooterTest.java
@@ -138,9 +138,8 @@ public class GridHeaderFooterTest extends GridBasicsTest {
assertFooterTexts(1, GridBasics.COLUMN_CAPTIONS);
}
- public void testDynamicallyChangingCellType() throws Exception {
- openTestURL();
-
+ @Test
+ public void testDynamicallyChangingHeaderCellType() throws Exception {
selectMenuPath("Component", "Columns", "Column 0", "Header Type",
"Widget Header");
GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0);
@@ -163,8 +162,6 @@ public class GridHeaderFooterTest extends GridBasicsTest {
@Test
public void testButtonInHeader() throws Exception {
- openTestURL();
-
selectMenuPath("Component", "Columns", "Column 1", "Header Type",
"Widget Header");
@@ -176,7 +173,6 @@ public class GridHeaderFooterTest extends GridBasicsTest {
@Test
public void testRemoveComponentFromHeader() throws Exception {
- openTestURL();
selectMenuPath("Component", "Columns", "Column 1", "Header Type",
"Widget Header");
selectMenuPath("Component", "Columns", "Column 1", "Header Type",
@@ -203,6 +199,67 @@ public class GridHeaderFooterTest extends GridBasicsTest {
assertEquals("Column 1", getColumnHidingToggle(1).getText());
}
+ @Test
+ public void testDynamicallyChangingFooterCellType() throws Exception {
+ selectMenuPath("Component", "Columns", "Column 0", "Footer Type",
+ "Widget Footer");
+ GridCellElement widgetCell = getGridElement().getFooterCell(0, 0);
+ assertTrue(widgetCell.isElementPresent(By.className("v-button")));
+
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "HTML Footer");
+ GridCellElement htmlCell = getGridElement().getFooterCell(0, 1);
+ assertEquals("<b>HTML Footer</b>",
+ htmlCell.findElement(
+ By.className("v-grid-column-footer-content"))
+ .getAttribute("innerHTML"));
+
+ selectMenuPath("Component", "Columns", "Column 2", "Footer Type",
+ "Text Footer");
+ GridCellElement textCell = getGridElement().getFooterCell(0, 2);
+
+ assertEquals("text footer", textCell.getText().toLowerCase());
+ }
+
+ @Test
+ public void testButtonInFooter() throws Exception {
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "Widget Footer");
+
+ getGridElement().findElements(By.className("v-button")).get(0).click();
+
+ assertTrue("Button click should be logged",
+ logContainsText("Button clicked!"));
+ }
+
+ @Test
+ public void testRemoveComponentFromFooter() throws Exception {
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "Widget Footer");
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "Text Footer");
+ assertTrue("No notifications should've been shown",
+ !$(NotificationElement.class).exists());
+ assertEquals("Footer should've been reverted back to text footer",
+ "text footer",
+ getGridElement().getFooterCell(0, 1).getText().toLowerCase());
+ }
+
+ @Test
+ public void testColumnHidingToggleCaption_settingWidgetToFooter_toggleCaptionStays() {
+ toggleColumnHidable(1);
+ getSidebarOpenButton().click();
+ assertEquals("column 1",
+ getGridElement().getHeaderCell(0, 1).getText().toLowerCase());
+ assertEquals("Column 1", getColumnHidingToggle(1).getText());
+
+ selectMenuPath("Component", "Columns", "Column 1", "Footer Type",
+ "Widget Footer");
+
+ getSidebarOpenButton().click();
+ assertEquals("Column 1", getColumnHidingToggle(1).getText());
+ }
+
private void toggleColumnHidable(int index) {
selectMenuPath("Component", "Columns", "Column " + index, "Hidable");
}