aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2017-02-08 15:45:20 +0200
committerIlia Motornyi <elmot@vaadin.com>2017-02-08 15:45:20 +0200
commit32cfd092800685e59b8a7b3862aafd7854f9e939 (patch)
tree5ebe208c7816a3f39b260ca6436cf2d95b9da6db /server/src/main/java/com
parentd0137a9877c735b70a0319f35e6326317f9f5c89 (diff)
downloadvaadin-framework-32cfd092800685e59b8a7b3862aafd7854f9e939.tar.gz
vaadin-framework-32cfd092800685e59b8a7b3862aafd7854f9e939.zip
Provide a convenience method to get items set via setItems().
Fixes #8357
Diffstat (limited to 'server/src/main/java/com')
-rw-r--r--server/src/main/java/com/vaadin/data/HasDataProvider.java7
-rw-r--r--server/src/main/java/com/vaadin/data/HasFilterableDataProvider.java7
-rw-r--r--server/src/main/java/com/vaadin/data/HasItems.java66
-rw-r--r--server/src/main/java/com/vaadin/data/provider/ListDataProvider.java9
4 files changed, 74 insertions, 15 deletions
diff --git a/server/src/main/java/com/vaadin/data/HasDataProvider.java b/server/src/main/java/com/vaadin/data/HasDataProvider.java
index 0dc0fc1c2c..c853f5c092 100644
--- a/server/src/main/java/com/vaadin/data/HasDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/HasDataProvider.java
@@ -37,13 +37,6 @@ import com.vaadin.data.provider.DataProvider;
public interface HasDataProvider<T> extends HasItems<T> {
/**
- * Returns the source of data items used by this listing.
- *
- * @return the data provider, not null
- */
- public DataProvider<T, ?> getDataProvider();
-
- /**
* Sets the data provider for this listing. The data provider is queried for
* displayed items as needed.
*
diff --git a/server/src/main/java/com/vaadin/data/HasFilterableDataProvider.java b/server/src/main/java/com/vaadin/data/HasFilterableDataProvider.java
index 4d2964b2e5..e84349c794 100644
--- a/server/src/main/java/com/vaadin/data/HasFilterableDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/HasFilterableDataProvider.java
@@ -38,13 +38,6 @@ import com.vaadin.server.SerializableFunction;
public interface HasFilterableDataProvider<T, F> extends HasItems<T> {
/**
- * Returns the source of data items used by this listing.
- *
- * @return the data provider, not <code>null</code>
- */
- public DataProvider<T, ?> getDataProvider();
-
- /**
* Sets the data provider for this listing. The data provider is queried for
* displayed items as needed.
*
diff --git a/server/src/main/java/com/vaadin/data/HasItems.java b/server/src/main/java/com/vaadin/data/HasItems.java
index 16ae8a2d25..03e85be6fd 100644
--- a/server/src/main/java/com/vaadin/data/HasItems.java
+++ b/server/src/main/java/com/vaadin/data/HasItems.java
@@ -22,6 +22,8 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.vaadin.data.provider.BackEndDataProvider;
+import com.vaadin.data.provider.DataProvider;
+import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.ui.Component;
/**
@@ -33,9 +35,33 @@ import com.vaadin.ui.Component;
* the type of the displayed item
*/
public interface HasItems<T> extends Component, Serializable {
+
+ /**
+ * Returns the source of data items used by this listing.
+ *
+ * @return the data provider, not null
+ */
+ public DataProvider<T, ?> getDataProvider();
+
/**
* Sets the data items of this component provided as a collection.
* <p>
+ * The provided items are wrapped into a {@link ListDataProvider} and this
+ * instance is used as a data provider for the
+ * {@link #setDataProvider(DataProvider)} method. It means that the items
+ * collection can be accessed later on via
+ * {@link ListDataProvider#getItems()}:
+ *
+ * <pre>
+ * <code>
+ * HasDataProvider<String> listing = new CheckBoxGroup<>();
+ * listing.setItems(Arrays.asList("a","b"));
+ * ...
+ *
+ * Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
+ * </code>
+ * </pre>
+ * <p>
* The provided collection instance may be used as-is. Subsequent
* modification of the collection might cause inconsistent data to be shown
* in the component unless it is explicitly instructed to read the data
@@ -49,7 +75,26 @@ public interface HasItems<T> extends Component, Serializable {
/**
* Sets the data items of this listing.
- *
+ * <p>
+ * The provided items are wrapped into a {@link ListDataProvider} and this
+ * instance is used as a data provider for the
+ * {@link #setDataProvider(DataProvider)} method. It means that the items
+ * collection can be accessed later on via
+ * {@link ListDataProvider#getItems()}:
+ *
+ * <pre>
+ * <code>
+ * HasDataProvider<String> listing = new CheckBoxGroup<>();
+ * listing.setItems(Arrays.asList("a","b"));
+ * ...
+ *
+ * Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
+ * </code>
+ * </pre>
+ * <p>
+ *
+ * @see #setItems(Collection)
+ *
* @param items
* the data items to display
*/
@@ -65,6 +110,25 @@ public interface HasItems<T> extends Component, Serializable {
* instead of its array and Collection variations, doesn't save any memory.
* If you have a large data set to bind, using a lazy data provider is
* recommended. See {@link BackEndDataProvider} for more info.
+ * <p>
+ * The provided items are wrapped into a {@link ListDataProvider} and this
+ * instance is used as a data provider for the
+ * {@link #setDataProvider(DataProvider)} method. It means that the items
+ * collection can be accessed later on via
+ * {@link ListDataProvider#getItems()}:
+ *
+ * <pre>
+ * <code>
+ * HasDataProvider<String> listing = new CheckBoxGroup<>();
+ * listing.setItems(Arrays.asList("a","b"));
+ * ...
+ *
+ * Collection<String> collection = ((ListDataProvider<String>)listing.getDataProvider()).getItems();
+ * </code>
+ * </pre>
+ * <p>
+ *
+ * @see #setItems(Collection)
*
* @param streamOfItems
* the stream of data items to display, not {@code null}
diff --git a/server/src/main/java/com/vaadin/data/provider/ListDataProvider.java b/server/src/main/java/com/vaadin/data/provider/ListDataProvider.java
index b452a16383..039366418a 100644
--- a/server/src/main/java/com/vaadin/data/provider/ListDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/ListDataProvider.java
@@ -72,6 +72,15 @@ public class ListDataProvider<T>
sortOrder = null;
}
+ /**
+ * Returns the underlying data items.
+ *
+ * @return the underlying data items
+ */
+ public Collection<T> getItems() {
+ return backend;
+ }
+
@Override
public Stream<T> fetch(Query<T, SerializablePredicate<T>> query) {
Stream<T> stream = getFilteredStream(query);