summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2016-09-05 12:20:36 +0300
committerLeif Åstrand <leif@vaadin.com>2016-09-06 15:07:07 +0300
commit3d3f12d92bb840a66ed6caaf992e0fe7bb3c1e77 (patch)
treed6b4f92365dff685f0576580fb7b0a9e10ec3fe7 /client
parentfbb55ac4fdf09103cf7e999b321812bea033a981 (diff)
downloadvaadin-framework-3d3f12d92bb840a66ed6caaf992e0fe7bb3c1e77.tar.gz
vaadin-framework-3d3f12d92bb840a66ed6caaf992e0fe7bb3c1e77.zip
Reimplement basic Grid renderers
Change-Id: Ic855143d23cc7735d00130806df45b6579ba0d5c
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java39
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/ColumnConnector.java28
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/DateRendererConnector.java33
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/NumberRendererConnector.java34
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/ProgressBarRendererConnector.java35
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/TextRendererConnector.java35
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/UnsafeHtmlRendererConnector.java43
7 files changed, 241 insertions, 6 deletions
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
new file mode 100644
index 0000000000..96bfc3b26d
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/AbstractGridRendererConnector.java
@@ -0,0 +1,39 @@
+/*
+ * 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 com.vaadin.client.connectors.AbstractRendererConnector;
+
+/**
+ * An abstract base class for renderer connectors. A renderer connector is used
+ * to link a client-side {@link Renderer} to a server-side
+ * {@link com.vaadin.client.renderers.Renderer Renderer}. As a connector, it can
+ * use the regular Vaadin RPC and shared state mechanism to pass additional
+ * state and information between the client and the server. This base class
+ * itself only uses the basic {@link com.vaadin.shared.communication.SharedState
+ * SharedState} and no RPC interfaces.
+ *
+ * @param <T>
+ * the presentation type of the renderer
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public abstract class AbstractGridRendererConnector<T>
+ extends AbstractRendererConnector<T> {
+ // getRowKey and getColumnId will be needed here later on
+}
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 4b61b62dc7..49bd492406 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
@@ -17,6 +17,7 @@ package com.vaadin.client.connectors.grid;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.annotations.OnStateChange;
+import com.vaadin.client.connectors.AbstractRendererConnector;
import com.vaadin.client.extensions.AbstractExtensionConnector;
import com.vaadin.client.widgets.Grid.Column;
import com.vaadin.shared.data.DataCommunicatorConstants;
@@ -35,7 +36,7 @@ import elemental.json.JsonValue;
@Connect(com.vaadin.ui.Grid.Column.class)
public class ColumnConnector extends AbstractExtensionConnector {
- private Column<JsonValue, JsonObject> column;
+ private Column<Object, JsonObject> column;
/* This parent is needed because it's no longer available in onUnregister */
private GridConnector parent;
@@ -43,15 +44,30 @@ public class ColumnConnector extends AbstractExtensionConnector {
@Override
protected void extend(ServerConnector target) {
parent = getParent();
- column = new Column<JsonValue, JsonObject>() {
+ String columnId = getState().id;
+ column = new Column<Object, JsonObject>() {
@Override
- public JsonValue getValue(JsonObject row) {
- return row.getObject(DataCommunicatorConstants.DATA)
- .get(getState().id);
+ public Object getValue(JsonObject row) {
+ final JsonObject rowData = row
+ .getObject(DataCommunicatorConstants.DATA);
+
+ if (rowData.hasKey(columnId)) {
+ final JsonValue columnValue = rowData.get(columnId);
+
+ return getRendererConnector().decode(columnValue);
+ }
+
+ return null;
}
};
- getParent().addColumn(column, getState().id);
+ column.setRenderer(getRendererConnector().getRenderer());
+ getParent().addColumn(column, columnId);
+ }
+
+ @SuppressWarnings("unchecked")
+ private AbstractRendererConnector<Object> getRendererConnector() {
+ return (AbstractRendererConnector<Object>) getState().renderer;
}
@OnStateChange("caption")
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/DateRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/DateRendererConnector.java
new file mode 100644
index 0000000000..da22c77548
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/DateRendererConnector.java
@@ -0,0 +1,33 @@
+/*
+ * 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 com.vaadin.shared.ui.Connect;
+
+/**
+ * A connector for {@link com.vaadin.ui.renderers.DateRenderer DateRenderer}.
+ * <p>
+ * The server-side Renderer operates on dates, but the data is serialized as a
+ * string, and displayed as-is on the client side. This is to be able to support
+ * the server's locale.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.DateRenderer.class)
+public class DateRendererConnector extends TextRendererConnector {
+ // No implementation needed
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/NumberRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/NumberRendererConnector.java
new file mode 100644
index 0000000000..dd5d4fae40
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/NumberRendererConnector.java
@@ -0,0 +1,34 @@
+/*
+ * 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 com.vaadin.shared.ui.Connect;
+
+/**
+ * A connector for {@link com.vaadin.ui.renderers.NumberRenderer
+ * NumberRenderer}.
+ * <p>
+ * The server-side Renderer operates on numbers, but the data is serialized as a
+ * string, and displayed as-is on the client side. This is to be able to support
+ * the server's locale.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.NumberRenderer.class)
+public class NumberRendererConnector extends TextRendererConnector {
+ // no implementation needed
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/ProgressBarRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/ProgressBarRendererConnector.java
new file mode 100644
index 0000000000..a5f6bec479
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/ProgressBarRendererConnector.java
@@ -0,0 +1,35 @@
+/*
+ * 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 com.vaadin.client.renderers.ProgressBarRenderer;
+import com.vaadin.shared.ui.Connect;
+
+/**
+ * A connector for {@link ProgressBarRenderer}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.ProgressBarRenderer.class)
+public class ProgressBarRendererConnector
+ extends AbstractGridRendererConnector<Double> {
+
+ @Override
+ public ProgressBarRenderer getRenderer() {
+ return (ProgressBarRenderer) super.getRenderer();
+ }
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/TextRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/TextRendererConnector.java
new file mode 100644
index 0000000000..4a368a975d
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/TextRendererConnector.java
@@ -0,0 +1,35 @@
+/*
+ * 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 com.vaadin.client.renderers.TextRenderer;
+import com.vaadin.shared.ui.Connect;
+
+/**
+ * A connector for {@link TextRenderer}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.TextRenderer.class)
+public class TextRendererConnector
+ extends AbstractGridRendererConnector<String> {
+
+ @Override
+ public TextRenderer getRenderer() {
+ return (TextRenderer) super.getRenderer();
+ }
+}
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/UnsafeHtmlRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/UnsafeHtmlRendererConnector.java
new file mode 100644
index 0000000000..42c9a64bd4
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/UnsafeHtmlRendererConnector.java
@@ -0,0 +1,43 @@
+/*
+ * 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 com.vaadin.client.renderers.Renderer;
+import com.vaadin.client.widget.grid.RendererCellReference;
+import com.vaadin.shared.ui.Connect;
+
+/**
+ * A connector for {@link UnsafeHtmlRenderer}
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.renderers.HtmlRenderer.class)
+public class UnsafeHtmlRendererConnector
+ extends AbstractGridRendererConnector<String> {
+
+ public static class UnsafeHtmlRenderer implements Renderer<String> {
+ @Override
+ public void render(RendererCellReference cell, String data) {
+ cell.getElement().setInnerHTML(data);
+ }
+ }
+
+ @Override
+ public UnsafeHtmlRenderer getRenderer() {
+ return (UnsafeHtmlRenderer) super.getRenderer();
+ }
+}