]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add ItemCollapseAllowedProvider interface
authorAleksi Hietanen <aleksi@vaadin.com>
Mon, 15 May 2017 10:49:56 +0000 (13:49 +0300)
committerHenri Sara <henri.sara@gmail.com>
Tue, 16 May 2017 12:35:17 +0000 (15:35 +0300)
server/src/main/java/com/vaadin/data/provider/HierarchicalDataCommunicator.java
server/src/main/java/com/vaadin/ui/ItemCollapseAllowedProvider.java [new file with mode: 0644]
server/src/main/java/com/vaadin/ui/Tree.java
server/src/main/java/com/vaadin/ui/TreeGrid.java
uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeatures.java

index df2a11c20014a6a96b16f5775e4897437fbddb07..ce6f7db13e2226d82ed6961e9c3c1f08f5a0b6cc 100644 (file)
@@ -31,10 +31,10 @@ import com.vaadin.data.TreeData;
 import com.vaadin.data.provider.HierarchyMapper.TreeLevelQuery;
 import com.vaadin.data.provider.HierarchyMapper.TreeNode;
 import com.vaadin.server.SerializableConsumer;
-import com.vaadin.server.SerializablePredicate;
 import com.vaadin.shared.Range;
 import com.vaadin.shared.data.HierarchicalDataCommunicatorConstants;
 import com.vaadin.shared.extension.datacommunicator.HierarchicalDataCommunicatorState;
+import com.vaadin.ui.ItemCollapseAllowedProvider;
 
 import elemental.json.Json;
 import elemental.json.JsonArray;
@@ -66,7 +66,7 @@ public class HierarchicalDataCommunicator<T> extends DataCommunicator<T> {
     /**
      * Collapse allowed provider used to allow/disallow collapsing nodes.
      */
-    private SerializablePredicate<T> itemCollapseAllowedProvider = t -> true;
+    private ItemCollapseAllowedProvider<T> itemCollapseAllowedProvider = t -> true;
 
     /**
      * The captured client side cache size.
@@ -521,7 +521,7 @@ public class HierarchicalDataCommunicator<T> extends DataCommunicator<T> {
      *            the item collapse allowed provider, not {@code null}
      */
     public void setItemCollapseAllowedProvider(
-            SerializablePredicate<T> provider) {
+            ItemCollapseAllowedProvider<T> provider) {
         Objects.requireNonNull(provider, "Provider can't be null");
         itemCollapseAllowedProvider = provider;
 
diff --git a/server/src/main/java/com/vaadin/ui/ItemCollapseAllowedProvider.java b/server/src/main/java/com/vaadin/ui/ItemCollapseAllowedProvider.java
new file mode 100644 (file)
index 0000000..2ec0ad2
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.ui;
+
+import com.vaadin.server.SerializablePredicate;
+
+/**
+ * A callback interface for resolving whether client-side collapsing should be
+ * allowed for an item in a listing component that displays hierarchical data,
+ * such as {@link TreeGrid}.
+ *
+ * @author Vaadin Ltd
+ * @since 8.1
+ *
+ * @see TreeGrid#setItemCollapseAllowedProvider(ItemCollapseAllowedProvider)
+ *
+ * @param <T>
+ *            item data type
+ */
+@FunctionalInterface
+public interface ItemCollapseAllowedProvider<T> extends SerializablePredicate<T> {
+
+    /**
+     * Returns whether collapsing is allowed for the given item.
+     *
+     * @param item
+     *            the item to test
+     * @return {@code true} if collapse is allowed for the given item,
+     *         {@code false} otherwise
+     */
+    @Override
+    boolean test(T item);
+}
index 9f30c010db947c566f7f3fe463466874cbfcebff..7b8fae59ca404eed06fadc949312877a483bdba1 100644 (file)
@@ -470,7 +470,7 @@ public class Tree<T> extends Composite
      *            the item collapse allowed provider, not {@code null}
      */
     public void setItemCollapseAllowedProvider(
-            SerializablePredicate<T> provider) {
+            ItemCollapseAllowedProvider<T> provider) {
         treeGrid.setItemCollapseAllowedProvider(provider);
     }
 
index f24e5ca9ecf8026abb0b707190a96dd743cd0e6f..54e8e10a6c994f282e526d75c5baa835887d1123 100644 (file)
@@ -43,7 +43,6 @@ import com.vaadin.event.CollapseEvent;
 import com.vaadin.event.CollapseEvent.CollapseListener;
 import com.vaadin.event.ExpandEvent;
 import com.vaadin.event.ExpandEvent.ExpandListener;
-import com.vaadin.server.SerializablePredicate;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.ui.treegrid.FocusParentRpc;
 import com.vaadin.shared.ui.treegrid.FocusRpc;
@@ -324,10 +323,10 @@ public class TreeGrid<T> extends Grid<T>
      * @param provider
      *            the item collapse allowed provider, not {@code null}
      *
-     * @see HierarchicalDataCommunicator#setItemCollapseAllowedProvider(SerializablePredicate)
+     * @see HierarchicalDataCommunicator#setItemCollapseAllowedProvider(ItemCollapseAllowedProvider)
      */
     public void setItemCollapseAllowedProvider(
-            SerializablePredicate<T> provider) {
+            ItemCollapseAllowedProvider<T> provider) {
         getDataCommunicator().setItemCollapseAllowedProvider(provider);
     }
 
index 13064c4c3991eb0abb624c952874e7d2c6de0538..911c13f449ae2c8555ae4ad646b5fa341e074bac 100644 (file)
@@ -17,6 +17,7 @@ import com.vaadin.server.SerializablePredicate;
 import com.vaadin.shared.Range;
 import com.vaadin.tests.components.AbstractComponentTest;
 import com.vaadin.tests.data.bean.HierarchicalTestBean;
+import com.vaadin.ui.ItemCollapseAllowedProvider;
 import com.vaadin.ui.TreeGrid;
 
 @Theme("valo")
@@ -137,7 +138,7 @@ public class TreeGridBasicFeatures extends AbstractComponentTest<TreeGrid> {
     }
 
     private void createCollapseAllowedSelect() {
-        LinkedHashMap<String, SerializablePredicate<HierarchicalTestBean>> options = new LinkedHashMap<>();
+        LinkedHashMap<String, ItemCollapseAllowedProvider<HierarchicalTestBean>> options = new LinkedHashMap<>();
         options.put("all allowed", t -> true);
         options.put("all disabled", t -> false);
         options.put("depth 0 disabled", t -> t.getDepth() != 0);