summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2016-09-06 11:25:50 +0300
committerAleksi Hietanen <aleksi@vaadin.com>2016-09-09 09:46:37 +0000
commit33809f43cd30f19c87c11db4bf8e9710aeac297e (patch)
treebc87705cc23fdc429d914ffcfec45aee9f6c01ee /client
parentdfe23f7385d8f8737747b8646299adddaaa57c8d (diff)
downloadvaadin-framework-33809f43cd30f19c87c11db4bf8e9710aeac297e.tar.gz
vaadin-framework-33809f43cd30f19c87c11db4bf8e9710aeac297e.zip
Migrate ClickableRenderer and subclasses
Change-Id: I233250d9b68052825b73bed0288fffeaf5bdd04b
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/ButtonRendererConnector.java45
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/ClickableRendererConnector.java63
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/ImageRendererConnector.java57
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java44
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java13
5 files changed, 220 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/ButtonRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/ButtonRendererConnector.java
new file mode 100644
index 0000000000..fad8918c92
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/ButtonRendererConnector.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import com.google.web.bindery.event.shared.HandlerRegistration;
+import com.vaadin.client.renderers.ButtonRenderer;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.shared.ui.Connect;
+
+import elemental.json.JsonObject;
+
+/**
+ * A connector for {@link ButtonRenderer}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.ButtonRenderer.class)
+public class ButtonRendererConnector
+ extends ClickableRendererConnector<String> {
+
+ @Override
+ public ButtonRenderer getRenderer() {
+ return (ButtonRenderer) super.getRenderer();
+ }
+
+ @Override
+ protected HandlerRegistration addClickHandler(
+ RendererClickHandler<JsonObject> handler) {
+ return getRenderer().addClickHandler(handler);
+ }
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/ClickableRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/ClickableRendererConnector.java
new file mode 100644
index 0000000000..f6f6607683
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/ClickableRendererConnector.java
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+import com.google.web.bindery.event.shared.HandlerRegistration;
+import com.vaadin.client.MouseEventDetailsBuilder;
+import com.vaadin.client.connectors.grid.AbstractGridRendererConnector;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickEvent;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.shared.ui.grid.renderers.RendererClickRpc;
+
+import elemental.json.JsonObject;
+
+/**
+ * An abstract base class for {@link ClickableRenderer} connectors.
+ *
+ * @param <T>
+ * the presentation type of the renderer
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public abstract class ClickableRendererConnector<T>
+ extends AbstractGridRendererConnector<T> {
+
+ private HandlerRegistration clickRegistration;
+
+ @Override
+ protected void init() {
+ clickRegistration = addClickHandler(
+ new RendererClickHandler<JsonObject>() {
+ @Override
+ public void onClick(RendererClickEvent<JsonObject> event) {
+ getRpcProxy(RendererClickRpc.class).click(
+ getRowKey(event.getCell().getRow()),
+ getColumnId(event.getCell().getColumn()),
+ MouseEventDetailsBuilder.buildMouseEventDetails(
+ event.getNativeEvent()));
+ }
+ });
+ }
+
+ @Override
+ public void onUnregister() {
+ clickRegistration.removeHandler();
+ }
+
+ protected abstract HandlerRegistration addClickHandler(
+ RendererClickHandler<JsonObject> handler);
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/ImageRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/ImageRendererConnector.java
new file mode 100644
index 0000000000..7949eeab3c
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/ImageRendererConnector.java
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import com.google.web.bindery.event.shared.HandlerRegistration;
+import com.vaadin.client.communication.JsonDecoder;
+import com.vaadin.client.metadata.TypeDataStore;
+import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
+import com.vaadin.client.renderers.ImageRenderer;
+import com.vaadin.shared.communication.URLReference;
+import com.vaadin.shared.ui.Connect;
+
+import elemental.json.JsonObject;
+import elemental.json.JsonValue;
+
+/**
+ * A connector for {@link ImageRenderer}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.ImageRenderer.class)
+public class ImageRendererConnector extends ClickableRendererConnector<String> {
+
+ @Override
+ public ImageRenderer getRenderer() {
+ return (ImageRenderer) super.getRenderer();
+ }
+
+ @Override
+ public String decode(JsonValue value) {
+ URLReference reference = (URLReference) JsonDecoder.decodeValue(
+ TypeDataStore.getType(URLReference.class), value, null,
+ getConnection());
+
+ return reference != null ? reference.getURL() : null;
+ }
+
+ @Override
+ protected HandlerRegistration addClickHandler(
+ RendererClickHandler<JsonObject> handler) {
+ return getRenderer().addClickHandler(handler);
+ }
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java
index 96bfc3b26d..e448c5f2fe 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java
@@ -16,7 +16,12 @@
package com.vaadin.client.connectors.grid;
+import com.vaadin.client.ServerConnector;
import com.vaadin.client.connectors.AbstractRendererConnector;
+import com.vaadin.client.widgets.Grid.Column;
+import com.vaadin.shared.data.DataCommunicatorConstants;
+
+import elemental.json.JsonObject;
/**
* An abstract base class for renderer connectors. A renderer connector is used
@@ -35,5 +40,42 @@ import com.vaadin.client.connectors.AbstractRendererConnector;
*/
public abstract class AbstractGridRendererConnector<T>
extends AbstractRendererConnector<T> {
- // getRowKey and getColumnId will be needed here later on
+
+ /**
+ * Gets the row key for a row object.
+ * <p>
+ * In case this renderer wants be able to identify a row in such a way that
+ * the server also understands it, the row key is used for that. Rows are
+ * identified by unified keys between the client and the server.
+ *
+ * @param row
+ * the row object
+ * @return the row key for the given row
+ */
+ protected String getRowKey(JsonObject row) {
+ return row.getString(DataCommunicatorConstants.KEY);
+ }
+
+ /**
+ * Gets the column id for a column.
+ * <p>
+ * In case this renderer wants be able to identify a column in such a way
+ * that the server also understands it, the column id is used for that.
+ * Columns are identified by unified ids between the client and the server.
+ *
+ * @param column
+ * the column object
+ * @return the column id for the given column
+ */
+ protected String getColumnId(Column<?, JsonObject> column) {
+ final ServerConnector parent = getParent();
+ if (parent instanceof ColumnConnector) {
+ final ServerConnector parentGrid = parent.getParent();
+ if (parentGrid instanceof GridConnector) {
+ return ((GridConnector) parentGrid).getColumnId(column);
+ }
+ }
+ throw new IllegalStateException(
+ "Renderers can only be used with a Grid.");
+ }
}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
index 006aa65318..43be3f0623 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java
@@ -66,6 +66,17 @@ public class GridConnector
private SpaceSelectHandler<JsonObject> spaceSelectHandler;
private ClickSelectHandler<JsonObject> clickSelectHandler;
+ /**
+ * Gets the string identifier of a {@link Column} in this grid.
+ *
+ * @param column
+ * the column for which the identifier is to be retrieved for
+ * @return the string identifying the given column in this grid
+ */
+ public String getColumnId(Grid.Column<?, ?> column) {
+ return columnToIdMap.get(column);
+ }
+
@Override
@SuppressWarnings("unchecked")
public Grid<JsonObject> getWidget() {
@@ -216,7 +227,7 @@ public class GridConnector
@Override
public void setChildComponents(List<ComponentConnector> children) {
- this.childComponents = children;
+ childComponents = children;
}