summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-11-17 17:05:28 +0200
committerVaadin Code Review <review@vaadin.com>2016-11-25 13:13:00 +0000
commitd37b2d430eca6b0eeacb48626c0bbfb33d1502de (patch)
treea73527e2b0eef2e902572908c1c6a22d44a2ab27 /client/src
parentd63c1f9014e0a49e5250edd41bd5c7542901c267 (diff)
downloadvaadin-framework-d37b2d430eca6b0eeacb48626c0bbfb33d1502de.tar.gz
vaadin-framework-d37b2d430eca6b0eeacb48626c0bbfb33d1502de.zip
Reintroduce Grid Editor using Binder
This patch restores the bean type to BinderValidationStatusHandler Change-Id: I9ace77a492c4823c15591fb1426e9bd216895fb0
Diffstat (limited to 'client/src')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java5
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java222
-rw-r--r--client/src/main/java/com/vaadin/client/widget/grid/EditorHandler.java19
-rw-r--r--client/src/main/java/com/vaadin/client/widgets/Grid.java5
4 files changed, 246 insertions, 5 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
index c3aa4fe5d2..700a3de575 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java
@@ -132,6 +132,11 @@ public class ColumnConnector extends AbstractExtensionConnector {
column.setExpandRatio(getState().expandRatio);
}
+ @OnStateChange("editable")
+ void updateEditable() {
+ column.setEditable(getState().editable);
+ }
+
@Override
public void onUnregister() {
super.onUnregister();
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
new file mode 100644
index 0000000000..c4bd801022
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2000-2016 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.connectors.grid;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.ConnectorMap;
+import com.vaadin.client.ServerConnector;
+import com.vaadin.client.annotations.OnStateChange;
+import com.vaadin.client.extensions.AbstractExtensionConnector;
+import com.vaadin.client.widget.grid.EditorHandler;
+import com.vaadin.client.widgets.Grid;
+import com.vaadin.client.widgets.Grid.Column;
+import com.vaadin.shared.data.DataCommunicatorConstants;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.grid.editor.EditorClientRpc;
+import com.vaadin.shared.ui.grid.editor.EditorServerRpc;
+import com.vaadin.shared.ui.grid.editor.EditorState;
+import com.vaadin.ui.components.grid.EditorImpl;
+
+import elemental.json.JsonObject;
+
+/**
+ * Connector for Grid Editor.
+ *
+ * @author Vaadin Ltd
+ * @since
+ */
+@Connect(EditorImpl.class)
+public class EditorConnector extends AbstractExtensionConnector {
+
+ /**
+ * EditorHandler for communicating with the server-side implementation.
+ */
+ private class CustomEditorHandler implements EditorHandler<JsonObject> {
+ private EditorServerRpc rpc = getRpcProxy(EditorServerRpc.class);
+ private EditorRequest<JsonObject> currentRequest = null;
+ private boolean serverInitiated = false;
+
+ public CustomEditorHandler() {
+ registerRpc(EditorClientRpc.class, new EditorClientRpc() {
+ @Override
+ public void cancel() {
+ serverInitiated = true;
+ getParent().getWidget().cancelEditor();
+ }
+
+ @Override
+ public void confirmBind(final boolean bindSucceeded) {
+ endRequest(bindSucceeded);
+ }
+
+ @Override
+ public void confirmSave(boolean saveSucceeded) {
+ endRequest(saveSucceeded);
+ }
+
+ @Override
+ public void setErrorMessage(String errorMessage,
+ List<String> errorColumnsIds) {
+ Collection<Column<?, JsonObject>> errorColumns;
+ if (errorColumnsIds != null) {
+ errorColumns = new ArrayList<Grid.Column<?, JsonObject>>();
+ for (String colId : errorColumnsIds) {
+ errorColumns.add(getParent().getColumn(colId));
+ }
+ } else {
+ errorColumns = null;
+ }
+ getParent().getWidget().getEditor()
+ .setEditorError(errorMessage, errorColumns);
+ }
+ });
+ }
+
+ @Override
+ public void bind(EditorRequest<JsonObject> request) {
+ startRequest(request);
+ rpc.bind(getRowKey(request.getRow()));
+ }
+
+ @Override
+ public void save(EditorRequest<JsonObject> request) {
+ startRequest(request);
+ rpc.save();
+ }
+
+ @Override
+ public void cancel(EditorRequest<JsonObject> request) {
+ if (!handleServerInitiated(request)) {
+ // No startRequest as we don't get (or need)
+ // a confirmation from the server
+ rpc.cancel();
+ }
+ }
+
+ @Override
+ public Widget getWidget(Column<?, JsonObject> column) {
+ String connId = getState().columnFields
+ .get(getParent().getColumnId(column));
+ if (connId == null) {
+ return null;
+ }
+ return getConnector(connId).getWidget();
+ }
+
+ private ComponentConnector getConnector(String id) {
+ return (ComponentConnector) ConnectorMap.get(getConnection())
+ .getConnector(id);
+ }
+
+ /**
+ * 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,
+ * the request can be simply synchronously completed.
+ *
+ * @param request
+ * the request object
+ * @return true if the request was originally triggered by the server,
+ * false otherwise
+ */
+ private boolean handleServerInitiated(EditorRequest<?> request) {
+ assert request != null : "Cannot handle null request";
+ assert currentRequest == null : "Earlier request not yet finished";
+
+ if (serverInitiated) {
+ serverInitiated = false;
+ request.success();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private void startRequest(EditorRequest<JsonObject> request) {
+ assert currentRequest == null : "Earlier request not yet finished";
+
+ currentRequest = request;
+ }
+
+ private void endRequest(boolean succeeded) {
+ assert currentRequest != null : "Current request was null";
+ /*
+ * Clear current request first to ensure the state is valid if
+ * another request is made in the callback.
+ */
+ EditorRequest<JsonObject> request = currentRequest;
+ currentRequest = null;
+ if (succeeded) {
+ request.success();
+ } else {
+ request.failure();
+ }
+ }
+ }
+
+ @OnStateChange("buffered")
+ void updateBuffered() {
+ getParent().getWidget().getEditor().setBuffered(getState().buffered);
+ }
+
+ @OnStateChange("enabled")
+ void updateEnabled() {
+ getParent().getWidget().getEditor().setEnabled(getState().enabled);
+ }
+
+ @OnStateChange("saveCaption")
+ void updateSaveCaption() {
+ getParent().getWidget().getEditor()
+ .setSaveCaption(getState().saveCaption);
+ }
+
+ @OnStateChange("cancelCaption")
+ void updateCancelCaption() {
+ getParent().getWidget().getEditor()
+ .setCancelCaption(getState().cancelCaption);
+ }
+
+ @Override
+ protected void extend(ServerConnector target) {
+ Grid<JsonObject> grid = getParent().getWidget();
+ grid.getEditor().setHandler(new CustomEditorHandler());
+ }
+
+ @Override
+ public GridConnector getParent() {
+ return (GridConnector) super.getParent();
+ }
+
+ @Override
+ public EditorState getState() {
+ return (EditorState) super.getState();
+ }
+
+ /**
+ * Returns the key of the given data row.
+ *
+ * @param row
+ * the row
+ * @return the row key
+ */
+ protected static String getRowKey(JsonObject row) {
+ return row.getString(DataCommunicatorConstants.KEY);
+ }
+}
diff --git a/client/src/main/java/com/vaadin/client/widget/grid/EditorHandler.java b/client/src/main/java/com/vaadin/client/widget/grid/EditorHandler.java
index 764a6e5086..97e8cbf297 100644
--- a/client/src/main/java/com/vaadin/client/widget/grid/EditorHandler.java
+++ b/client/src/main/java/com/vaadin/client/widget/grid/EditorHandler.java
@@ -19,6 +19,7 @@ import java.util.Collection;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.widgets.Grid;
+import com.vaadin.client.widgets.Grid.Editor;
/**
* An interface for binding widgets and data to the grid row editor. Used by the
@@ -93,6 +94,15 @@ public interface EditorHandler<T> {
* Informs Grid that an error occurred while trying to process the
* request.
*
+ * @see Editor#setEditorError(String, Collection)
+ */
+ public void failure();
+
+ /**
+ * Informs Grid that an error occurred while trying to process the
+ * request. This method is a short-hand for calling {@link #failure()}
+ * and {@link Editor#setEditorError(String, Collection)}
+ *
* @param errorMessage
* and error message to show to the user, or
* <code>null</code> to not show any message.
@@ -100,9 +110,14 @@ public interface EditorHandler<T> {
* a collection of columns for which an error indicator
* should be shown, or <code>null</code> if no columns should
* be marked as erroneous.
+ *
+ * @see Editor#setEditorError(String, Collection)
*/
- public void failure(String errorMessage,
- Collection<Grid.Column<?, T>> errorColumns);
+ public default void failure(String errorMessage,
+ Collection<Grid.Column<?, T>> errorColumns) {
+ failure();
+ getGrid().getEditor().setEditorError(errorMessage, errorColumns);
+ }
/**
* Checks whether the request is completed or not.
diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java
index e1633fdbd3..0cad901ec2 100644
--- a/client/src/main/java/com/vaadin/client/widgets/Grid.java
+++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java
@@ -1152,9 +1152,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
}
@Override
- public void failure(String errorMessage,
- Collection<Grid.Column<?, T>> errorColumns) {
- complete(errorMessage, errorColumns);
+ public void failure() {
+ complete("", null);
if (callback != null) {
callback.onError(this);
}