diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-08-21 12:01:32 +0300 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2017-08-21 12:01:32 +0300 |
commit | 5ef925daa91b1253f170f244e2a992f4f92979e1 (patch) | |
tree | d45284ba338b71140bf1be522c8782fb16c9aca9 | |
parent | 554f39ad0455623fbb1befc4444e67c809de5c0a (diff) | |
download | vaadin-framework-5ef925daa91b1253f170f244e2a992f4f92979e1.tar.gz vaadin-framework-5ef925daa91b1253f170f244e2a992f4f92979e1.zip |
Add item descriptions to Tree (#9840)
Fixes #9803
3 files changed, 43 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Tree.java b/server/src/main/java/com/vaadin/ui/Tree.java index aeb2dcfb6d..77d7d2300a 100644 --- a/server/src/main/java/com/vaadin/ui/Tree.java +++ b/server/src/main/java/com/vaadin/ui/Tree.java @@ -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; @@ -596,6 +597,20 @@ public class Tree<T> extends Composite } /** + * 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. * * @return the item caption generator @@ -636,6 +651,16 @@ public class Tree<T> extends Composite } /** + * 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. * diff --git a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java index edcb76e1ca..b18364ccb8 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java +++ b/uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java @@ -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))); diff --git a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java index 4137e11098..34be123ee2 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java @@ -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()); + } } |