diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-04 15:16:58 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-05 10:34:45 +0000 |
commit | b5b4df245f9173ec87991d678b9d13734d7637a3 (patch) | |
tree | ed81e8574f3a5b44cb082107dc2295bacc2be6f5 | |
parent | c080a93f842b711161df466f3780b52b44300e08 (diff) | |
download | vaadin-framework-b5b4df245f9173ec87991d678b9d13734d7637a3.tar.gz vaadin-framework-b5b4df245f9173ec87991d678b9d13734d7637a3.zip |
Remove Column visibility setting from client side (#13334)
Change-Id: I30abbd5d1c10c6532c9289aeb375ad5edb0fe818
7 files changed, 27 insertions, 267 deletions
diff --git a/client/src/com/vaadin/client/ui/grid/EditorRow.java b/client/src/com/vaadin/client/ui/grid/EditorRow.java index e7585b78a3..cc56a4c4a9 100644 --- a/client/src/com/vaadin/client/ui/grid/EditorRow.java +++ b/client/src/com/vaadin/client/ui/grid/EditorRow.java @@ -280,7 +280,7 @@ public class EditorRow<T> { /** * Returns the editor widget associated with the given column. If the editor * row is not active, returns null. - * + * * @param column * the column * @return the widget if the editor row is open, null otherwise @@ -326,7 +326,7 @@ public class EditorRow<T> { editorOverlay.appendChild(cell); - GridColumn<?, T> column = grid.getColumnFromVisibleIndex(i); + GridColumn<?, T> column = grid.getColumn(i); if (column instanceof SelectionColumn) { continue; } diff --git a/client/src/com/vaadin/client/ui/grid/Grid.java b/client/src/com/vaadin/client/ui/grid/Grid.java index 0844be563a..a7e74bb216 100644 --- a/client/src/com/vaadin/client/ui/grid/Grid.java +++ b/client/src/com/vaadin/client/ui/grid/Grid.java @@ -41,7 +41,6 @@ import com.google.gwt.touch.client.Point; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.ui.HasVisibility; import com.google.gwt.user.client.ui.ResizeComposite; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.DeferredWorker; @@ -444,7 +443,7 @@ public class Grid<T> extends ResizeComposite implements --newRow; break; case KeyCodes.KEY_RIGHT: - if (cellFocusRange.getEnd() >= getVisibleColumns().size()) { + if (cellFocusRange.getEnd() >= getColumns().size()) { return; } newColumn = cellFocusRange.getEnd(); @@ -627,16 +626,6 @@ public class Grid<T> extends ResizeComposite implements } @Override - public void setVisible(boolean visible) { - if (!visible && initDone) { - throw new UnsupportedOperationException("The selection " - + "column cannot be modified after init"); - } else { - super.setVisible(visible); - } - } - - @Override public void setWidth(int pixels) { if (pixels != getWidth() && initDone) { throw new UnsupportedOperationException("The selection " @@ -688,8 +677,7 @@ public class Grid<T> extends ResizeComposite implements */ public void sort(Cell cell, boolean multisort) { - final GridColumn<?, T> column = getColumnFromVisibleIndex(cell - .getColumn()); + final GridColumn<?, T> column = getColumn(cell.getColumn()); if (!column.isSortable()) { return; } @@ -889,7 +877,7 @@ public class Grid<T> extends ResizeComposite implements * @param <T> * the row type */ - static abstract class AbstractGridColumn<C, T> implements HasVisibility { + static abstract class AbstractGridColumn<C, T> { /** * Default renderer for GridColumns. Renders everything into text @@ -918,11 +906,6 @@ public class Grid<T> extends ResizeComposite implements private Grid<T> grid; /** - * Should the column be visible in the grid - */ - private boolean visible = true; - - /** * Width of column in pixels */ private int width = 100; @@ -1039,68 +1022,6 @@ public class Grid<T> extends ResizeComposite implements } /** - * Is the column visible. By default all columns are visible. - * - * @return <code>true</code> if the column is visible - */ - @Override - public boolean isVisible() { - return visible; - } - - /** - * Sets a column as visible in the grid. - * - * @param visible - * <code>true</code> if the column should be displayed in the - * grid - */ - @Override - public void setVisible(boolean visible) { - if (this.visible == visible) { - return; - } - - /* - * We need to guarantee that both insertColumns and removeColumns - * have this particular column accessible. Therefore, if we're - * turning the column visible, it's set before the other logic. - * Analogously, if we're turning the column invisible, we do that - * only after the logic has been performed. - */ - - if (visible) { - this.visible = true; - } - - if (grid != null) { - int index = findIndexOfColumn(); - ColumnConfiguration conf = grid.escalator - .getColumnConfiguration(); - - if (visible) { - conf.insertColumns(index, 1); - } else { - conf.removeColumns(index, 1); - } - } - - if (!visible) { - this.visible = false; - } - - if (grid != null) { - for (HeaderRow row : grid.getHeader().getRows()) { - row.calculateColspans(); - } - - for (FooterRow row : grid.getFooter().getRows()) { - row.calculateColspans(); - } - } - } - - /** * Returns the data that should be rendered into the cell. By default * returning Strings and Widgets are supported. If the return type is a * String then it will be treated as preformatted text. @@ -1148,14 +1069,6 @@ public class Grid<T> extends ResizeComposite implements } /** - * Finds the index of this column instance - * - */ - private int findIndexOfColumn() { - return grid.findVisibleColumnIndex((GridColumn<?, T>) this); - } - - /** * Sets the pixel width of the column. Use a negative value for the grid * to autosize column based on content and available space * @@ -1165,8 +1078,8 @@ public class Grid<T> extends ResizeComposite implements public void setWidth(int pixels) { width = pixels; - if (grid != null && isVisible()) { - int index = findIndexOfColumn(); + if (grid != null) { + int index = grid.indexOfColumn((GridColumn<?, T>) this); ColumnConfiguration conf = grid.escalator .getColumnConfiguration(); conf.setColumnWidth(index, pixels); @@ -1234,7 +1147,6 @@ public class Grid<T> extends ResizeComposite implements details += "detached "; } - details += "visible:" + visible + " "; details += "sortable:" + sortable + " "; return getClass().getSimpleName() + "[" + details.trim() + "]"; @@ -1323,8 +1235,7 @@ public class Grid<T> extends ResizeComposite implements cellFocusHandler.updateFocusedRowStyle(row); for (FlyweightCell cell : cellsToUpdate) { - GridColumn<?, T> column = getColumnFromVisibleIndex(cell - .getColumn()); + GridColumn<?, T> column = getColumn(cell.getColumn()); assert column != null : "Column was not found from cell (" + cell.getColumn() + "," + cell.getRow() + ")"; @@ -1422,7 +1333,7 @@ public class Grid<T> extends ResizeComposite implements public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) { GridStaticSection.StaticRow<?> staticRow = section.getRow(row .getRow()); - final List<GridColumn<?, T>> columns = getVisibleColumns(); + final List<GridColumn<?, T>> columns = getColumns(); setCustomStyleName(row.getElement(), staticRow.getStyleName()); @@ -1463,8 +1374,7 @@ public class Grid<T> extends ResizeComposite implements cleanup(cell); - GridColumn<?, ?> column = getColumnFromVisibleIndex(cell - .getColumn()); + GridColumn<?, ?> column = getColumn(cell.getColumn()); SortOrder sortingOrder = getSortOrder(column); if (!headerRow.isDefault() || !column.isSortable() || sortingOrder == null) { @@ -1517,7 +1427,7 @@ public class Grid<T> extends ResizeComposite implements public void postAttach(Row row, Iterable<FlyweightCell> attachedCells) { GridStaticSection.StaticRow<?> gridRow = section.getRow(row .getRow()); - List<GridColumn<?, T>> columns = getVisibleColumns(); + List<GridColumn<?, T>> columns = getColumns(); for (FlyweightCell cell : attachedCells) { StaticCell metadata = gridRow.getCell(columns.get(cell @@ -1547,7 +1457,7 @@ public class Grid<T> extends ResizeComposite implements if (section.getRowCount() > row.getRow()) { GridStaticSection.StaticRow<?> gridRow = section.getRow(row .getRow()); - List<GridColumn<?, T>> columns = getVisibleColumns(); + List<GridColumn<?, T>> columns = getColumns(); for (FlyweightCell cell : cellsToDetach) { StaticCell metadata = gridRow.getCell(columns.get(cell .getColumn())); @@ -1826,21 +1736,13 @@ public class Grid<T> extends ResizeComposite implements // Register this grid instance with the column ((AbstractGridColumn<?, T>) column).setGrid(this); - // Insert column into escalator - if (column.isVisible()) { - int visibleIndex = findVisibleColumnIndex(column); - ColumnConfiguration conf = escalator.getColumnConfiguration(); + // Add to escalator + escalator.getColumnConfiguration().insertColumns(index, 1); - // Insert column - conf.insertColumns(visibleIndex, 1); + // Reapply column width + column.reapplyWidth(); - // Transfer column width from column object to escalator - conf.setColumnWidth(visibleIndex, column.getWidth()); - } - - if (lastFrozenColumn != null - && ((AbstractGridColumn<?, T>) lastFrozenColumn) - .findIndexOfColumn() < index) { + if (lastFrozenColumn != null && indexOfColumn(lastFrozenColumn) < index) { refreshFrozenColumns(); } @@ -1870,33 +1772,8 @@ public class Grid<T> extends ResizeComposite implements } } - protected int findVisibleColumnIndex(GridColumn<?, T> column) { - int idx = 0; - for (GridColumn<?, T> c : columns) { - if (c == column) { - return idx; - } else if (c.isVisible()) { - idx++; - } - } - return -1; - } - - protected GridColumn<?, T> getColumnFromVisibleIndex(int index) { - int idx = -1; - for (GridColumn<?, T> c : columns) { - if (c.isVisible()) { - idx++; - } - if (index == idx) { - return c; - } - } - return null; - } - private Renderer<?> findRenderer(FlyweightCell cell) { - GridColumn<?, T> column = getColumnFromVisibleIndex(cell.getColumn()); + GridColumn<?, T> column = getColumn(cell.getColumn()); assert column != null : "Could not find column at index:" + cell.getColumn(); return column.getRenderer(); @@ -1919,12 +1796,9 @@ public class Grid<T> extends ResizeComposite implements private void removeColumnSkipSelectionColumnCheck(GridColumn<?, T> column) { int columnIndex = columns.indexOf(column); - int visibleIndex = findVisibleColumnIndex(column); - if (column.isVisible()) { - ColumnConfiguration conf = escalator.getColumnConfiguration(); - conf.removeColumns(visibleIndex, 1); - } + // Remove from column configuration + escalator.getColumnConfiguration().removeColumns(columnIndex, 1); if (column.equals(lastFrozenColumn)) { setLastFrozenColumn(null); @@ -1978,18 +1852,14 @@ public class Grid<T> extends ResizeComposite implements } /** - * Returns a list of columns that are currently visible. + * Returns current index of given column * - * @return a list of columns + * @param column + * column in grid + * @return column index, or <code>-1</code> if not in this Grid */ - protected List<GridColumn<?, T>> getVisibleColumns() { - List<GridColumn<?, T>> visible = new ArrayList<GridColumn<?, T>>(); - for (GridColumn<?, T> column : getColumns()) { - if (column.isVisible()) { - visible.add(column); - } - } - return visible; + protected int indexOfColumn(GridColumn<?, T> column) { + return columns.indexOf(column); } /** @@ -2505,8 +2375,7 @@ public class Grid<T> extends ResizeComposite implements Cell cell) { if (container == escalator.getBody() && cell != null) { - GridColumn<?, T> gridColumn = getColumnFromVisibleIndex(cell - .getColumn()); + GridColumn<?, T> gridColumn = getColumn(cell.getColumn()); boolean enterKey = event.getType().equals(BrowserEvents.KEYDOWN) && event.getKeyCode() == KeyCodes.KEY_ENTER; boolean doubleClick = event.getType() diff --git a/client/src/com/vaadin/client/ui/grid/GridConnector.java b/client/src/com/vaadin/client/ui/grid/GridConnector.java index 671fd259d6..ba674c829e 100644 --- a/client/src/com/vaadin/client/ui/grid/GridConnector.java +++ b/client/src/com/vaadin/client/ui/grid/GridConnector.java @@ -621,7 +621,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements */ private static void updateColumnFromState(CustomGridColumn column, GridColumnState state) { - column.setVisible(state.visible); column.setWidth(state.width); column.setSortable(state.sortable); column.setEditorConnector((AbstractFieldConnector) state.editorConnector); diff --git a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java index c26287f095..228ff73894 100644 --- a/client/src/com/vaadin/client/ui/grid/GridStaticSection.java +++ b/client/src/com/vaadin/client/ui/grid/GridStaticSection.java @@ -334,11 +334,6 @@ abstract class GridStaticSection<ROWTYPE extends GridStaticSection.StaticRow<?>> cellGroups.get(group).setColspan(1); } else { int colSpan = group.size(); - for (GridColumn<?, ?> column : group) { - if (!column.isVisible()) { - --colSpan; - } - } cellGroups.get(group).setColspan(colSpan); } } diff --git a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java index 89e7791dbb..b1b562d715 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java @@ -35,11 +35,6 @@ public class GridColumnState implements Serializable { public String id; /** - * Has the column been hidden. By default the column is visible. - */ - public boolean visible = true; - - /** * Column width in pixels. Default column width is 100px. */ public int width = 100; diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java index 4508bd6b1d..f58239eb3d 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java @@ -21,7 +21,6 @@ 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; @@ -66,31 +65,6 @@ public class GridHeaderTest extends GridStaticSectionTest { } @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(); @@ -219,72 +193,6 @@ public class GridHeaderTest extends GridStaticSectionTest { } @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(); diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java index 5fca34ba42..8a4bbeed09 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java @@ -579,12 +579,6 @@ public class GridBasicClientFeaturesWidget extends for (int i = 0; i < COLUMNS; i++) { final int index = i; final GridColumn<?, List<Data>> column = grid.getColumn(index); - addMenuCommand("Visible", new ScheduledCommand() { - @Override - public void execute() { - column.setVisible(!column.isVisible()); - } - }, "Component", "Columns", "Column " + i); addMenuCommand("Sortable", new ScheduledCommand() { @Override public void execute() { |