From 6ed909f2c61f7d434d1c91549dcda27cfa3698a8 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Mon, 15 Dec 2014 16:31:26 +0200 Subject: Change "editor row" to just "editor" in method names and javadoc (#13334) Change-Id: Idafdbe3d71a38a979e1eeb07c527f66ce61ccfa9 --- .../vaadin/client/connectors/GridConnector.java | 40 ++-- .../vaadin/client/widget/grid/EditorHandler.java | 171 +++++++++++++++++ .../client/widget/grid/EditorRowHandler.java | 171 ----------------- client/src/com/vaadin/client/widgets/Grid.java | 174 ++++++++--------- server/src/com/vaadin/ui/Grid.java | 162 ++++++++-------- .../server/component/grid/EditorRowTests.java | 209 --------------------- .../server/component/grid/GridEditorTest.java | 209 +++++++++++++++++++++ .../com/vaadin/shared/ui/grid/EditorClientRpc.java | 55 ++++++ .../vaadin/shared/ui/grid/EditorRowClientRpc.java | 55 ------ .../vaadin/shared/ui/grid/EditorRowServerRpc.java | 58 ------ .../com/vaadin/shared/ui/grid/EditorServerRpc.java | 58 ++++++ .../com/vaadin/shared/ui/grid/GridColumnState.java | 2 +- .../src/com/vaadin/shared/ui/grid/GridState.java | 4 +- .../vaadin/tests/components/grid/EditorRowUI.java | 49 ----- .../tests/components/grid/EditorRowUITest.java | 63 ------- .../vaadin/tests/components/grid/GridEditorUI.java | 49 +++++ .../tests/components/grid/GridEditorUITest.java | 63 +++++++ .../grid/basicfeatures/GridBasicFeatures.java | 42 ++--- .../grid/basicfeatures/GridBasicFeaturesTest.java | 4 +- .../client/GridClientCompositeEditorRowTest.java | 13 -- .../client/GridClientCompositeEditorTest.java | 13 ++ .../basicfeatures/client/GridEditorClientTest.java | 155 +++++++++++++++ .../client/GridEditorRowClientTest.java | 155 --------------- .../basicfeatures/server/GridEditorRowTest.java | 168 ----------------- .../grid/basicfeatures/server/GridEditorTest.java | 168 +++++++++++++++++ .../client/grid/GridBasicClientFeaturesWidget.java | 34 ++-- 26 files changed, 1175 insertions(+), 1169 deletions(-) create mode 100644 client/src/com/vaadin/client/widget/grid/EditorHandler.java delete mode 100644 client/src/com/vaadin/client/widget/grid/EditorRowHandler.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/grid/EditorRowTests.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java create mode 100644 shared/src/com/vaadin/shared/ui/grid/EditorClientRpc.java delete mode 100644 shared/src/com/vaadin/shared/ui/grid/EditorRowClientRpc.java delete mode 100644 shared/src/com/vaadin/shared/ui/grid/EditorRowServerRpc.java create mode 100644 shared/src/com/vaadin/shared/ui/grid/EditorServerRpc.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/EditorRowUI.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/EditorRowUITest.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridEditorUITest.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorRowTest.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorRowClientTest.java delete mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorRowTest.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index 061a6ac61e..ec25b57c45 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -44,7 +44,7 @@ import com.vaadin.client.ui.AbstractHasComponentsConnector; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.CellStyleGenerator; -import com.vaadin.client.widget.grid.EditorRowHandler; +import com.vaadin.client.widget.grid.EditorHandler; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; import com.vaadin.client.widget.grid.events.SelectAllEvent; @@ -65,10 +65,10 @@ import com.vaadin.client.widgets.Grid.HeaderCell; import com.vaadin.client.widgets.Grid.HeaderRow; import com.vaadin.shared.data.sort.SortDirection; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.grid.EditorRowClientRpc; -import com.vaadin.shared.ui.grid.EditorRowServerRpc; import com.vaadin.shared.ui.grid.GridClientRpc; import com.vaadin.shared.ui.grid.GridColumnState; +import com.vaadin.shared.ui.grid.EditorClientRpc; +import com.vaadin.shared.ui.grid.EditorServerRpc; import com.vaadin.shared.ui.grid.GridServerRpc; import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.GridState.SharedSelectionMode; @@ -189,18 +189,17 @@ public class GridConnector extends AbstractHasComponentsConnector implements } /* - * An editor row handler using Vaadin RPC to manage the editor row state. + * An editor handler using Vaadin RPC to manage the editor state. */ - private class CustomEditorRowHandler implements - EditorRowHandler { + private class CustomEditorHandler implements EditorHandler { - private EditorRowServerRpc rpc = getRpcProxy(EditorRowServerRpc.class); + private EditorServerRpc rpc = getRpcProxy(EditorServerRpc.class); - private EditorRowRequest currentRequest = null; + private EditorRequest currentRequest = null; private boolean serverInitiated = false; - public CustomEditorRowHandler() { - registerRpc(EditorRowClientRpc.class, new EditorRowClientRpc() { + public CustomEditorHandler() { + registerRpc(EditorClientRpc.class, new EditorClientRpc() { @Override public void bind(final int rowIndex) { @@ -222,7 +221,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements @Override public void cancel(int rowIndex) { serverInitiated = true; - GridConnector.this.getWidget().cancelEditorRow(); + GridConnector.this.getWidget().cancelEditor(); } @Override @@ -246,7 +245,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements } @Override - public void bind(EditorRowRequest request) { + public void bind(EditorRequest request) { if (!handleServerInitiated(request)) { startRequest(request); rpc.bind(request.getRowIndex()); @@ -254,7 +253,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements } @Override - public void save(EditorRowRequest request) { + public void save(EditorRequest request) { if (!handleServerInitiated(request)) { startRequest(request); rpc.save(request.getRowIndex()); @@ -262,7 +261,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements } @Override - public void cancel(EditorRowRequest request) { + public void cancel(EditorRequest request) { if (!handleServerInitiated(request)) { // No startRequest as we don't get (or need) // a confirmation from the server @@ -285,7 +284,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements } /** - * Used to handle the case where EditorRow calls us because it was + * Used to handle the case where the editor calls us because it was * invoked by the server via RPC and not by the client. In that case, we * simply synchronously complete the request. * @@ -294,7 +293,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements * @return true if the request was originally triggered by the server, * false otherwise */ - private boolean handleServerInitiated(EditorRowRequest request) { + private boolean handleServerInitiated(EditorRequest request) { assert request != null; assert currentRequest == null; @@ -307,7 +306,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements } } - private void startRequest(EditorRowRequest request) { + private void startRequest(EditorRequest request) { currentRequest = request; } @@ -430,7 +429,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements }); - getWidget().setEditorRowHandler(new CustomEditorRowHandler()); + getWidget().setEditorHandler(new CustomEditorHandler()); getLayoutManager().registerDependency(this, getWidget().getElement()); layout(); } @@ -483,9 +482,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements updateFooterFromState(getState().footer); } - if (stateChangeEvent.hasPropertyChanged("editorRowEnabled")) { - getWidget() - .setEditorRowEnabled(getState().editorRowEnabled); + if (stateChangeEvent.hasPropertyChanged("editorEnabled")) { + getWidget().setEditorEnabled(getState().editorEnabled); } if (stateChangeEvent.hasPropertyChanged("frozenColumnCount")) { diff --git a/client/src/com/vaadin/client/widget/grid/EditorHandler.java b/client/src/com/vaadin/client/widget/grid/EditorHandler.java new file mode 100644 index 0000000000..2b609f5de3 --- /dev/null +++ b/client/src/com/vaadin/client/widget/grid/EditorHandler.java @@ -0,0 +1,171 @@ +/* + * 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.widget.grid; + +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.widgets.Grid; + +/** + * An interface for binding widgets and data to the grid row editor. Used by the + * editor to support different row types, data sources and custom data binding + * mechanisms. + * + * @param + * the row data type + * + * @since + * @author Vaadin Ltd + */ +public interface EditorHandler { + + /** + * A request class for handling asynchronous data binding. The request is + * callback-based to facilitate usage with remote or otherwise asynchronous + * data sources. + *

+ * TODO Should have a mechanism for signaling a failed request to the caller + */ + public static class EditorRequest { + + /** + * A callback interface used to notify the caller about completed + * requests. + */ + public interface RequestCallback { + public void onResponse(EditorRequest request); + } + + private Grid grid; + private int rowIndex; + private RequestCallback callback; + + /** + * Creates a new editor request. + * + * @param rowIndex + * the index of the edited row + * @param callback + * the callback invoked when the request is ready, or null if + * no need to call back + */ + public EditorRequest(Grid grid, int rowIndex, + RequestCallback callback) { + this.grid = grid; + this.rowIndex = rowIndex; + this.callback = callback; + } + + /** + * Returns the index of the row being requested. + * + * @return the row index + */ + public int getRowIndex() { + return rowIndex; + } + + /** + * Returns the row data related to the row being requested. + * + * @return the row data + */ + public T getRow() { + return grid.getDataSource().getRow(rowIndex); + } + + /** + * Returns the grid instance related to this editor request. + * + * @return the grid instance + */ + public Grid getGrid() { + return grid; + } + + /** + * Returns the editor widget used to edit the values of the given + * column. + * + * @param column + * the column whose widget to get + * @return the widget related to the column + */ + public Widget getWidget(Grid.Column column) { + Widget w = grid.getEditorWidget(column); + assert w != null; + return w; + } + + /** + * Invokes the stored callback if it is not null. + */ + public void invokeCallback() { + if (callback != null) { + callback.onResponse(this); + } + } + } + + /** + * Binds row data to the editor widgets. Called by the editor when it is + * opened for editing. + *

+ * An implementation must call {@link EditorRequest#invokeCallback() + * request.invokeCallback()} when the binding is complete (possibly + * asynchronously). + * + * @param request + * the data binding request + * + * @see Grid#editRow(int) + */ + public void bind(EditorRequest request); + + /** + * Cancels a currently active edit if any. Called by the grid editor when + * editing is cancelled. + *

+ * An implementation must call {@link EditorRequest#invokeCallback() + * request.invokeCallback()} when the cancel is done (possibly + * asynchronously). + * + * @param request + * the cancel request + * + * @see Grid#cancelEditor() + */ + public void cancel(EditorRequest request); + + /** + * Saves changes in the currently active edit to the data source. Called by + * the grid editor when changes are saved. + * + * @param request + * the save request + */ + public void save(EditorRequest request); + + /** + * Returns a widget instance that is used to edit the values in the given + * column. A null return value means the column is not editable. + * + * @param column + * the column whose values should be edited + * @return the editor widget for the column or null if the column is not + * editable + */ + public Widget getWidget(Grid.Column column); +} diff --git a/client/src/com/vaadin/client/widget/grid/EditorRowHandler.java b/client/src/com/vaadin/client/widget/grid/EditorRowHandler.java deleted file mode 100644 index 14b494a3ae..0000000000 --- a/client/src/com/vaadin/client/widget/grid/EditorRowHandler.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.widget.grid; - -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.widgets.Grid; - -/** - * An interface for binding widgets and data to the editor row. Used by the - * editor row to support different row types, data sources and custom data - * binding mechanisms. - * - * @param - * the row data type - * - * @since - * @author Vaadin Ltd - */ -public interface EditorRowHandler { - - /** - * A request class for handling asynchronous data binding. The request is - * callback-based to facilitate usage with remote or otherwise asynchronous - * data sources. - *

- * TODO Should have a mechanism for signaling a failed request to the caller - */ - public static class EditorRowRequest { - - /** - * A callback interface used to notify the caller about completed - * requests. - */ - public interface RequestCallback { - public void onResponse(EditorRowRequest request); - } - - private Grid grid; - private int rowIndex; - private RequestCallback callback; - - /** - * Creates a new editor row request. - * - * @param rowIndex - * the index of the edited row - * @param callback - * the callback invoked when the request is ready, or null if - * no need to call back - */ - public EditorRowRequest(Grid grid, int rowIndex, - RequestCallback callback) { - this.grid = grid; - this.rowIndex = rowIndex; - this.callback = callback; - } - - /** - * Returns the index of the row being requested. - * - * @return the row index - */ - public int getRowIndex() { - return rowIndex; - } - - /** - * Returns the row data related to the row being requested. - * - * @return the row data - */ - public T getRow() { - return grid.getDataSource().getRow(rowIndex); - } - - /** - * Returns the grid instance related to this editor row request. - * - * @return the grid instance - */ - public Grid getGrid() { - return grid; - } - - /** - * Returns the editor row widget used to edit the values of the given - * column. - * - * @param column - * the column whose widget to get - * @return the widget related to the column - */ - public Widget getWidget(Grid.Column column) { - Widget w = grid.getEditorRowWidget(column); - assert w != null; - return w; - } - - /** - * Invokes the stored callback if it is not null. - */ - public void invokeCallback() { - if (callback != null) { - callback.onResponse(this); - } - } - } - - /** - * Binds row data to the editor row widgets. Called by the editor row when - * it is opened for editing. - *

- * An implementation must call {@link EditorRowRequest#invokeCallback() - * request.invokeCallback()} when the binding is complete (possibly - * asynchronously). - * - * @param request - * the data binding request - * - * @see Grid#editRow(int) - */ - public void bind(EditorRowRequest request); - - /** - * Cancels a currently active edit if any. Called by the editor row when - * editing is cancelled. - *

- * An implementation must call {@link EditorRowRequest#invokeCallback() - * request.invokeCallback()} when the cancel is done (possibly - * asynchronously). - * - * @param request - * the cancel request - * - * @see Grid#cancelEditorRow() - */ - public void cancel(EditorRowRequest request); - - /** - * Saves changes in the currently active edit to the data source. Called by - * the editor row when changes are saved. - * - * @param request - * the save request - */ - public void save(EditorRowRequest request); - - /** - * Returns a widget instance that is used to edit the values in the given - * column. A null return value means the column is not editable. - * - * @param column - * the column whose values should be edited - * @return the editor widget for the column or null if the column is not - * editable - */ - public Widget getWidget(Grid.Column column); -} diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 42da0ca90d..1708beba30 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -78,9 +78,9 @@ import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.CellStyleGenerator; import com.vaadin.client.widget.grid.DataAvailableEvent; import com.vaadin.client.widget.grid.DataAvailableHandler; -import com.vaadin.client.widget.grid.EditorRowHandler; -import com.vaadin.client.widget.grid.EditorRowHandler.EditorRowRequest; -import com.vaadin.client.widget.grid.EditorRowHandler.EditorRowRequest.RequestCallback; +import com.vaadin.client.widget.grid.EditorHandler; +import com.vaadin.client.widget.grid.EditorHandler.EditorRequest; +import com.vaadin.client.widget.grid.EditorHandler.EditorRequest.RequestCallback; import com.vaadin.client.widget.grid.GridUtil; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; @@ -931,7 +931,7 @@ public class Grid extends ResizeComposite implements * An editor UI for Grid rows. A single Grid row at a time can be opened for * editing. */ - protected static class EditorRow { + protected static class Editor { public static final int KEYCODE_SHOW = KeyCodes.KEY_ENTER; public static final int KEYCODE_HIDE = KeyCodes.KEY_ESCAPE; @@ -941,7 +941,7 @@ public class Grid extends ResizeComposite implements } private Grid grid; - private EditorRowHandler handler; + private EditorHandler handler; private DivElement editorOverlay = DivElement.as(DOM.createDiv()); @@ -965,18 +965,18 @@ public class Grid extends ResizeComposite implements * the index of the row to be edited * * @throws IllegalStateException - * if this editor row is not enabled + * if this editor is not enabled * @throws IllegalStateException - * if this editor row is already in edit mode + * if this editor is already in edit mode */ public void editRow(int rowIndex) { if (!enabled) { throw new IllegalStateException( - "Cannot edit row: EditorRow is not enabled"); + "Cannot edit row: editor is not enabled"); } if (state != State.INACTIVE) { throw new IllegalStateException( - "Cannot edit row: EditorRow already in edit mode"); + "Cannot edit row: editor already in edit mode"); } this.rowIndex = rowIndex; @@ -995,22 +995,22 @@ public class Grid extends ResizeComposite implements * that are not {@link #save() saved} are lost. * * @throws IllegalStateException - * if this editor row is not enabled + * if this editor is not enabled * @throws IllegalStateException - * if this editor row is not in edit mode + * if this editor is not in edit mode */ public void cancel() { if (!enabled) { throw new IllegalStateException( - "Cannot cancel edit: EditorRow is not enabled"); + "Cannot cancel edit: editor is not enabled"); } if (state == State.INACTIVE) { throw new IllegalStateException( - "Cannot cancel edit: EditorRow is not in edit mode"); + "Cannot cancel edit: editor is not in edit mode"); } hideOverlay(); grid.getEscalator().setScrollLocked(Direction.VERTICAL, false); - handler.cancel(new EditorRowRequest(grid, rowIndex, null)); + handler.cancel(new EditorRequest(grid, rowIndex, null)); state = State.INACTIVE; } @@ -1018,26 +1018,26 @@ public class Grid extends ResizeComposite implements * Saves any unsaved changes to the data source. * * @throws IllegalStateException - * if this editor row is not enabled + * if this editor is not enabled * @throws IllegalStateException - * if this editor row is not in edit mode + * if this editor is not in edit mode */ public void save() { if (!enabled) { throw new IllegalStateException( - "Cannot save: EditorRow is not enabled"); + "Cannot save: editor is not enabled"); } if (state != State.ACTIVE) { throw new IllegalStateException( - "Cannot save: EditorRow is not in edit mode"); + "Cannot save: editor is not in edit mode"); } state = State.SAVING; - handler.save(new EditorRowRequest(grid, rowIndex, + handler.save(new EditorRequest(grid, rowIndex, new RequestCallback() { @Override - public void onResponse(EditorRowRequest request) { + public void onResponse(EditorRequest request) { if (state == State.SAVING) { state = State.ACTIVE; } @@ -1047,28 +1047,28 @@ public class Grid extends ResizeComposite implements /** * Returns the handler responsible for binding data and editor widgets - * to this editor row. + * to this editor. * - * @return the editor row handler or null if not set + * @return the editor handler or null if not set */ - public EditorRowHandler getHandler() { + public EditorHandler getHandler() { return handler; } /** * Sets the handler responsible for binding data and editor widgets to - * this editor row. + * this editor. * * @param rowHandler - * the new editor row handler + * the new editor handler * * @throws IllegalStateException - * if this editor row is currently in edit mode + * if this editor is currently in edit mode */ - public void setHandler(EditorRowHandler rowHandler) { + public void setHandler(EditorHandler rowHandler) { if (state != State.INACTIVE) { throw new IllegalStateException( - "Cannot set EditorRowHandler: EditorRow is currently in edit mode"); + "Cannot set EditorHandler: editor is currently in edit mode"); } handler = rowHandler; } @@ -1078,7 +1078,7 @@ public class Grid extends ResizeComposite implements } /** - * Sets the enabled state of this editor row. + * Sets the enabled state of this editor. * * @param enabled * true if enabled, false otherwise @@ -1086,25 +1086,25 @@ public class Grid extends ResizeComposite implements * @throws IllegalStateException * if in edit mode and trying to disable * @throws IllegalStateException - * if the editor row handler is not set + * if the editor handler is not set */ public void setEnabled(boolean enabled) { if (enabled == false && state != State.INACTIVE) { throw new IllegalStateException( - "Cannot disable: EditorRow is in edit mode"); + "Cannot disable: editor is in edit mode"); } else if (enabled == true && getHandler() == null) { throw new IllegalStateException( - "Cannot enable: EditorRowHandler not set"); + "Cannot enable: EditorHandler not set"); } this.enabled = enabled; } protected void show() { if (state == State.ACTIVATING) { - handler.bind(new EditorRowRequest(grid, rowIndex, + handler.bind(new EditorRequest(grid, rowIndex, new RequestCallback() { @Override - public void onResponse(EditorRowRequest request) { + public void onResponse(EditorRequest request) { if (state == State.ACTIVATING) { state = State.ACTIVE; showOverlay(grid @@ -1121,7 +1121,7 @@ public class Grid extends ResizeComposite implements protected void setGrid(final Grid grid) { assert grid != null : "Grid cannot be null"; - assert this.grid == null : "Can only attach EditorRow to Grid once"; + assert this.grid == null : "Can only attach editor to Grid once"; this.grid = grid; @@ -1145,11 +1145,11 @@ public class Grid extends ResizeComposite implements /** * Returns the editor widget associated with the given column. If the - * editor row is not active, returns null. + * editor is not active, returns null. * * @param column * the column - * @return the widget if the editor row is open, null otherwise + * @return the widget if the editor is open, null otherwise */ protected Widget getWidget(Column column) { return columnToWidget.get(column); @@ -1252,13 +1252,13 @@ public class Grid extends ResizeComposite implements } /** - * Creates an editor row cell corresponding to the given table cell. The + * Creates an editor cell corresponding to the given table cell. The * returned element is empty and has the same dimensions and position as * the table cell. * * @param td * the table cell used as a reference - * @return an editor row cell corresponding to the given cell + * @return an editor cell corresponding to the given cell */ protected Element createCell(TableCellElement td) { DivElement cell = DivElement.as(DOM.createDiv()); @@ -2402,7 +2402,7 @@ public class Grid extends ResizeComposite implements private final UserSorter sorter = new UserSorter(); - private final EditorRow editorRow = GWT.create(EditorRow.class); + private final Editor editor = GWT.create(Editor.class); private boolean dataIsBeingFetched = false; @@ -3351,7 +3351,7 @@ public class Grid extends ResizeComposite implements footer.setGrid(this); - editorRow.setGrid(this); + editor.setGrid(this); setSelectionMode(SelectionMode.MULTI); @@ -3415,7 +3415,7 @@ public class Grid extends ResizeComposite implements public void setStylePrimaryName(String style) { super.setStylePrimaryName(style); escalator.setStylePrimaryName(style); - editorRow.setStylePrimaryName(style); + editor.setStylePrimaryName(style); String rowStyle = getStylePrimaryName() + "-row"; rowHasDataStyleName = rowStyle + "-has-data"; @@ -3987,8 +3987,8 @@ public class Grid extends ResizeComposite implements return footer.isVisible(); } - protected EditorRow getEditorRow() { - return editorRow; + protected Editor getEditor() { + return editor; } protected Escalator getEscalator() { @@ -4421,8 +4421,8 @@ public class Grid extends ResizeComposite implements assert cell != null : "received " + eventType + "-event with a null cell target"; - // Editor Row can steal focus from Grid and is still handled - if (handleEditorRowEvent(event, container, cell)) { + // Editor can steal focus from Grid and is still handled + if (handleEditorEvent(event, container, cell)) { return; } @@ -4470,26 +4470,26 @@ public class Grid extends ResizeComposite implements return w != null; } - private boolean handleEditorRowEvent(Event event, RowContainer container, + private boolean handleEditorEvent(Event event, RowContainer container, Cell cell) { - if (editorRow.getState() != EditorRow.State.INACTIVE) { + if (editor.getState() != Editor.State.INACTIVE) { if (event.getTypeInt() == Event.ONKEYDOWN - && event.getKeyCode() == EditorRow.KEYCODE_HIDE) { - editorRow.cancel(); + && event.getKeyCode() == Editor.KEYCODE_HIDE) { + editor.cancel(); } return true; } - if (container == escalator.getBody() && editorRow.isEnabled()) { + if (container == escalator.getBody() && editor.isEnabled()) { if (event.getTypeInt() == Event.ONDBLCLICK) { if (cell != null) { - editorRow.editRow(cell.getRow()); + editor.editRow(cell.getRow()); return true; } } else if (event.getTypeInt() == Event.ONKEYDOWN - && event.getKeyCode() == EditorRow.KEYCODE_SHOW) { - editorRow.editRow(cellFocusHandler.rowWithFocus); + && event.getKeyCode() == Editor.KEYCODE_SHOW) { + editor.editRow(cellFocusHandler.rowWithFocus); return true; } } @@ -5434,74 +5434,74 @@ public class Grid extends ResizeComposite implements * the index of the row to be edited * * @throws IllegalStateException - * if the editor row is not enabled + * if the editor is not enabled * @throws IllegalStateException - * if the editor row is already in edit mode + * if the editor is already in edit mode */ public void editRow(int rowIndex) { - editorRow.editRow(rowIndex); + editor.editRow(rowIndex); } /** - * Saves any unsaved changes to the data source. + * Saves any unsaved changes in the editor to the data source. * * @throws IllegalStateException - * if the editor row is not enabled + * if the editor is not enabled * @throws IllegalStateException - * if the editor row is not in edit mode + * if the editor is not in edit mode */ - public void saveEditorRow() { - editorRow.save(); + public void saveEditor() { + editor.save(); } /** * Cancels the currently active edit and hides the editor. Any changes that - * are not {@link #saveEditorRow() saved} are lost. + * are not {@link #saveEditor() saved} are lost. * * @throws IllegalStateException - * if the editor row is not enabled + * if the editor is not enabled * @throws IllegalStateException - * if the editor row is not in edit mode + * if the editor is not in edit mode */ - public void cancelEditorRow() { - editorRow.cancel(); + public void cancelEditor() { + editor.cancel(); } /** * Returns the handler responsible for binding data and editor widgets to - * the editor row. + * the editor. * - * @return the editor row handler or null if not set + * @return the editor handler or null if not set */ - public EditorRowHandler getEditorRowHandler() { - return editorRow.getHandler(); + public EditorHandler getEditorHandler() { + return editor.getHandler(); } /** * Sets the handler responsible for binding data and editor widgets to the - * editor row. + * editor. * * @param rowHandler - * the new editor row handler + * the new editor handler * * @throws IllegalStateException - * if the editor row is currently in edit mode + * if the editor is currently in edit mode */ - public void setEditorRowHandler(EditorRowHandler handler) { - editorRow.setHandler(handler); + public void setEditorHandler(EditorHandler handler) { + editor.setHandler(handler); } /** - * Returns the enabled state of the editor row. + * Returns the enabled state of the editor. * * @return true if editing is enabled, false otherwise */ - public boolean isEditorRowEnabled() { - return editorRow.isEnabled(); + public boolean isEditorEnabled() { + return editor.isEnabled(); } /** - * Sets the enabled state of the editor row. + * Sets the enabled state of the editor. * * @param enabled * true to enable editing, false to disable @@ -5509,22 +5509,22 @@ public class Grid extends ResizeComposite implements * @throws IllegalStateException * if in edit mode and trying to disable * @throws IllegalStateException - * if the editor row handler is not set + * if the editor handler is not set */ - public void setEditorRowEnabled(boolean enabled) { - editorRow.setEnabled(enabled); + public void setEditorEnabled(boolean enabled) { + editor.setEnabled(enabled); } /** * Returns the editor widget associated with the given column. If the editor - * row is not active, returns null. + * is not active, returns null. * * @param column * the column - * @return the widget if the editor row is open, null otherwise + * @return the widget if the editor is open, null otherwise */ - public Widget getEditorRowWidget(Column column) { - return editorRow.getWidget(column); + public Widget getEditorWidget(Column column) { + return editor.getWidget(column); } @Override diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 3daf63806d..a1403401c7 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -69,8 +69,8 @@ import com.vaadin.server.JsonCodec; import com.vaadin.server.KeyMapper; import com.vaadin.server.VaadinSession; import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.shared.ui.grid.EditorRowClientRpc; -import com.vaadin.shared.ui.grid.EditorRowServerRpc; +import com.vaadin.shared.ui.grid.EditorClientRpc; +import com.vaadin.shared.ui.grid.EditorServerRpc; import com.vaadin.shared.ui.grid.GridClientRpc; import com.vaadin.shared.ui.grid.GridColumnState; import com.vaadin.shared.ui.grid.GridServerRpc; @@ -2405,7 +2405,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, private final Footer footer = new Footer(this); private Object editedItemId = null; - private FieldGroup editorRowFieldGroup = new CustomFieldGroup(); + private FieldGroup editorFieldGroup = new CustomFieldGroup(); private CellStyleGenerator cellStyleGenerator; private RowStyleGenerator rowStyleGenerator; @@ -2596,14 +2596,14 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } }); - registerRpc(new EditorRowServerRpc() { + registerRpc(new EditorServerRpc() { @Override public void bind(int rowIndex) { try { Object id = getContainerDataSource().getIdByIndex(rowIndex); doEditItem(id); - getEditorRowRpc().confirmBind(); + getEditorRpc().confirmBind(); } catch (Exception e) { handleError(e); } @@ -2613,7 +2613,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, public void cancel(int rowIndex) { try { // For future proofing even though cannot currently fail - doCancelEditorRow(); + doCancelEditor(); } catch (Exception e) { handleError(e); } @@ -2622,8 +2622,8 @@ public class Grid extends AbstractComponent implements SelectionNotifier, @Override public void save(int rowIndex) { try { - saveEditorRow(); - getEditorRowRpc().confirmSave(); + saveEditor(); + getEditorRpc().confirmSave(); } catch (Exception e) { handleError(e); } @@ -2696,7 +2696,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, columnKeys.removeAll(); datasource = container; - resetEditorRow(); + resetEditor(); // // Adjust sort order @@ -2978,7 +2978,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * The property id of column to be removed */ public void removeColumn(Object propertyId) { - setEditorRowField(propertyId, null); + setEditorField(propertyId, null); header.removeColumn(propertyId); footer.removeColumn(propertyId); Column column = columns.remove(propertyId); @@ -3969,15 +3969,15 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } } - componentList.addAll(getEditorRowFields()); + componentList.addAll(getEditorFields()); return componentList.iterator(); } @Override public boolean isRendered(Component childComponent) { - if (getEditorRowFields().contains(childComponent)) { - // Only render editor row fields if the editor is open - return isEditorRowActive(); + if (getEditorFields().contains(childComponent)) { + // Only render editor fields if the editor is open + return isEditorActive(); } else { // TODO Header and footer components should also only be rendered if // the header/footer is visible @@ -3985,8 +3985,8 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } } - EditorRowClientRpc getEditorRowRpc() { - return getRpcProxy(EditorRowClientRpc.class); + EditorClientRpc getEditorRpc() { + return getRpcProxy(EditorClientRpc.class); } /** @@ -4113,36 +4113,41 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } /** - * Sets whether or not the editor row feature is enabled for this grid. + * Sets whether or not the item editor UI is enabled for this grid. When the + * editor is enabled, the user can open it by double-clicking a row or + * hitting enter when a row is focused. The editor can also be opened + * programmatically using the {@link #editItem(Object)} method. * * @param isEnabled * true to enable the feature, false * otherwise * @throws IllegalStateException * if an item is currently being edited + * * @see #getEditedItemId() */ - public void setEditorRowEnabled(boolean isEnabled) + public void setEditorEnabled(boolean isEnabled) throws IllegalStateException { - if (isEditorRowActive()) { + if (isEditorActive()) { throw new IllegalStateException( - "Cannot disable the editor row while an item (" - + getEditedItemId() + ") is being edited."); + "Cannot disable the editor while an item (" + + getEditedItemId() + ") is being edited"); } - if (isEditorRowEnabled() != isEnabled) { - getState().editorRowEnabled = isEnabled; + if (isEditorEnabled() != isEnabled) { + getState().editorEnabled = isEnabled; } } /** - * Checks whether the editor row feature is enabled for this grid. + * Checks whether the item editor UI is enabled for this grid. + * + * @return true iff the editor is enabled for this grid * - * @return true iff the editor row feature is enabled for this - * grid + * @see #setEditorEnabled(boolean) * @see #getEditedItemId() */ - public boolean isEditorRowEnabled() { - return getState(false).editorRowEnabled; + public boolean isEditorEnabled() { + return getState(false).editorEnabled; } /** @@ -4156,34 +4161,38 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } /** - * Gets the field group that is backing the editor row of this grid. + * Gets the field group that is backing the item editor of this grid. * * @return the backing field group */ - public FieldGroup getEditorRowFieldGroup() { - return editorRowFieldGroup; + public FieldGroup getEditorFieldGroup() { + return editorFieldGroup; } /** - * Sets the field group that is backing this editor row. + * Sets the field group that is backing the item editor of this grid. * * @param fieldGroup * the backing field group + * + * @throws IllegalStateException + * if the editor is currently active */ - public void setEditorRowFieldGroup(FieldGroup fieldGroup) { - editorRowFieldGroup = fieldGroup; - if (isEditorRowActive()) { - editorRowFieldGroup.setItemDataSource(getContainerDataSource() - .getItem(editedItemId)); + public void setEditorFieldGroup(FieldGroup fieldGroup) { + if (isEditorActive()) { + throw new IllegalStateException( + "Cannot change field group while an item (" + + getEditedItemId() + ") is being edited"); } + editorFieldGroup = fieldGroup; } /** - * Returns whether an item is currently being edited in the editor row. + * Returns whether an item is currently being edited in the editor. * - * @return true iff the editor row is editing an item + * @return true iff the editor is open */ - public boolean isEditorRowActive() { + public boolean isEditorActive() { return editedItemId != null; } @@ -4195,12 +4204,12 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } /** - * Gets the field component that represents a property in the editor row. + * Gets the field component that represents a property in the item editor. *

* When {@link #editItem(Object) editItem} is called, fields are * automatically created and bound for any unbound properties. *

- * Getting a field before the editor row has been opened depends on special + * Getting a field before the editor has been opened depends on special * support from the {@link FieldGroup} in use. Using this method with a * user-provided FieldGroup might cause {@link BindException} * to be thrown. @@ -4215,12 +4224,12 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * if no field has been configured and there is a problem * building or binding */ - public Field getEditorRowField(Object propertyId) { + public Field getEditorField(Object propertyId) { checkColumnExists(propertyId); - Field editor = editorRowFieldGroup.getField(propertyId); + Field editor = editorFieldGroup.getField(propertyId); if (editor == null) { - editor = editorRowFieldGroup.buildAndBind(propertyId); + editor = editorFieldGroup.buildAndBind(propertyId); } if (editor.getParent() != Grid.this) { @@ -4231,26 +4240,26 @@ public class Grid extends AbstractComponent implements SelectionNotifier, } /** - * Opens the editor row for the provided item. + * Opens the editor interface for the provided item. * * @param itemId * the id of the item to edit * @throws IllegalStateException - * if the editor row is not enabled + * if the editor is not enabled * @throws IllegalArgumentException * if the {@code itemId} is not in the backing container - * @see #setEditorRowEnabled(boolean) + * @see #setEditorEnabled(boolean) */ public void editItem(Object itemId) throws IllegalStateException, IllegalArgumentException { doEditItem(itemId); - getEditorRowRpc().bind(getContainerDataSource().indexOfId(itemId)); + getEditorRpc().bind(getContainerDataSource().indexOfId(itemId)); } protected void doEditItem(Object itemId) { - if (!isEditorRowEnabled()) { - throw new IllegalStateException("Editor row is not enabled"); + if (!isEditorEnabled()) { + throw new IllegalStateException("Item editor is not enabled"); } Item item = getContainerDataSource().getItem(itemId); @@ -4259,13 +4268,13 @@ public class Grid extends AbstractComponent implements SelectionNotifier, + " not found in current container"); } - editorRowFieldGroup.setItemDataSource(item); + editorFieldGroup.setItemDataSource(item); editedItemId = itemId; for (Column column : getColumns()) { Object propertyId = column.getColumnProperty(); - Field editor = getEditorRowField(propertyId); + Field editor = getEditorField(propertyId); getColumn(propertyId).getState().editorConnector = editor; } @@ -4277,25 +4286,26 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * {@link #editItem(Object)}. *

* Setting the field to null clears any previously set field, - * causing a new field to be created the next time the editor row is opened. + * causing a new field to be created the next time the item editor is + * opened. * * @param field * The field to bind * @param propertyId * The propertyId to bind the field to */ - public void setEditorRowField(Object propertyId, Field field) { + public void setEditorField(Object propertyId, Field field) { checkColumnExists(propertyId); - Field oldField = editorRowFieldGroup.getField(propertyId); + Field oldField = editorFieldGroup.getField(propertyId); if (oldField != null) { - editorRowFieldGroup.unbind(oldField); + editorFieldGroup.unbind(oldField); oldField.setParent(null); } if (field != null) { field.setParent(this); - editorRowFieldGroup.bind(field, propertyId); + editorFieldGroup.bind(field, propertyId); } } @@ -4309,51 +4319,51 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * * @see FieldGroup#commit() */ - public void saveEditorRow() throws CommitException { - editorRowFieldGroup.commit(); + public void saveEditor() throws CommitException { + editorFieldGroup.commit(); } /** * Cancels the currently active edit if any. */ - public void cancelEditorRow() { - if (isEditorRowActive()) { - getEditorRowRpc().cancel( + public void cancelEditor() { + if (isEditorActive()) { + getEditorRpc().cancel( getContainerDataSource().indexOfId(editedItemId)); - doCancelEditorRow(); + doCancelEditor(); } } - protected void doCancelEditorRow() { + protected void doCancelEditor() { editedItemId = null; } - void resetEditorRow() { - if (isEditorRowActive()) { + void resetEditor() { + if (isEditorActive()) { /* * Simply force cancel the editing; throwing here would just make * Grid.setContainerDataSource semantics more complicated. */ - cancelEditorRow(); + cancelEditor(); } - for (Field editor : getEditorRowFields()) { + for (Field editor : getEditorFields()) { editor.setParent(null); } editedItemId = null; - editorRowFieldGroup = new CustomFieldGroup(); + editorFieldGroup = new CustomFieldGroup(); } /** - * Gets a collection of all fields bound to the editor row of this grid. + * Gets a collection of all fields bound to the item editor of this grid. *

* When {@link #editItem(Object) editItem} is called, fields are * automatically created and bound to any unbound properties. * - * @return a collection of all the fields bound to this editor row + * @return a collection of all the fields bound to the item editor */ - Collection> getEditorRowFields() { - Collection> fields = editorRowFieldGroup.getFields(); + Collection> getEditorFields() { + Collection> fields = editorFieldGroup.getFields(); assert allAttached(fields); return fields; } @@ -4376,7 +4386,7 @@ public class Grid extends AbstractComponent implements SelectionNotifier, * @param fieldFactory * The field factory to use */ - public void setEditorRowFieldFactory(FieldGroupFieldFactory fieldFactory) { - editorRowFieldGroup.setFieldFactory(fieldFactory); + public void setEditorFieldFactory(FieldGroupFieldFactory fieldFactory) { + editorFieldGroup.setFieldFactory(fieldFactory); } } diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/EditorRowTests.java b/server/tests/src/com/vaadin/tests/server/component/grid/EditorRowTests.java deleted file mode 100644 index 6252b6b568..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/grid/EditorRowTests.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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.server.component.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.easymock.EasyMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.data.Item; -import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.data.util.IndexedContainer; -import com.vaadin.server.MockVaadinSession; -import com.vaadin.server.VaadinService; -import com.vaadin.server.VaadinSession; -import com.vaadin.ui.Field; -import com.vaadin.ui.Grid; -import com.vaadin.ui.TextField; - -public class EditorRowTests { - - private static final Object PROPERTY_NAME = "name"; - private static final Object PROPERTY_AGE = "age"; - private static final Object ITEM_ID = new Object(); - - private Grid grid; - - // Explicit field for the test session to save it from GC - private VaadinSession session; - - @Before - @SuppressWarnings("unchecked") - public void setup() { - IndexedContainer container = new IndexedContainer(); - container.addContainerProperty(PROPERTY_NAME, String.class, "[name]"); - container.addContainerProperty(PROPERTY_AGE, Integer.class, - Integer.valueOf(-1)); - - Item item = container.addItem(ITEM_ID); - item.getItemProperty(PROPERTY_NAME).setValue("Some Valid Name"); - item.getItemProperty(PROPERTY_AGE).setValue(Integer.valueOf(25)); - - grid = new Grid(container); - - // VaadinSession needed for ConverterFactory - VaadinService mockService = EasyMock - .createNiceMock(VaadinService.class); - session = new MockVaadinSession(mockService); - VaadinSession.setCurrent(session); - session.lock(); - } - - @After - public void tearDown() { - session.unlock(); - session = null; - VaadinSession.setCurrent(null); - } - - @Test - public void initAssumptions() throws Exception { - assertFalse(grid.isEditorRowEnabled()); - assertNull(grid.getEditedItemId()); - assertNotNull(grid.getEditorRowFieldGroup()); - } - - @Test - public void setEnabled() throws Exception { - assertFalse(grid.isEditorRowEnabled()); - grid.setEditorRowEnabled(true); - assertTrue(grid.isEditorRowEnabled()); - } - - @Test - public void setDisabled() throws Exception { - assertFalse(grid.isEditorRowEnabled()); - grid.setEditorRowEnabled(true); - grid.setEditorRowEnabled(false); - assertFalse(grid.isEditorRowEnabled()); - } - - @Test - public void setReEnabled() throws Exception { - assertFalse(grid.isEditorRowEnabled()); - grid.setEditorRowEnabled(true); - grid.setEditorRowEnabled(false); - grid.setEditorRowEnabled(true); - assertTrue(grid.isEditorRowEnabled()); - } - - @Test - public void detached() throws Exception { - FieldGroup oldFieldGroup = grid.getEditorRowFieldGroup(); - grid.removeAllColumns(); - grid.setContainerDataSource(new IndexedContainer()); - assertFalse(oldFieldGroup == grid.getEditorRowFieldGroup()); - } - - @Test(expected = IllegalStateException.class) - public void disabledEditItem() throws Exception { - grid.editItem(ITEM_ID); - } - - @Test - public void editItem() throws Exception { - startEdit(); - assertEquals(ITEM_ID, grid.getEditedItemId()); - } - - @Test(expected = IllegalArgumentException.class) - public void nonexistentEditItem() throws Exception { - grid.setEditorRowEnabled(true); - grid.editItem(new Object()); - } - - @Test - public void getField() throws Exception { - startEdit(); - - assertNotNull(grid.getEditorRowField(PROPERTY_NAME)); - } - - @Test - public void getFieldWithoutItem() throws Exception { - grid.setEditorRowEnabled(true); - assertNotNull(grid.getEditorRowField(PROPERTY_NAME)); - } - - @Test - public void customBinding() { - TextField textField = new TextField(); - grid.setEditorRowField(PROPERTY_NAME, textField); - - startEdit(); - - assertSame(textField, grid.getEditorRowField(PROPERTY_NAME)); - } - - @Test(expected = IllegalStateException.class) - public void disableWhileEditing() { - startEdit(); - grid.setEditorRowEnabled(false); - } - - @Test - public void fieldIsNotReadonly() { - startEdit(); - - Field field = grid.getEditorRowField(PROPERTY_NAME); - assertFalse(field.isReadOnly()); - } - - @Test - public void fieldIsReadonlyWhenFieldGroupIsReadonly() { - startEdit(); - - grid.getEditorRowFieldGroup().setReadOnly(true); - Field field = grid.getEditorRowField(PROPERTY_NAME); - assertTrue(field.isReadOnly()); - } - - @Test - public void columnRemoved() { - Field field = grid.getEditorRowField(PROPERTY_NAME); - - assertSame("field should be attached to grid.", grid, field.getParent()); - - grid.removeColumn(PROPERTY_NAME); - - assertNull("field should be detached from grid.", field.getParent()); - } - - @Test - public void setFieldAgain() { - TextField field = new TextField(); - grid.setEditorRowField(PROPERTY_NAME, field); - - field = new TextField(); - grid.setEditorRowField(PROPERTY_NAME, field); - - assertSame("new field should be used.", field, - grid.getEditorRowField(PROPERTY_NAME)); - } - - private void startEdit() { - grid.setEditorRowEnabled(true); - grid.editItem(ITEM_ID); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java b/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java new file mode 100644 index 0000000000..c3817efc3f --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/grid/GridEditorTest.java @@ -0,0 +1,209 @@ +/* + * 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.server.component.grid; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import org.easymock.EasyMock; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.data.Item; +import com.vaadin.data.fieldgroup.FieldGroup; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.MockVaadinSession; +import com.vaadin.server.VaadinService; +import com.vaadin.server.VaadinSession; +import com.vaadin.ui.Field; +import com.vaadin.ui.Grid; +import com.vaadin.ui.TextField; + +public class GridEditorTest { + + private static final Object PROPERTY_NAME = "name"; + private static final Object PROPERTY_AGE = "age"; + private static final Object ITEM_ID = new Object(); + + private Grid grid; + + // Explicit field for the test session to save it from GC + private VaadinSession session; + + @Before + @SuppressWarnings("unchecked") + public void setup() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty(PROPERTY_NAME, String.class, "[name]"); + container.addContainerProperty(PROPERTY_AGE, Integer.class, + Integer.valueOf(-1)); + + Item item = container.addItem(ITEM_ID); + item.getItemProperty(PROPERTY_NAME).setValue("Some Valid Name"); + item.getItemProperty(PROPERTY_AGE).setValue(Integer.valueOf(25)); + + grid = new Grid(container); + + // VaadinSession needed for ConverterFactory + VaadinService mockService = EasyMock + .createNiceMock(VaadinService.class); + session = new MockVaadinSession(mockService); + VaadinSession.setCurrent(session); + session.lock(); + } + + @After + public void tearDown() { + session.unlock(); + session = null; + VaadinSession.setCurrent(null); + } + + @Test + public void initAssumptions() throws Exception { + assertFalse(grid.isEditorEnabled()); + assertNull(grid.getEditedItemId()); + assertNotNull(grid.getEditorFieldGroup()); + } + + @Test + public void setEnabled() throws Exception { + assertFalse(grid.isEditorEnabled()); + grid.setEditorEnabled(true); + assertTrue(grid.isEditorEnabled()); + } + + @Test + public void setDisabled() throws Exception { + assertFalse(grid.isEditorEnabled()); + grid.setEditorEnabled(true); + grid.setEditorEnabled(false); + assertFalse(grid.isEditorEnabled()); + } + + @Test + public void setReEnabled() throws Exception { + assertFalse(grid.isEditorEnabled()); + grid.setEditorEnabled(true); + grid.setEditorEnabled(false); + grid.setEditorEnabled(true); + assertTrue(grid.isEditorEnabled()); + } + + @Test + public void detached() throws Exception { + FieldGroup oldFieldGroup = grid.getEditorFieldGroup(); + grid.removeAllColumns(); + grid.setContainerDataSource(new IndexedContainer()); + assertFalse(oldFieldGroup == grid.getEditorFieldGroup()); + } + + @Test(expected = IllegalStateException.class) + public void disabledEditItem() throws Exception { + grid.editItem(ITEM_ID); + } + + @Test + public void editItem() throws Exception { + startEdit(); + assertEquals(ITEM_ID, grid.getEditedItemId()); + } + + @Test(expected = IllegalArgumentException.class) + public void nonexistentEditItem() throws Exception { + grid.setEditorEnabled(true); + grid.editItem(new Object()); + } + + @Test + public void getField() throws Exception { + startEdit(); + + assertNotNull(grid.getEditorField(PROPERTY_NAME)); + } + + @Test + public void getFieldWithoutItem() throws Exception { + grid.setEditorEnabled(true); + assertNotNull(grid.getEditorField(PROPERTY_NAME)); + } + + @Test + public void customBinding() { + TextField textField = new TextField(); + grid.setEditorField(PROPERTY_NAME, textField); + + startEdit(); + + assertSame(textField, grid.getEditorField(PROPERTY_NAME)); + } + + @Test(expected = IllegalStateException.class) + public void disableWhileEditing() { + startEdit(); + grid.setEditorEnabled(false); + } + + @Test + public void fieldIsNotReadonly() { + startEdit(); + + Field field = grid.getEditorField(PROPERTY_NAME); + assertFalse(field.isReadOnly()); + } + + @Test + public void fieldIsReadonlyWhenFieldGroupIsReadonly() { + startEdit(); + + grid.getEditorFieldGroup().setReadOnly(true); + Field field = grid.getEditorField(PROPERTY_NAME); + assertTrue(field.isReadOnly()); + } + + @Test + public void columnRemoved() { + Field field = grid.getEditorField(PROPERTY_NAME); + + assertSame("field should be attached to grid.", grid, field.getParent()); + + grid.removeColumn(PROPERTY_NAME); + + assertNull("field should be detached from grid.", field.getParent()); + } + + @Test + public void setFieldAgain() { + TextField field = new TextField(); + grid.setEditorField(PROPERTY_NAME, field); + + field = new TextField(); + grid.setEditorField(PROPERTY_NAME, field); + + assertSame("new field should be used.", field, + grid.getEditorField(PROPERTY_NAME)); + } + + private void startEdit() { + grid.setEditorEnabled(true); + grid.editItem(ITEM_ID); + } +} diff --git a/shared/src/com/vaadin/shared/ui/grid/EditorClientRpc.java b/shared/src/com/vaadin/shared/ui/grid/EditorClientRpc.java new file mode 100644 index 0000000000..c083252754 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/grid/EditorClientRpc.java @@ -0,0 +1,55 @@ +/* + * 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.shared.ui.grid; + +import com.vaadin.shared.communication.ClientRpc; + +/** + * An RPC interface for the grid editor server-to-client communications. + * + * @since + * @author Vaadin Ltd + */ +public interface EditorClientRpc extends ClientRpc { + + /** + * Tells the client to open the editor and bind data to it. + * + * @param rowIndex + * the index of the edited row + */ + void bind(int rowIndex); + + /** + * Tells the client to cancel editing and hide the editor. + * + * @param rowIndex + * the index of the edited row + */ + void cancel(int rowIndex); + + /** + * Confirms a pending {@link EditorServerRpc#bind(int) bind request} + * sent by the client. + */ + void confirmBind(); + + /** + * Confirms a pending {@link EditorServerRpc#save(int) save request} + * sent by the client. + */ + void confirmSave(); +} diff --git a/shared/src/com/vaadin/shared/ui/grid/EditorRowClientRpc.java b/shared/src/com/vaadin/shared/ui/grid/EditorRowClientRpc.java deleted file mode 100644 index c72f767f3c..0000000000 --- a/shared/src/com/vaadin/shared/ui/grid/EditorRowClientRpc.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.shared.ui.grid; - -import com.vaadin.shared.communication.ClientRpc; - -/** - * An RPC interface for the grid editor row server-to-client communications. - * - * @since - * @author Vaadin Ltd - */ -public interface EditorRowClientRpc extends ClientRpc { - - /** - * Tells the client to open the editor row and bind data to it. - * - * @param rowIndex - * the index of the edited row - */ - void bind(int rowIndex); - - /** - * Tells the client to cancel editing and hide the editor row. - * - * @param rowIndex - * the index of the edited row - */ - void cancel(int rowIndex); - - /** - * Confirms a pending {@link EditorRowServerRpc#bind(int) bind request} sent - * by the client. - */ - void confirmBind(); - - /** - * Confirms a pending {@link EditorRowServerRpc#save(int) save request} sent - * by the client. - */ - void confirmSave(); -} diff --git a/shared/src/com/vaadin/shared/ui/grid/EditorRowServerRpc.java b/shared/src/com/vaadin/shared/ui/grid/EditorRowServerRpc.java deleted file mode 100644 index 8215e8963c..0000000000 --- a/shared/src/com/vaadin/shared/ui/grid/EditorRowServerRpc.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.shared.ui.grid; - -import com.vaadin.shared.communication.ServerRpc; - -/** - * An RPC interface for the grid editor row client-to-server communications. - * - * @since - * @author Vaadin Ltd - */ -public interface EditorRowServerRpc extends ServerRpc { - - /** - * Asks the server to open the editor row and bind data to it. When a bind - * request is sent, it must be acknowledged with a - * {@link EditorRowClientRpc#confirmBind() confirm call} before the client - * can open the editor. - * - * @param rowIndex - * the index of the edited row - */ - void bind(int rowIndex); - - /** - * Asks the server to save unsaved changes in the editor row to the data - * source. When a save request is sent, it must be acknowledged with a - * {@link EditorRowClientRpc#confirmSave() confirm call}. - * - * @param rowIndex - * the index of the edited row - */ - void save(int rowIndex); - - /** - * Tells the server to cancel editing. When sending a cancel request, the - * client does not need to wait for confirmation by the server before hiding - * the editor row. - * - * @param rowIndex - * the index of the edited row - */ - void cancel(int rowIndex); -} diff --git a/shared/src/com/vaadin/shared/ui/grid/EditorServerRpc.java b/shared/src/com/vaadin/shared/ui/grid/EditorServerRpc.java new file mode 100644 index 0000000000..57df691547 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/grid/EditorServerRpc.java @@ -0,0 +1,58 @@ +/* + * 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.shared.ui.grid; + +import com.vaadin.shared.communication.ServerRpc; + +/** + * An RPC interface for the grid editor client-to-server communications. + * + * @since + * @author Vaadin Ltd + */ +public interface EditorServerRpc extends ServerRpc { + + /** + * Asks the server to open the editor and bind data to it. When a bind + * request is sent, it must be acknowledged with a + * {@link EditorClientRpc#confirmBind() confirm call} before the client + * can open the editor. + * + * @param rowIndex + * the index of the edited row + */ + void bind(int rowIndex); + + /** + * Asks the server to save unsaved changes in the editor to the data source. + * When a save request is sent, it must be acknowledged with a + * {@link EditorClientRpc#confirmSave() confirm call}. + * + * @param rowIndex + * the index of the edited row + */ + void save(int rowIndex); + + /** + * Tells the server to cancel editing. When sending a cancel request, the + * client does not need to wait for confirmation by the server before hiding + * the editor. + * + * @param rowIndex + * the index of the edited row + */ + void cancel(int rowIndex); +} diff --git a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java index 34e6fb4cfd..11cb133fa5 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridColumnState.java @@ -53,7 +53,7 @@ public class GridColumnState implements Serializable { /** * The connector for the field used to edit cells in this column when the - * editor row is active. + * editor interface is active. */ public Connector editorConnector; diff --git a/shared/src/com/vaadin/shared/ui/grid/GridState.java b/shared/src/com/vaadin/shared/ui/grid/GridState.java index 4cf834c4f0..1f98431caf 100644 --- a/shared/src/com/vaadin/shared/ui/grid/GridState.java +++ b/shared/src/com/vaadin/shared/ui/grid/GridState.java @@ -138,8 +138,8 @@ public class GridState extends AbstractComponentState { /** Directions for each sorted column */ public SortDirection[] sortDirs = new SortDirection[0]; - /** The enabled state of the editor row */ - public boolean editorRowEnabled = false; + /** The enabled state of the editor interface */ + public boolean editorEnabled = false; /** Whether row data might contain generated row styles */ public boolean hasRowStyleGenerator; diff --git a/uitest/src/com/vaadin/tests/components/grid/EditorRowUI.java b/uitest/src/com/vaadin/tests/components/grid/EditorRowUI.java deleted file mode 100644 index 3891583098..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/EditorRowUI.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.PersonContainer; -import com.vaadin.ui.Grid; -import com.vaadin.ui.PasswordField; -import com.vaadin.ui.TextField; - -public class EditorRowUI extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - PersonContainer container = PersonContainer.createWithTestData(); - - Grid grid = new Grid(container); - - // Don't use address since there's no converter - grid.removeColumn("address"); - - grid.setEditorRowEnabled(true); - - grid.setEditorRowField("firstName", new PasswordField()); - - TextField lastNameField = (TextField) grid - .getEditorRowField("lastName"); - lastNameField.setMaxLength(50); - - grid.getEditorRowField("phoneNumber").setReadOnly(true); - - addComponent(grid); - } - -} diff --git a/uitest/src/com/vaadin/tests/components/grid/EditorRowUITest.java b/uitest/src/com/vaadin/tests/components/grid/EditorRowUITest.java deleted file mode 100644 index 269f997c95..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/EditorRowUITest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.elements.PasswordFieldElement; -import com.vaadin.tests.annotations.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class EditorRowUITest extends MultiBrowserTest { - - @Test - public void testEditorRow() { - setDebug(true); - openTestURL(); - - assertFalse("Sanity check", - isElementPresent(PasswordFieldElement.class)); - - openEditorRow(5); - new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); - - openEditorRow(10); - - assertTrue("Edtor row should be opened with a password field", - isElementPresent(PasswordFieldElement.class)); - - assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - } - - private void openEditorRow(int rowIndex) { - GridElement grid = $(GridElement.class).first(); - - GridCellElement cell = grid.getCell(rowIndex, 1); - - new Actions(driver).moveToElement(cell).doubleClick().build().perform(); - } - -} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java new file mode 100644 index 0000000000..fe4b4342a2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditorUI.java @@ -0,0 +1,49 @@ +/* + * 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; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.ui.Grid; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.TextField; + +public class GridEditorUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + PersonContainer container = PersonContainer.createWithTestData(); + + Grid grid = new Grid(container); + + // Don't use address since there's no converter + grid.removeColumn("address"); + + grid.setEditorEnabled(true); + + grid.setEditorField("firstName", new PasswordField()); + + TextField lastNameField = (TextField) grid + .getEditorField("lastName"); + lastNameField.setMaxLength(50); + + grid.getEditorField("phoneNumber").setReadOnly(true); + + addComponent(grid); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridEditorUITest.java b/uitest/src/com/vaadin/tests/components/grid/GridEditorUITest.java new file mode 100644 index 0000000000..6c386eec03 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridEditorUITest.java @@ -0,0 +1,63 @@ +/* + * 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; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.tests.annotations.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridEditorUITest extends MultiBrowserTest { + + @Test + public void testEditor() { + setDebug(true); + openTestURL(); + + assertFalse("Sanity check", + isElementPresent(PasswordFieldElement.class)); + + openEditor(5); + new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); + + openEditor(10); + + assertTrue("Edtor should be opened with a password field", + isElementPresent(PasswordFieldElement.class)); + + assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + } + + private void openEditor(int rowIndex) { + GridElement grid = $(GridElement.class).first(); + + GridCellElement cell = grid.getCell(rowIndex, 1); + + new Actions(driver).moveToElement(cell).doubleClick().build().perform(); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java index 62f3488447..9aceef70bb 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -189,7 +189,7 @@ public class GridBasicFeatures extends AbstractComponentTest { grid.setSelectionMode(SelectionMode.NONE); - grid.getEditorRowField(getColumnProperty(3)).setReadOnly(true); + grid.getEditorField(getColumnProperty(3)).setReadOnly(true); createGridActions(); @@ -203,7 +203,7 @@ public class GridBasicFeatures extends AbstractComponentTest { createRowActions(); - createEditorRowActions(); + createEditorActions(); addHeightActions(); @@ -853,48 +853,46 @@ public class GridBasicFeatures extends AbstractComponentTest { }, null); } - protected void createEditorRowActions() { - createBooleanAction("Enabled", "Editor row", false, + protected void createEditorActions() { + createBooleanAction("Enabled", "Editor", false, new Command() { @Override public void execute(Grid c, Boolean value, Object data) { - c.setEditorRowEnabled(value); + c.setEditorEnabled(value); } }); - createClickAction("Edit item 5", "Editor row", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.editItem(5); - } - }, null); + createClickAction("Edit item 5", "Editor", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.editItem(5); + } + }, null); - createClickAction("Edit item 100", "Editor row", + createClickAction("Edit item 100", "Editor", new Command() { @Override public void execute(Grid c, String value, Object data) { c.editItem(100); } }, null); - createClickAction("Save", "Editor row", new Command() { + createClickAction("Save", "Editor", new Command() { @Override public void execute(Grid c, String value, Object data) { try { - c.saveEditorRow(); + c.saveEditor(); } catch (CommitException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }, null); - createClickAction("Cancel edit", "Editor row", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.cancelEditorRow(); - } - }, null); + createClickAction("Cancel edit", "Editor", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.cancelEditor(); + } + }, null); } @SuppressWarnings("boxing") diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java index 50e1034b50..279f75492e 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java @@ -90,11 +90,11 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest { return footerCells; } - protected WebElement getEditorRow() { + protected WebElement getEditor() { List elems = getGridElement().findElements( By.className("v-grid-editor-row")); - assertLessThanOrEqual("number of editor rows", elems.size(), 1); + assertLessThanOrEqual("number of editors", elems.size(), 1); return elems.isEmpty() ? null : elems.get(0); } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorRowTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorRowTest.java deleted file mode 100644 index 1fa8549b1c..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorRowTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures.client; - -import org.junit.Before; - -public class GridClientCompositeEditorRowTest extends GridEditorRowClientTest { - - @Override - @Before - public void setUp() { - setUseComposite(true); - super.setUp(); - } -} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java new file mode 100644 index 0000000000..29e6fed68c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java @@ -0,0 +1,13 @@ +package com.vaadin.tests.components.grid.basicfeatures.client; + +import org.junit.Before; + +public class GridClientCompositeEditorTest extends GridEditorClientTest { + + @Override + @Before + public void setUp() { + setUseComposite(true); + super.setUp(); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java new file mode 100644 index 0000000000..5db7f3a0b9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java @@ -0,0 +1,155 @@ +/* + * 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.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; + +public class GridEditorClientTest extends GridBasicClientFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "Editor", "Enabled"); + } + + @Test + public void testProgrammaticOpeningClosing() { + selectMenuPath("Component", "Editor", "Edit row 5"); + assertNotNull(getEditor()); + + selectMenuPath("Component", "Editor", "Cancel edit"); + assertNull(getEditor()); + assertEquals("Row 5 edit cancelled", + findElement(By.className("grid-editor-log")).getText()); + } + + @Test + public void testProgrammaticOpeningWithScroll() { + selectMenuPath("Component", "Editor", "Edit row 100"); + assertNotNull(getEditor()); + } + + @Test(expected = NoSuchElementException.class) + public void testVerticalScrollLocking() { + selectMenuPath("Component", "Editor", "Edit row 5"); + getGridElement().getCell(200, 0); + } + + @Test + public void testKeyboardOpeningClosing() { + + getGridElement().getCell(4, 0).click(); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertNotNull(getEditor()); + + new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); + assertNull(getEditor()); + assertEquals("Row 4 edit cancelled", + findElement(By.className("grid-editor-log")).getText()); + + // Disable editor + selectMenuPath("Component", "Editor", "Enabled"); + + getGridElement().getCell(5, 0).click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertNull(getEditor()); + } + + @Test + public void testWidgetBinding() throws Exception { + selectMenuPath("Component", "Editor", "Edit row 100"); + WebElement editor = getEditor(); + + List widgets = editor.findElements(By + .className("gwt-TextBox")); + + assertEquals(GridBasicFeatures.COLUMNS, widgets.size()); + + assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); + assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); + assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); + + assertEquals("100", widgets.get(7).getAttribute("value")); + assertEquals("100", widgets.get(9).getAttribute("value")); + } + + @Test + public void testWithSelectionColumn() throws Exception { + selectMenuPath("Component", "State", "Selection mode", "multi"); + selectMenuPath("Component", "State", "Editor", "Edit row 5"); + + WebElement editor = getEditor(); + List selectorDivs = editor.findElements(By + .cssSelector("div")); + + assertTrue("selector column cell should've been empty", selectorDivs + .get(0).getAttribute("innerHTML").isEmpty()); + assertFalse("normal column cell shoul've had contents", selectorDivs + .get(1).getAttribute("innerHTML").isEmpty()); + } + + @Test + public void testSave() { + selectMenuPath("Component", "Editor", "Edit row 100"); + + WebElement textField = getEditor().findElements( + By.className("gwt-TextBox")).get(0); + + textField.clear(); + textField.sendKeys("Changed"); + + WebElement saveButton = getEditor().findElement( + By.className("v-editor-row-save")); + + saveButton.click(); + + assertEquals("Changed", getGridElement().getCell(100, 0).getText()); + } + + @Test + public void testProgrammaticSave() { + selectMenuPath("Component", "Editor", "Edit row 100"); + + WebElement textField = getEditor().findElements( + By.className("gwt-TextBox")).get(0); + + textField.clear(); + textField.sendKeys("Changed"); + + selectMenuPath("Component", "Editor", "Save"); + + assertEquals("Changed", getGridElement().getCell(100, 0).getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorRowClientTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorRowClientTest.java deleted file mode 100644 index f3c49db39e..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorRowClientTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; - -public class GridEditorRowClientTest extends GridBasicClientFeaturesTest { - - @Before - public void setUp() { - openTestURL(); - selectMenuPath("Component", "Editor row", "Enabled"); - } - - @Test - public void testProgrammaticOpeningClosing() { - selectMenuPath("Component", "Editor row", "Edit row 5"); - assertNotNull(getEditorRow()); - - selectMenuPath("Component", "Editor row", "Cancel edit"); - assertNull(getEditorRow()); - assertEquals("Row 5 edit cancelled", - findElement(By.className("editor-row-log")).getText()); - } - - @Test - public void testProgrammaticOpeningWithScroll() { - selectMenuPath("Component", "Editor row", "Edit row 100"); - assertNotNull(getEditorRow()); - } - - @Test(expected = NoSuchElementException.class) - public void testVerticalScrollLocking() { - selectMenuPath("Component", "Editor row", "Edit row 5"); - getGridElement().getCell(200, 0); - } - - @Test - public void testKeyboardOpeningClosing() { - - getGridElement().getCell(4, 0).click(); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - assertNotNull(getEditorRow()); - - new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); - assertNull(getEditorRow()); - assertEquals("Row 4 edit cancelled", - findElement(By.className("editor-row-log")).getText()); - - // Disable editor row - selectMenuPath("Component", "Editor row", "Enabled"); - - getGridElement().getCell(5, 0).click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertNull(getEditorRow()); - } - - @Test - public void testWidgetBinding() throws Exception { - selectMenuPath("Component", "Editor row", "Edit row 100"); - WebElement editorRow = getEditorRow(); - - List widgets = editorRow.findElements(By - .className("gwt-TextBox")); - - assertEquals(GridBasicFeatures.COLUMNS, widgets.size()); - - assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); - assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); - assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); - - assertEquals("100", widgets.get(7).getAttribute("value")); - assertEquals("100", widgets.get(9).getAttribute("value")); - } - - @Test - public void testWithSelectionColumn() throws Exception { - selectMenuPath("Component", "State", "Selection mode", "multi"); - selectMenuPath("Component", "State", "Editor row", "Edit row 5"); - - WebElement editorRow = getEditorRow(); - List selectorDivs = editorRow.findElements(By - .cssSelector("div")); - - assertTrue("selector column cell should've been empty", selectorDivs - .get(0).getAttribute("innerHTML").isEmpty()); - assertFalse("normal column cell shoul've had contents", selectorDivs - .get(1).getAttribute("innerHTML").isEmpty()); - } - - @Test - public void testSave() { - selectMenuPath("Component", "Editor row", "Edit row 100"); - - WebElement textField = getEditorRow().findElements( - By.className("gwt-TextBox")).get(0); - - textField.clear(); - textField.sendKeys("Changed"); - - WebElement saveButton = getEditorRow().findElement( - By.className("v-editor-row-save")); - - saveButton.click(); - - assertEquals("Changed", getGridElement().getCell(100, 0).getText()); - } - - @Test - public void testProgrammaticSave() { - selectMenuPath("Component", "Editor row", "Edit row 100"); - - WebElement textField = getEditorRow().findElements( - By.className("gwt-TextBox")).get(0); - - textField.clear(); - textField.sendKeys("Changed"); - - selectMenuPath("Component", "Editor row", "Save"); - - assertEquals("Changed", getGridElement().getCell(100, 0).getText()); - } -} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorRowTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorRowTest.java deleted file mode 100644 index f07d33080d..0000000000 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorRowTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridEditorRowTest extends GridBasicFeaturesTest { - - @Before - public void setUp() { - openTestURL(); - selectMenuPath("Component", "Editor row", "Enabled"); - } - - @Test - public void testProgrammaticOpeningClosing() { - selectMenuPath("Component", "Editor row", "Edit item 5"); - assertEditorRowOpen(); - - selectMenuPath("Component", "Editor row", "Cancel edit"); - assertEditorRowClosed(); - } - - @Test - public void testProgrammaticOpeningWhenDisabled() { - selectMenuPath("Component", "Editor row", "Enabled"); - selectMenuPath("Component", "Editor row", "Edit item 5"); - assertEditorRowClosed(); - assertEquals( - "5. Exception occured, java.lang.IllegalStateExceptionEditor row is not enabled", - getLogRow(0)); - } - - @Test - public void testDisablingWhileOpen() { - selectMenuPath("Component", "Editor row", "Edit item 5"); - selectMenuPath("Component", "Editor row", "Enabled"); - assertEditorRowOpen(); - assertEquals( - "5. Exception occured, java.lang.IllegalStateExceptionCannot disable the editor row while an item (5) is being edited.", - getLogRow(0)); - - } - - @Test - public void testProgrammaticOpeningWithScroll() { - selectMenuPath("Component", "Editor row", "Edit item 100"); - assertEditorRowOpen(); - } - - @Test(expected = NoSuchElementException.class) - public void testVerticalScrollLocking() { - selectMenuPath("Component", "Editor row", "Edit item 5"); - getGridElement().getCell(200, 0); - } - - @Test - public void testKeyboardOpeningClosing() { - - getGridElement().getCell(4, 0).click(); - assertEditorRowClosed(); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertEditorRowOpen(); - - new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); - assertEditorRowClosed(); - - // Disable editor row - selectMenuPath("Component", "Editor row", "Enabled"); - getGridElement().getCell(5, 0).click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertEditorRowClosed(); - } - - @Test - public void testComponentBinding() { - selectMenuPath("Component", "State", "Editor row", "Edit item 100"); - - List widgets = getEditorWidgets(); - assertEquals("Number of widgets", GridBasicFeatures.COLUMNS, - widgets.size()); - - assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); - assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); - assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); - assertEquals("100", widgets.get(9).getAttribute("value")); - } - - @Test - public void testSave() { - selectMenuPath("Component", "Editor row", "Edit item 100"); - - WebElement textField = getEditorWidgets().get(0); - - textField.click(); - - textField.sendKeys(" changed"); - - WebElement saveButton = getEditorRow().findElement( - By.className("v-editor-row-save")); - - saveButton.click(); - - assertEquals("(100, 0) changed", getGridElement().getCell(100, 0) - .getText()); - } - - @Test - public void testProgrammaticSave() { - selectMenuPath("Component", "Editor row", "Edit item 100"); - - WebElement textField = getEditorWidgets().get(0); - - textField.click(); - - textField.sendKeys(" changed"); - - selectMenuPath("Component", "Editor row", "Save"); - - assertEquals("(100, 0) changed", getGridElement().getCell(100, 0) - .getText()); - } - - private void assertEditorRowOpen() { - assertNotNull("Editor row open", getEditorRow()); - assertEquals("Number of widgets", GridBasicFeatures.COLUMNS, - getEditorWidgets().size()); - } - - private void assertEditorRowClosed() { - assertNull("Editor row closed", getEditorRow()); - } - - private List getEditorWidgets() { - assertNotNull(getEditorRow()); - return getEditorRow().findElements(By.className("v-textfield")); - - } -} diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java new file mode 100644 index 0000000000..2afa9ec04e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java @@ -0,0 +1,168 @@ +/* + * 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.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridEditorTest extends GridBasicFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "Editor", "Enabled"); + } + + @Test + public void testProgrammaticOpeningClosing() { + selectMenuPath("Component", "Editor", "Edit item 5"); + assertEditorOpen(); + + selectMenuPath("Component", "Editor", "Cancel edit"); + assertEditorClosed(); + } + + @Test + public void testProgrammaticOpeningWhenDisabled() { + selectMenuPath("Component", "Editor", "Enabled"); + selectMenuPath("Component", "Editor", "Edit item 5"); + assertEditorClosed(); + boolean thrown = getLogRow(0).startsWith( + "5. Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + } + + @Test + public void testDisablingWhileOpen() { + selectMenuPath("Component", "Editor", "Edit item 5"); + selectMenuPath("Component", "Editor", "Enabled"); + assertEditorOpen(); + boolean thrown = getLogRow(0).startsWith( + "5. Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + } + + @Test + public void testProgrammaticOpeningWithScroll() { + selectMenuPath("Component", "Editor", "Edit item 100"); + assertEditorOpen(); + } + + @Test(expected = NoSuchElementException.class) + public void testVerticalScrollLocking() { + selectMenuPath("Component", "Editor", "Edit item 5"); + getGridElement().getCell(200, 0); + } + + @Test + public void testKeyboardOpeningClosing() { + + getGridElement().getCell(4, 0).click(); + assertEditorClosed(); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertEditorOpen(); + + new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); + assertEditorClosed(); + + // Disable Editor + selectMenuPath("Component", "Editor", "Enabled"); + getGridElement().getCell(5, 0).click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertEditorClosed(); + } + + @Test + public void testComponentBinding() { + selectMenuPath("Component", "State", "Editor", "Edit item 100"); + + List widgets = getEditorWidgets(); + assertEquals("Number of widgets", GridBasicFeatures.COLUMNS, + widgets.size()); + + assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); + assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); + assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); + assertEquals("100", widgets.get(9).getAttribute("value")); + } + + @Test + public void testSave() { + selectMenuPath("Component", "Editor", "Edit item 100"); + + WebElement textField = getEditorWidgets().get(0); + + textField.click(); + + textField.sendKeys(" changed"); + + WebElement saveButton = getEditor().findElement( + By.className("v-editor-row-save")); + + saveButton.click(); + + assertEquals("(100, 0) changed", getGridElement().getCell(100, 0) + .getText()); + } + + @Test + public void testProgrammaticSave() { + selectMenuPath("Component", "Editor", "Edit item 100"); + + WebElement textField = getEditorWidgets().get(0); + + textField.click(); + + textField.sendKeys(" changed"); + + selectMenuPath("Component", "Editor", "Save"); + + assertEquals("(100, 0) changed", getGridElement().getCell(100, 0) + .getText()); + } + + private void assertEditorOpen() { + assertNotNull("Editor open", getEditor()); + assertEquals("Number of widgets", GridBasicFeatures.COLUMNS, + getEditorWidgets().size()); + } + + private void assertEditorClosed() { + assertNull("Editor closed", getEditor()); + } + + private List getEditorWidgets() { + assertNotNull(getEditor()); + return getEditor().findElements(By.className("v-textfield")); + + } +} 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 71fc47277f..f66347bd2d 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java @@ -46,7 +46,7 @@ import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widget.escalator.FlyweightCell; import com.vaadin.client.widget.grid.CellReference; import com.vaadin.client.widget.grid.CellStyleGenerator; -import com.vaadin.client.widget.grid.EditorRowHandler; +import com.vaadin.client.widget.grid.EditorHandler; import com.vaadin.client.widget.grid.RowReference; import com.vaadin.client.widget.grid.RowStyleGenerator; import com.vaadin.client.widget.grid.datasources.ListDataSource; @@ -92,19 +92,19 @@ public class GridBasicClientFeaturesWidget extends TEXT_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER; } - private class TestEditorRowHandler implements EditorRowHandler> { + private class TestEditorHandler implements EditorHandler> { private Map, TextBox> widgets = new HashMap, TextBox>(); private Label log = new Label(); { - log.addStyleName("editor-row-log"); + log.addStyleName("grid-editor-log"); addSouth(log, 20); } @Override - public void bind(EditorRowRequest> request) { + public void bind(EditorRequest> request) { List rowData = ds.getRow(request.getRowIndex()); boolean hasSelectionColumn = !(grid.getSelectionModel() instanceof None); @@ -117,13 +117,13 @@ public class GridBasicClientFeaturesWidget extends } @Override - public void cancel(EditorRowRequest> request) { + public void cancel(EditorRequest> request) { log.setText("Row " + request.getRowIndex() + " edit cancelled"); request.invokeCallback(); } @Override - public void save(EditorRowRequest> request) { + public void save(EditorRequest> request) { log.setText("Row " + request.getRowIndex() + " edit committed"); List rowData = ds.getRow(request.getRowIndex()); @@ -252,7 +252,7 @@ public class GridBasicClientFeaturesWidget extends grid.setDataSource(ds); grid.addSelectAllHandler(ds.getSelectAllHandler()); grid.setSelectionMode(SelectionMode.NONE); - grid.setEditorRowHandler(new TestEditorRowHandler()); + grid.setEditorHandler(new TestEditorHandler()); sorter = new ListSorter>(grid); @@ -377,7 +377,7 @@ public class GridBasicClientFeaturesWidget extends createColumnsMenu(); createHeaderMenu(); createFooterMenu(); - createEditorRowMenu(); + createEditorMenu(); createInternalsMenu(); createDataSourceMenu(); @@ -906,41 +906,41 @@ public class GridBasicClientFeaturesWidget extends }, menuPath); } - private void createEditorRowMenu() { + private void createEditorMenu() { addMenuCommand("Enabled", new ScheduledCommand() { @Override public void execute() { - grid.setEditorRowEnabled(!grid.isEditorRowEnabled()); + grid.setEditorEnabled(!grid.isEditorEnabled()); } - }, "Component", "Editor row"); + }, "Component", "Editor"); addMenuCommand("Edit row 5", new ScheduledCommand() { @Override public void execute() { grid.editRow(5); } - }, "Component", "Editor row"); + }, "Component", "Editor"); addMenuCommand("Edit row 100", new ScheduledCommand() { @Override public void execute() { grid.editRow(100); } - }, "Component", "Editor row"); + }, "Component", "Editor"); addMenuCommand("Save", new ScheduledCommand() { @Override public void execute() { - grid.saveEditorRow(); + grid.saveEditor(); } - }, "Component", "Editor row"); + }, "Component", "Editor"); addMenuCommand("Cancel edit", new ScheduledCommand() { @Override public void execute() { - grid.cancelEditorRow(); + grid.cancelEditor(); } - }, "Component", "Editor row"); + }, "Component", "Editor"); } -- cgit v1.2.3