summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2016-09-05 19:34:19 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-07 07:19:58 +0000
commitd8562821deedbbce7985a8b02cf14ee604934ac3 (patch)
tree7ecab60499824412e028da37af33c8ba4c4895ce
parent400818bff226f60e37ee30ed3a0ffe7e845dcf67 (diff)
downloadvaadin-framework-d8562821deedbbce7985a8b02cf14ee604934ac3.tar.gz
vaadin-framework-d8562821deedbbce7985a8b02cf14ee604934ac3.zip
Parameterize listing and selection connectors by selection model type
Change-Id: I9c31582242b0b37b8a732e41bc73c59881dcf68b
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java57
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java4
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java23
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/selection/SingleSelectionConnector.java7
-rw-r--r--uitest/src/main/java/com/vaadin/tests/widgetset/client/data/DummyComponentConnector.java10
5 files changed, 77 insertions, 24 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java b/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java
index 938df199da..6593b5a0be 100644
--- a/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java
@@ -18,22 +18,29 @@ package com.vaadin.client.connectors;
import com.vaadin.client.connectors.data.HasDataSource;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.data.DataCommunicatorConstants;
import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.ui.AbstractListing;
import elemental.json.JsonObject;
+import elemental.json.JsonValue;
/**
- * Base connector class for {@link AbstractListing}.
+ * A base connector class for {@link AbstractListing}.
*
- * @since
+ * @author Vaadin Ltd.
+ *
+ * @param <SELECTIONMODEL>
+ * the client-side selection model type
+ *
+ * @since 8.0
*/
-public abstract class AbstractListingConnector
+public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionModel<?>>
extends AbstractComponentConnector implements HasDataSource {
private DataSource<JsonObject> dataSource = null;
- private SelectionModel<JsonObject> selectionModel = null;
+ private SELECTIONMODEL selectionModel = null;
@Override
public void setDataSource(DataSource<JsonObject> dataSource) {
@@ -51,11 +58,49 @@ public abstract class AbstractListingConnector
* @param selectionModel
* the selection model or null to disable
*/
- public void setSelectionModel(SelectionModel<JsonObject> selectionModel) {
+ public void setSelectionModel(SELECTIONMODEL selectionModel) {
this.selectionModel = selectionModel;
}
- public SelectionModel<JsonObject> getSelectionModel() {
+ /**
+ * Returns the selection model instance used.
+ *
+ * @return the selection model
+ */
+ public SELECTIONMODEL getSelectionModel() {
return selectionModel;
}
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Returns the data of the given data row.
+ *
+ * @param row
+ * the row
+ * @return the row data
+ */
+ protected static JsonValue getRowData(JsonObject row) {
+ return row.get(DataCommunicatorConstants.DATA);
+ }
+
+ /**
+ * Returns whether the given row is selected.
+ *
+ * @param row
+ * the row
+ * @return {@code true} if the row is selected, {@code false} otherwise
+ */
+ protected boolean isRowSelected(JsonObject row) {
+ return row.hasKey(DataCommunicatorConstants.SELECTED);
+ }
}
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 31f6cc38ab..91adcc14ac 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
@@ -52,7 +52,8 @@ import elemental.json.JsonObject;
* @since
*/
@Connect(com.vaadin.ui.Grid.class)
-public class GridConnector extends AbstractListingConnector
+public class GridConnector
+ extends AbstractListingConnector<SelectionModel<JsonObject>>
implements HasComponentsConnector, SimpleManagedLayout, DeferredWorker {
/* Map to keep track of all added columns */
@@ -63,6 +64,7 @@ public class GridConnector extends AbstractListingConnector
private ClickSelectHandler<JsonObject> clickSelectHandler;
@Override
+ @SuppressWarnings("unchecked")
public Grid<JsonObject> getWidget() {
return (Grid<JsonObject>) super.getWidget();
}
diff --git a/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java b/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java
index 7edc944a22..9d4604993d 100644
--- a/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/selection/AbstractSelectionConnector.java
@@ -27,15 +27,18 @@ import elemental.json.JsonObject;
* The client-side connector for selection extensions.
*
* @author Vaadin Ltd.
- *
- * @since
+ *
+ * @param <SELECTIONMODEL>
+ * the supported client-side selection model
+ * @since 8.0
*/
-public abstract class AbstractSelectionConnector
+public abstract class AbstractSelectionConnector<SELECTIONMODEL extends SelectionModel<?>>
extends AbstractExtensionConnector {
- private SelectionModel<JsonObject> model = null;
+ private SELECTIONMODEL model = null;
@Override
+ @SuppressWarnings("unchecked")
protected void extend(ServerConnector target) {
if (!(target instanceof AbstractListingConnector)) {
throw new IllegalArgumentException(
@@ -43,7 +46,8 @@ public abstract class AbstractSelectionConnector
+ AbstractListingConnector.class.getSimpleName());
}
model = createSelectionModel();
- ((AbstractListingConnector) target).setSelectionModel(model);
+ ((AbstractListingConnector<SELECTIONMODEL>) target)
+ .setSelectionModel(model);
}
/**
@@ -51,11 +55,12 @@ public abstract class AbstractSelectionConnector
*
* @return created selection model
*/
- protected abstract SelectionModel<JsonObject> createSelectionModel();
+ protected abstract SELECTIONMODEL createSelectionModel();
@Override
- public AbstractListingConnector getParent() {
- return (AbstractListingConnector) super.getParent();
+ @SuppressWarnings("unchecked")
+ public AbstractListingConnector<SELECTIONMODEL> getParent() {
+ return (AbstractListingConnector<SELECTIONMODEL>) super.getParent();
}
/**
@@ -63,7 +68,7 @@ public abstract class AbstractSelectionConnector
*
* @return the selection model in use
*/
- protected SelectionModel<JsonObject> getSelectionModel() {
+ protected SELECTIONMODEL getSelectionModel() {
return model;
}
diff --git a/client/src/main/java/com/vaadin/client/connectors/selection/SingleSelectionConnector.java b/client/src/main/java/com/vaadin/client/connectors/selection/SingleSelectionConnector.java
index 912b20310e..875a70412c 100644
--- a/client/src/main/java/com/vaadin/client/connectors/selection/SingleSelectionConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/selection/SingleSelectionConnector.java
@@ -31,7 +31,8 @@ import elemental.json.JsonObject;
* @author Vaadin Ltd.
*/
@Connect(com.vaadin.data.selection.SingleSelection.class)
-public class SingleSelectionConnector extends AbstractSelectionConnector {
+public class SingleSelectionConnector extends
+ AbstractSelectionConnector<SelectionModel.Single<JsonObject>> {
private static class SingleSelection
implements SelectionModel.Single<JsonObject> {
@@ -68,7 +69,7 @@ public class SingleSelectionConnector extends AbstractSelectionConnector {
}
}
- private AbstractListingConnector parent;
+ private AbstractListingConnector<?> parent;
@Override
public void onUnregister() {
@@ -85,7 +86,7 @@ public class SingleSelectionConnector extends AbstractSelectionConnector {
}
@Override
- protected SelectionModel<JsonObject> createSelectionModel() {
+ protected SingleSelection createSelectionModel() {
return new SingleSelection(getRpcProxy(SelectionServerRpc.class));
}
}
diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/data/DummyComponentConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/data/DummyComponentConnector.java
index 061b52abf5..228f5120e7 100644
--- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/data/DummyComponentConnector.java
+++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/data/DummyComponentConnector.java
@@ -4,14 +4,15 @@ import com.google.gwt.user.client.ui.FlowPanel;
import com.vaadin.client.connectors.AbstractListingConnector;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.VLabel;
-import com.vaadin.shared.data.DataCommunicatorConstants;
+import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.shared.ui.Connect;
import com.vaadin.tests.data.DummyData.DummyComponent;
import elemental.json.JsonObject;
@Connect(DummyComponent.class)
-public class DummyComponentConnector extends AbstractListingConnector {
+public class DummyComponentConnector extends
+ AbstractListingConnector<SelectionModel<?>> {
@Override
public FlowPanel getWidget() {
@@ -30,9 +31,8 @@ public class DummyComponentConnector extends AbstractListingConnector {
VLabel label = new VLabel();
getWidget().add(label);
JsonObject row = dataSource.getRow(i);
- String text = row.getString(DataCommunicatorConstants.DATA);
- if (row.hasKey(DataCommunicatorConstants.SELECTED)
- && row.getBoolean(DataCommunicatorConstants.SELECTED)) {
+ String text = getRowData(row).asString();
+ if (isRowSelected(row)) {
text = "<b>" + text + "</b>";
label.addStyleName("selected");
}