aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-06-15 15:04:58 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2016-06-15 17:42:03 +0300
commitfa1ae150f0a0de39e31a424eeb426abca6f46fa6 (patch)
treeb95a3216e8d568f6fc0e215ded2e6799e1d75712
parentc9bd00f902274a00eba371a6ae5907d6a1812b35 (diff)
downloadvaadin-framework-fa1ae150f0a0de39e31a424eeb426abca6f46fa6.tar.gz
vaadin-framework-fa1ae150f0a0de39e31a424eeb426abca6f46fa6.zip
Introduce Listing and SelectionModel
Change-Id: Ied323b4874c3abe57e745a842c30580b50389243
-rw-r--r--server/src/main/java/com/vaadin/server/communication/data/typed/SelectionModel.java93
-rw-r--r--server/src/main/java/com/vaadin/ui/components/Listing.java60
2 files changed, 153 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/server/communication/data/typed/SelectionModel.java b/server/src/main/java/com/vaadin/server/communication/data/typed/SelectionModel.java
new file mode 100644
index 0000000000..3b45a5a5f3
--- /dev/null
+++ b/server/src/main/java/com/vaadin/server/communication/data/typed/SelectionModel.java
@@ -0,0 +1,93 @@
+/*
+ * 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.server.communication.data.typed;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import com.vaadin.event.handler.Handler;
+import com.vaadin.event.handler.Registration;
+import com.vaadin.ui.components.HasValue;
+
+/**
+ * Generic selection model interface.
+ *
+ * @since
+ * @param <T>
+ * type of selected values
+ */
+public interface SelectionModel<T> extends Serializable {
+
+ /**
+ * Selection model for selection a single value.
+ *
+ * @param <T>
+ * type of selected values
+ */
+ public interface Single<T> extends SelectionModel<T>, HasValue<T> {
+ }
+
+ /**
+ * Selection model for selection multiple values.
+ *
+ * @param <T>
+ * type of selected values
+ */
+ public interface Multi<T> extends SelectionModel<T>,
+ HasValue<Collection<T>> {
+ }
+
+ /**
+ * Get current selection.
+ *
+ * @return selection
+ */
+ Collection<T> getSelected();
+
+ /**
+ * Dummy selection model.
+ *
+ * @param <T>
+ * selected data type
+ */
+ public static class NullSelectionModel<T> implements
+ SelectionModel.Single<T> {
+
+ @Override
+ public void setValue(T value) {
+ // NO-OP
+ }
+
+ @Override
+ public T getValue() {
+ return null;
+ }
+
+ @Override
+ public Registration onChange(Handler<T> onChange) {
+ return () -> {
+ // NO-OP
+ };
+ }
+
+ @Override
+ public List<T> getSelected() {
+ return Collections.emptyList();
+ }
+ }
+}
diff --git a/server/src/main/java/com/vaadin/ui/components/Listing.java b/server/src/main/java/com/vaadin/ui/components/Listing.java
new file mode 100644
index 0000000000..47310c3bc6
--- /dev/null
+++ b/server/src/main/java/com/vaadin/ui/components/Listing.java
@@ -0,0 +1,60 @@
+/*
+ * 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.ui.components;
+
+import java.io.Serializable;
+
+import com.vaadin.server.communication.data.typed.DataSource;
+import com.vaadin.server.communication.data.typed.SelectionModel;
+
+/**
+ * Generic interface for Components that show a list of data.
+ *
+ * @param <T>
+ * data type for listing
+ */
+public interface Listing<T> extends Serializable {
+
+ /**
+ * Sets the {@link DataSource} used by this Listing.
+ *
+ * @param data
+ * data source
+ */
+ void setDataSource(DataSource<T> data);
+
+ /**
+ * Returns the {@link DataSource} of this Listing.
+ *
+ * @return data source
+ */
+ DataSource<T> getDataSource();
+
+ /**
+ * Gets the {@link SelectionModel} for this Listing.
+ *
+ * @return selection model
+ */
+ SelectionModel<T> getSelectionModel();
+
+ /**
+ * Sets the {@link SelectionModel} for this Listing.
+ *
+ * @param model
+ * selection model
+ */
+ void setSelectionModel(SelectionModel<T> model);
+}