diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-02-04 18:33:30 +0200 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2015-02-05 15:47:46 +0000 |
commit | a15f2847950126bc87751c54d977d2f4edd45c04 (patch) | |
tree | 200d9866abb2c9334ca9c38ef58639954c562d27 /client | |
parent | 50724f2d0d1e225b5c24d097d3c4b8529b7a8f3f (diff) | |
download | vaadin-framework-a15f2847950126bc87751c54d977d2f4edd45c04.tar.gz vaadin-framework-a15f2847950126bc87751c54d977d2f4edd45c04.zip |
Grid columns can now be marked as non-editable (#16538)
Non-editable columns are not assigned editor fields. When the editor is active,
any non-editable content is not displayed (this should changein the future).
This is separate from setting the property or editor field read-only - in those
cases the field is still used to display the data which may not be desired and
will fail if there is no converter.
Also add Column.setEditorField(Field<?>) and the corresponding getter.
Change-Id: Ice17c357895cb63a8e1bfd6abaffc1d803399e98
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/connectors/GridConnector.java | 1 | ||||
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 82 |
2 files changed, 73 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index 827e366de0..8d383ab0ae 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -756,6 +756,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements column.setExpandRatio(state.expandRatio); column.setSortable(state.sortable); + column.setEditable(state.editable); column.setEditorConnector((AbstractFieldConnector) state.editorConnector); } diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index a870a732b5..303b94763d 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -1254,11 +1254,13 @@ public class Grid<T> extends ResizeComposite implements /** * Returns the editor widget associated with the given column. If the - * editor is not active, returns null. + * editor is not active or the column is not + * {@link Grid.Column#isEditable() editable}, returns null. * * @param column * the column - * @return the widget if the editor is open, null otherwise + * @return the widget if the editor is open and the column is editable, + * null otherwise */ protected Widget getWidget(Column<?, T> column) { return columnToWidget.get(column); @@ -1305,14 +1307,12 @@ public class Grid<T> extends ResizeComposite implements editorOverlay.appendChild(cell); Column<?, T> column = grid.getColumn(i); - if (column == grid.selectionColumn) { - continue; - } - - Widget editor = getHandler().getWidget(column); - if (editor != null) { - columnToWidget.put(column, editor); - attachWidget(editor, cell); + if (column.isEditable()) { + Widget editor = getHandler().getWidget(column); + if (editor != null) { + columnToWidget.put(column, editor); + attachWidget(editor, cell); + } } } @@ -1987,6 +1987,7 @@ public class Grid<T> extends ResizeComposite implements } public final class SelectionColumn extends Column<Boolean, T> { + private boolean initDone = false; SelectionColumn(final Renderer<Boolean> selectColumnRenderer) { @@ -2022,6 +2023,8 @@ public class Grid<T> extends ResizeComposite implements setWidth(-1); + setEditable(false); + initDone = true; } @@ -2074,6 +2077,17 @@ public class Grid<T> extends ResizeComposite implements public double getMinimumWidth() { return -1; } + + @Override + public Column<Boolean, T> setEditable(boolean editable) { + if (initDone) { + throw new UnsupportedOperationException( + "can't set the selection column editable"); + } + super.setEditable(editable); + return this; + } + } /** @@ -2738,6 +2752,8 @@ public class Grid<T> extends ResizeComposite implements private boolean sortable = false; + private boolean editable = true; + private String headerCaption = ""; private double minimumWidthPx = GridConstants.DEFAULT_MIN_WIDTH; @@ -3159,6 +3175,43 @@ public class Grid<T> extends ResizeComposite implements return expandRatio; } + /** + * Sets whether the values in this column should be editable by the user + * when the row editor is active. By default columns are editable. + * + * @param editable + * {@code true} to set this column editable, {@code false} + * otherwise + * @return this column + * + * @throws IllegalStateException + * if the editor is currently active + * + * @see Grid#editRow(int) + * @see Grid#isEditorActive() + */ + public Column<C, T> setEditable(boolean editable) { + if (editable != this.editable && grid.isEditorActive()) { + throw new IllegalStateException( + "Cannot change column editable status while the editor is active"); + } + this.editable = editable; + return this; + } + + /** + * Returns whether the values in this column are editable by the user + * when the row editor is active. + * + * @return {@code true} if this column is editable, {@code false} + * otherwise + * + * @see #setEditable(boolean) + */ + public boolean isEditable() { + return editable; + } + private void scheduleColumnWidthRecalculator() { if (grid != null) { grid.autoColumnWidthsRecalculator.schedule(); @@ -5782,6 +5835,15 @@ public class Grid<T> extends ResizeComposite implements } /** + * Returns whether the editor is currently open on some row. + * + * @return {@code true} if the editor is active, {@code false} otherwise. + */ + public boolean isEditorActive() { + return editor.getState() != State.INACTIVE; + } + + /** * Saves any unsaved changes in the editor to the data source. * * @throws IllegalStateException |