summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2014-11-19 14:13:44 +0200
committerVaadin Code Review <review@vaadin.com>2014-11-21 07:38:02 +0000
commit448d2b9e9b1c673ea5c8dd6b8404b93d753cd569 (patch)
treebd8ae8458fd2bdb8a99147056d29d039d9ca25d5
parent5f6ecda3e745ea0cbfd619fefac7da82ec9e47b2 (diff)
downloadvaadin-framework-448d2b9e9b1c673ea5c8dd6b8404b93d753cd569.tar.gz
vaadin-framework-448d2b9e9b1c673ea5c8dd6b8404b93d753cd569.zip
Fix client headers to return same cell for all merged columns (#13334)
Change-Id: Idad11b8d7a4b6e78e061c15863b99339c317f6f1
-rw-r--r--client/src/com/vaadin/client/ui/grid/GridConnector.java49
-rw-r--r--client/src/com/vaadin/client/ui/grid/GridStaticSection.java10
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridColspans.java15
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java18
4 files changed, 69 insertions, 23 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/GridConnector.java b/client/src/com/vaadin/client/ui/grid/GridConnector.java
index f719b5979e..24ea3ec433 100644
--- a/client/src/com/vaadin/client/ui/grid/GridConnector.java
+++ b/client/src/com/vaadin/client/ui/grid/GridConnector.java
@@ -295,7 +295,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
for (JSONObject row : event.getAdded()) {
- selectedKeys.add((String) dataSource.getRowKey(row));
+ selectedKeys.add(dataSource.getRowKey(row));
}
getRpcProxy(GridServerRpc.class).selectionChange(
@@ -481,29 +481,25 @@ public class GridConnector extends AbstractHasComponentsConnector implements
CustomGridColumn column = columnIdToColumn
.get(cellState.columnId);
GridStaticSection.StaticCell cell = row.getCell(column);
- switch (cellState.type) {
- case TEXT:
- cell.setText(cellState.text);
- break;
- case HTML:
- cell.setHtml(cellState.html);
- break;
- case WIDGET:
- ComponentConnector connector = (ComponentConnector) cellState.connector;
- cell.setWidget(connector.getWidget());
- break;
- default:
- throw new IllegalStateException("unexpected cell type: "
- + cellState.type);
- }
+ updateStaticCellFromState(cell, cellState);
}
for (List<String> group : rowState.cellGroups) {
GridColumn<?, ?>[] columns = new GridColumn<?, ?>[group.size()];
+ String firstId = group.get(0);
+ CellState cellState = null;
+ for (CellState c : rowState.cells) {
+ if (c.columnId.equals(firstId)) {
+ cellState = c;
+ }
+ }
+
for (int i = 0; i < group.size(); ++i) {
columns[i] = columnIdToColumn.get(group.get(i));
}
- row.join(columns);
+
+ // Set state to be the same as first in group.
+ updateStaticCellFromState(row.join(columns), cellState);
}
if (section instanceof GridHeader && rowState.defaultRow) {
@@ -516,6 +512,25 @@ public class GridConnector extends AbstractHasComponentsConnector implements
section.requestSectionRefresh();
}
+ private void updateStaticCellFromState(GridStaticSection.StaticCell 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;
+ cell.setWidget(connector.getWidget());
+ break;
+ default:
+ throw new IllegalStateException("unexpected cell type: "
+ + cellState.type);
+ }
+ }
+
/**
* Updates a column from a state change event.
*
diff --git a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java
index 01248f12d6..52ea80c52b 100644
--- a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java
+++ b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java
@@ -235,14 +235,14 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>>
}
cellGroups.add(Arrays.asList(columns));
+ CELLTYPE joinedCell = createCell();
+ joinedCell.setSection(getSection());
+ for (GridColumn<?, ?> column : columns) {
+ cells.put(column, joinedCell);
+ }
calculateColspans();
- for (i = 0; i < columns.length; ++i) {
- if (columns[i].isVisible()) {
- return getCell(columns[i]);
- }
- }
return getCell(columns[0]);
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridColspans.java b/uitest/src/com/vaadin/tests/components/grid/GridColspans.java
index 7b905d5404..3b3229a652 100644
--- a/uitest/src/com/vaadin/tests/components/grid/GridColspans.java
+++ b/uitest/src/com/vaadin/tests/components/grid/GridColspans.java
@@ -20,7 +20,10 @@ import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.components.grid.Grid;
+import com.vaadin.ui.components.grid.GridColumn;
import com.vaadin.ui.components.grid.GridFooter;
import com.vaadin.ui.components.grid.GridFooter.FooterRow;
import com.vaadin.ui.components.grid.GridHeader;
@@ -32,7 +35,7 @@ public class GridColspans extends AbstractTestUI {
@Override
protected void setup(VaadinRequest request) {
Indexed dataSource = new IndexedContainer();
- Grid grid;
+ final Grid grid;
dataSource.addContainerProperty("firstName", String.class, "");
dataSource.addContainerProperty("lastName", String.class, "");
@@ -64,6 +67,16 @@ public class GridColspans extends AbstractTestUI {
footerRow.join("streetAddress", "zipCode", "city").setText("Address");
footer.appendRow().join(dataSource.getContainerPropertyIds().toArray())
.setText("All the stuff");
+
+ addComponent(new Button("Show/Hide firstName",
+ new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ GridColumn column = grid.getColumn("firstName");
+ column.setVisible(!column.isVisible());
+ }
+ }));
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java b/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java
index ca3d4f9dd0..0191f1d625 100644
--- a/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/GridColspansTest.java
@@ -19,10 +19,12 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
+import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.interactions.Actions;
+import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
@@ -70,4 +72,20 @@ public class GridColspansTest extends MultiBrowserTest {
compareScreen("afterNavigation");
}
+
+ @Test
+ public void testHideFirstColumnOfColspan() {
+ openTestURL();
+
+ GridElement grid = $(GridElement.class).first();
+ Assert.assertEquals("Failed initial condition.",
+ grid.getHeaderCell(0, 1).getText(), "All the stuff");
+ Assert.assertEquals("Failed initial condition.",
+ grid.getHeaderCell(2, 1).getText(), "firstName");
+ $(ButtonElement.class).first().click();
+ Assert.assertEquals("Header text changed on column hide.", grid
+ .getHeaderCell(0, 1).getText(), "All the stuff");
+ Assert.assertEquals("Failed initial condition.", "lastName", grid
+ .getHeaderCell(2, 1).getText());
+ }
}