The old API is marked as deprecated and does not work anymore.
Currently supported:
* A single hard-coded header
* Text captions
TODO:
* Footers
* 0..n headers and footers
* Column spanning
* HTML content
* Widget content
* Component content
* Sorting/Indicators
* Server side API
* Shared state handling
Change-Id: I0448c36c8406807037b5e21e2db205a2ee24bc8a
* @author Vaadin Ltd
* @see ColumnGroupRow#addGroup(ColumnGroup...)
*/
+@Deprecated
public class ColumnGroup<T> {
/**
* @since
* @author Vaadin Ltd
*/
+@Deprecated
public class ColumnGroupRow<T> {
/**
*/
private Escalator escalator = GWT.create(Escalator.class);
+ private GridHeader header = GWT.create(GridHeader.class);
+
/**
* List of columns in the grid. Order defines the visible order.
*/
/**
* The column groups rows added to the grid
*/
+ @Deprecated
private final List<ColumnGroupRow<T>> columnGroupRows = new ArrayList<ColumnGroupRow<T>>();
/**
* Are the headers for the columns visible
*/
+ @Deprecated
private boolean columnHeadersVisible = true;
/**
* Are the footers for the columns visible
*/
+ @Deprecated
private boolean columnFootersVisible = false;
/**
/**
* The text displayed in the header of the column
*/
+ @Deprecated
private String header;
/**
* Text displayed in the column footer
*/
+ @Deprecated
private String footer;
/**
/**
* Renderer for rendering the header cell value into the cell
*/
+ @Deprecated
private Renderer<String> headerRenderer = new SortableColumnHeaderRenderer(
new TextRenderer());
/**
* Renderer for rendering the footer cell value into the cell
*/
+ @Deprecated
private Renderer<String> footerRenderer = new TextRenderer();
private boolean sortable = false;
*
* @return the text displayed in the column caption
*/
+ @Deprecated
public String getHeaderCaption() {
return header;
}
*
* @return a renderer that renders header cells
*/
+ @Deprecated
public Renderer<String> getHeaderRenderer() {
return headerRenderer;
}
* @param renderer
* The renderer to use for rendering header cells.
*/
+ @Deprecated
public void setHeaderRenderer(Renderer<String> renderer) {
if (renderer == null) {
throw new IllegalArgumentException("Renderer cannot be null.");
*
* @return a renderer that renders footer cells
*/
+ @Deprecated
public Renderer<String> getFooterRenderer() {
return footerRenderer;
}
* @param renderer
* The renderer to use for rendering footer cells.
*/
+ @Deprecated
public void setFooterRenderer(Renderer<String> renderer) {
if (renderer == null) {
throw new IllegalArgumentException("Renderer cannot be null.");
* @param caption
* the text displayed in the column header
*/
+ @Deprecated
public void setHeaderCaption(String caption) {
if (SharedUtil.equals(caption, header)) {
return;
*
* @return The text displayed in the footer of the column
*/
+ @Deprecated
public String getFooterCaption() {
return footer;
}
* @param caption
* the text displayed in the footer of the column
*/
+ @Deprecated
public void setFooterCaption(String caption) {
if (SharedUtil.equals(caption, footer)) {
return;
/**
* Base class for header / footer escalator updater
*/
+ @Deprecated
protected abstract class HeaderFooterEscalatorUpdater implements
EscalatorUpdater {
* @return the updater that updates the data in the escalator.
*/
private EscalatorUpdater createHeaderUpdater() {
- return new HeaderFooterEscalatorUpdater(escalator.getHeader(), true) {
+ return new EscalatorUpdater() {
@Override
- public boolean isRowVisible(ColumnGroupRow<T> row) {
- return row.isHeaderVisible();
- }
+ public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) {
+ GridHeader.HeaderRow headerRow = header.getRow(row.getRow());
- @Override
- public String getGroupValue(ColumnGroup<T> group) {
- return group.getHeaderCaption();
+ int colIndex = -1;
+ for (FlyweightCell cell : cellsToUpdate) {
+ if (colIndex == -1) {
+ colIndex = cell.getColumn();
+ }
+ while (!columns.get(colIndex).isVisible()) {
+ colIndex++;
+ }
+
+ headerRow.getRenderer().render(cell,
+ headerRow.getCell(colIndex).getText());
+
+ colIndex++;
+ }
}
@Override
- public String getColumnValue(GridColumn<?, T> column) {
- return column.getHeaderCaption();
+ public void preAttach(Row row, Iterable<FlyweightCell> cellsToAttach) {
}
@Override
- public boolean firstRowIsVisible() {
- return isColumnHeadersVisible();
+ public void postAttach(Row row,
+ Iterable<FlyweightCell> attachedCells) {
}
@Override
- public Renderer<String> getRenderer(GridColumn<?, T> column) {
- return column.getHeaderRenderer();
+ public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
}
@Override
- public Renderer<String> getGroupRenderer(ColumnGroup<T> group) {
- return group.getHeaderRenderer();
+ public void postDetach(Row row,
+ Iterable<FlyweightCell> detachedCells) {
}
};
}
* @return the updater that updates the data in the escalator.
*/
private EscalatorUpdater createFooterUpdater() {
- return new HeaderFooterEscalatorUpdater(escalator.getFooter(), false) {
-
- @Override
- public boolean isRowVisible(ColumnGroupRow<T> row) {
- return row.isFooterVisible();
- }
-
- @Override
- public String getGroupValue(ColumnGroup<T> group) {
- return group.getFooterCaption();
- }
-
- @Override
- public String getColumnValue(GridColumn<?, T> column) {
- return column.getFooterCaption();
- }
-
- @Override
- public boolean firstRowIsVisible() {
- return isColumnFootersVisible();
- }
-
- @Override
- public Renderer<String> getRenderer(GridColumn<?, T> column) {
- return column.getFooterRenderer();
- }
-
- @Override
- public Renderer<String> getGroupRenderer(ColumnGroup<T> group) {
- return group.getFooterRenderer();
- }
- };
+ return EscalatorUpdater.NULL;
}
/**
// Register column with grid
columns.add(index, column);
+ header.addColumn(column, index);
+
// Register this grid instance with the column
((AbstractGridColumn<?, T>) column).setGrid(this);
int columnIndex = columns.indexOf(column);
int visibleIndex = findVisibleColumnIndex(column);
columns.remove(columnIndex);
+ header.removeColumn(columnIndex);
// de-register column with grid
((AbstractGridColumn<?, T>) column).setGrid(null);
* @param visible
* <code>true</code> if header rows should be visible
*/
+ @Deprecated
public void setColumnHeadersVisible(boolean visible) {
if (visible == isColumnHeadersVisible()) {
return;
*
* @return <code>true</code> if they are visible
*/
+ @Deprecated
public boolean isColumnHeadersVisible() {
return columnHeadersVisible;
}
* @param visible
* <code>true</code> if the footer row should be visible
*/
+ @Deprecated
public void setColumnFootersVisible(boolean visible) {
if (visible == isColumnFootersVisible()) {
return;
* @return <code>true</code> if they are visible
*
*/
+ @Deprecated
public boolean isColumnFootersVisible() {
return columnFootersVisible;
}
*
* @return a column group row instance you can use to add column groups
*/
+ @Deprecated
public ColumnGroupRow<T> addColumnGroupRow() {
ColumnGroupRow<T> row = new ColumnGroupRow<T>(this);
columnGroupRows.add(row);
* the index where the column group row should be added
* @return a column group row instance you can use to add column groups
*/
+ @Deprecated
public ColumnGroupRow<T> addColumnGroupRow(int rowIndex) {
ColumnGroupRow<T> row = new ColumnGroupRow<T>(this);
columnGroupRows.add(rowIndex, row);
* @param row
* The row to remove
*/
+ @Deprecated
public void removeColumnGroupRow(ColumnGroupRow<T> row) {
columnGroupRows.remove(row);
refreshHeader();
* @return a unmodifiable list of column group rows
*
*/
+ @Deprecated
public List<ColumnGroupRow<T>> getColumnGroupRows() {
return Collections.unmodifiableList(new ArrayList<ColumnGroupRow<T>>(
columnGroupRows));
* @return A column group for the row and column or <code>null</code> if not
* found.
*/
+ @Deprecated
private ColumnGroup<T> getGroupForColumn(ColumnGroupRow<T> row,
GridColumn<?, T> column) {
for (ColumnGroup<T> group : row.getGroups()) {
--- /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.client.ui.grid;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.client.ui.grid.renderers.TextRenderer;
+
+/**
+ * Represents the header section of a Grid. A header consists of a single header
+ * row containing a header cell for each column. Each cell has a simple textual
+ * caption.
+ *
+ * TODO Arbitrary number of header rows (zero included)
+ *
+ * TODO Merging header cells
+ *
+ * TODO "Default" row with sorting
+ *
+ * TODO Widgets in cells
+ *
+ * TODO HTML in cells
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class GridHeader {
+
+ /**
+ * A single row in a grid header section.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+ public static class HeaderRow {
+
+ private List<HeaderCell> cells = new ArrayList<HeaderCell>();
+
+ private Renderer<String> renderer = new TextRenderer();
+
+ public HeaderCell getCell(int index) {
+ return cells.get(index);
+ }
+
+ protected void addCell(int index) {
+ cells.add(index, new HeaderCell());
+ }
+
+ protected void removeCell(int index) {
+ cells.remove(index);
+ }
+
+ protected Renderer<String> getRenderer() {
+ return renderer;
+ }
+ }
+
+ /**
+ * A single cell in a grid header row. Has a textual caption.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+ public static class HeaderCell {
+
+ private String text = "";
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getText() {
+ return text;
+ }
+ }
+
+ private List<HeaderRow> rows = Arrays.asList(new HeaderRow());
+
+ public HeaderRow getRow(int index) {
+ return rows.get(index);
+ }
+
+ protected void addColumn(GridColumn<?, ?> column, int index) {
+ getRow(0).addCell(index);
+ }
+
+ protected void removeColumn(int index) {
+ getRow(0).removeCell(index);
+ }
+}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
@TestCategory("grid")
public class GridSingleColumnTest extends MultiBrowserTest {
+ /*
+ * TODO unignore once column header captions are reimplemented
+ */
@Test
+ @Ignore
public void headerIsVisible() {
openTestURL();
*/
package com.vaadin.tests.components.grid.basicfeatures;
+import java.util.ArrayList;
+import java.util.List;
+
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
+import com.vaadin.testbench.TestBenchElement;
import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.components.grid.GridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
getGridVerticalScrollbar());
}
+ protected List<TestBenchElement> getGridHeaderRowCells() {
+ List<TestBenchElement> headerCells = new ArrayList<TestBenchElement>();
+ for (int i = 0; i < getGridElement().getHeaderCount(); ++i) {
+ headerCells.addAll(getGridElement().getHeaderCells(i));
+ }
+ return headerCells;
+ }
+
private Object executeScript(String script, WebElement element) {
final WebDriver driver = getDriver();
if (driver instanceof JavascriptExecutor) {
--- /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.util.List;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.TestBenchElement;
+
+public class GridHeaderTest extends GridBasicClientFeaturesTest {
+
+ @Test
+ public void testHeaderVisible() throws Exception {
+ openTestURL();
+
+ // Column headers should be visible
+ List<TestBenchElement> cells = getGridHeaderRowCells();
+ assertEquals(GridBasicFeatures.COLUMNS, cells.size());
+ }
+}
import java.io.IOException;
+import org.junit.Ignore;
import org.junit.Test;
import com.vaadin.tests.components.grid.GridElement;
public class GridSortingTest extends GridBasicFeaturesTest {
+ /*
+ * TODO unignore once column header captions are reimplemented
+ */
@Test
+ @Ignore
public void testProgrammaticSorting() throws IOException {
openTestURL();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
import java.util.List;
+import org.junit.Ignore;
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.GridBasicFeatures;
-import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
public class GridStructureTest extends GridBasicFeaturesTest {
+ /*
+ * TODO unignore once column header captions are reimplemented
+ */
@Test
- public void testColumnHeaderCaptions() throws Exception {
- openTestURL();
-
- // Column headers should be visible
- List<TestBenchElement> cells = getGridHeaderRowCells();
- assertEquals(GridBasicFeatures.COLUMNS, cells.size());
- assertEquals("Column0", cells.get(0).getText());
- assertEquals("Column1", cells.get(1).getText());
- assertEquals("Column2", cells.get(2).getText());
- }
-
- @Test
- public void testColumnFooterCaptions() throws Exception {
- openTestURL();
-
- // footer row should by default be hidden
- List<TestBenchElement> cells = getGridFooterRowCells();
- assertEquals(0, cells.size());
-
- // Open footer row
- selectMenuPath("Component", "Footers", "Visible");
-
- // Footers should now be visible
- cells = getGridFooterRowCells();
- assertEquals(GridBasicFeatures.COLUMNS, cells.size());
- assertEquals("Footer 0", cells.get(0).getText());
- assertEquals("Footer 1", cells.get(1).getText());
- assertEquals("Footer 2", cells.get(2).getText());
- }
-
- @Test
- public void testColumnGroupHeaders() throws Exception {
- openTestURL();
-
- // Hide column headers for this test
- selectMenuPath("Component", "Headers", "Visible");
-
- List<TestBenchElement> cells = getGridHeaderRowCells();
-
- // header row should be empty
- assertEquals(0, cells.size());
-
- // add a group row
- selectMenuPath("Component", "Column groups", "Add group row");
-
- // Empty group row cells should be present
- cells = getGridHeaderRowCells();
- assertEquals(GridBasicFeatures.COLUMNS, cells.size());
-
- // Group columns 0 & 1
- selectMenuPath("Component", "Column groups", "Column group row 1",
- "Group Column 0 & 1");
-
- cells = getGridHeaderRowCells();
- assertEquals("Column 0 & 1", cells.get(0).getText());
- }
-
- @Test
- public void testColumnGroupFooters() throws Exception {
- openTestURL();
-
- // add a group row
- selectMenuPath("Component", "Column groups", "Add group row");
-
- // Set footer visible
- selectMenuPath("Component", "Column groups", "Column group row 1",
- "Footer Visible");
-
- // Group columns 0 & 1
- selectMenuPath("Component", "Column groups", "Column group row 1",
- "Group Column 0 & 1");
-
- List<TestBenchElement> cells = getGridFooterRowCells();
- assertEquals("Column 0 & 1", cells.get(0).getText());
- }
-
- @Test
- public void testGroupingSameColumnsOnRowThrowsException() throws Exception {
- openTestURL();
-
- // add a group row
- selectMenuPath("Component", "Column groups", "Add group row");
-
- // Group columns 0 & 1
- selectMenuPath("Component", "Column groups", "Column group row 1",
- "Group Column 0 & 1");
-
- // Group columns 1 & 2 shoud fail
- selectMenuPath("Component", "Column groups", "Column group row 1",
- "Group Column 1 & 2");
-
- assertTrue(getLogRow(0)
- .contains(
- "Exception occured, java.lang.IllegalArgumentExceptionColumn Column1 already belongs to another group."));
- }
-
- @Test
+ @Ignore
public void testHidingColumn() throws Exception {
openTestURL();
assertEquals("Column1", cells.get(0).getText());
}
+ /*
+ * TODO unignore once column header captions are reimplemented
+ */
@Test
+ @Ignore
public void testRemovingColumn() throws Exception {
openTestURL();
private WebElement getTableWrapper() {
return getGridElement().findElement(By.xpath("./div[3]"));
}
-
- private List<TestBenchElement> getGridHeaderRowCells() {
- List<TestBenchElement> headerCells = new ArrayList<TestBenchElement>();
- for (int i = 0; i < getGridElement().getHeaderCount(); ++i) {
- headerCells.addAll(getGridElement().getHeaderCells(i));
- }
- return headerCells;
- }
-
- private List<TestBenchElement> getGridFooterRowCells() {
- List<TestBenchElement> footerCells = new ArrayList<TestBenchElement>();
- for (int i = 0; i < getGridElement().getFooterCount(); ++i) {
- footerCells.addAll(getGridElement().getFooterCells(i));
- }
- return footerCells;
- }
}