]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add item descriptions to Tree (#9840)
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>
Mon, 21 Aug 2017 09:01:32 +0000 (12:01 +0300)
committerAleksi Hietanen <aleksi@vaadin.com>
Mon, 21 Aug 2017 09:01:32 +0000 (12:01 +0300)
Fixes #9803

server/src/main/java/com/vaadin/ui/Tree.java
uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java
uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java

index aeb2dcfb6dfc59c0f4c782f6222575379e3b55dd..77d7d2300aeed71ac0df8508076233ffe7b4512a 100644 (file)
@@ -49,6 +49,7 @@ import com.vaadin.shared.ui.grid.HeightMode;
 import com.vaadin.shared.ui.tree.TreeMultiSelectionModelState;
 import com.vaadin.shared.ui.tree.TreeRendererState;
 import com.vaadin.ui.Grid.SelectionMode;
+import com.vaadin.ui.components.grid.DescriptionGenerator;
 import com.vaadin.ui.components.grid.MultiSelectionModelImpl;
 import com.vaadin.ui.renderers.AbstractRenderer;
 import com.vaadin.util.ReflectTools;
@@ -595,6 +596,20 @@ public class Tree<T> extends Composite
         treeGrid.setStyleGenerator(styleGenerator);
     }
 
+    /**
+     * Sets the description generator that is used for generating tooltip
+     * descriptions for items.
+     * 
+     * @since
+     * @param descriptionGenerator
+     *            the item description generator to set, or <code>null</code> to
+     *            remove a previously set generator
+     */
+    public void setItemDescriptionGenerator(
+            DescriptionGenerator<T> descriptionGenerator) {
+        treeGrid.setDescriptionGenerator(descriptionGenerator);
+    }
+
     /**
      * Gets the item caption generator.
      *
@@ -635,6 +650,16 @@ public class Tree<T> extends Composite
         return treeGrid.getStyleGenerator();
     }
 
+    /**
+     * Gets the item description generator.
+     *
+     * @since
+     * @return the item description generator
+     */
+    public DescriptionGenerator<T> getItemDescriptionGenerator() {
+        return treeGrid.getDescriptionGenerator();
+    }
+
     /**
      * Adds an item click listener. The listener is called when an item of this
      * {@code Tree} is clicked.
index edcb76e1cab8831ec44653b69886d91400b2ce39..b18364ccb845916baf3734d7b5cb6a5fdf71d3a3 100644 (file)
@@ -1,10 +1,7 @@
 package com.vaadin.tests.components.tree;
 
 import java.util.Arrays;
-import java.util.Enumeration;
 import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 import com.vaadin.annotations.Theme;
@@ -76,6 +73,7 @@ public class TreeBasicFeatures extends AbstractTestUIWithLog {
         MenuItem componentMenu = menu.addItem("Component", null);
         createIconMenu(componentMenu.addItem("Icons", null));
         createCaptionMenu(componentMenu.addItem("Captions", null));
+        createDescriptionMenu(componentMenu.addItem("Descriptions", null));
         createContentModeMenu(componentMenu.addItem("ContentMode", null));
         createSelectionModeMenu(componentMenu.addItem("Selection Mode", null));
         createRowHeightMenu(componentMenu.addItem("Row Height", null));
@@ -149,6 +147,15 @@ public class TreeBasicFeatures extends AbstractTestUIWithLog {
         });
     }
 
+    private void createDescriptionMenu(MenuItem descriptionMenu) {
+        descriptionMenu.addItem("No Description", menu -> {
+            tree.setItemDescriptionGenerator(t -> null);
+        });
+        descriptionMenu.addItem("String.valueOf", menu -> {
+            tree.setItemDescriptionGenerator(String::valueOf);
+        });
+    }
+
     private void createContentModeMenu(MenuItem contentModeMenu) {
         Arrays.stream(ContentMode.values()).forEach(mode -> contentModeMenu
                 .addItem(mode.toString(), item -> tree.setContentMode(mode)));
index 4137e11098de179c431a4bb8378027ce42806e9a..34be123ee29b2b5c6225f9f1481c0cc39fbc846c 100644 (file)
@@ -252,4 +252,12 @@ public class TreeBasicFeaturesTest extends MultiBrowserTest {
                             .contains("height: " + height + "px;"));
                 });
     }
+
+    @Test
+    public void tree_item_description() {
+        selectMenuPath("Component", "Descriptions", "String.valueOf");
+
+        $(TreeElement.class).first().getItem(0).showTooltip();
+        Assert.assertEquals("", "0 | 0", getTooltipElement().getText());
+    }
 }