diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-06-20 12:59:14 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-06-20 12:59:14 +0300 |
commit | f700c01e12ea5be80d88587a2720a03187922f2c (patch) | |
tree | e6e1cdd58cfe034769e29cdc85abc70dd1746331 /uitest | |
parent | 086170faf858062d2d85fca7fade901a6070c2c2 (diff) | |
download | vaadin-framework-f700c01e12ea5be80d88587a2720a03187922f2c.tar.gz vaadin-framework-f700c01e12ea5be80d88587a2720a03187922f2c.zip |
Enable row height and content mode settings for Tree (#9540)
* Enable row height setting for Tree
* Add content mode for captions
* Align expander element by default to top
The content mode allows use of preformatted and
HTML captions that bring value to row height
Fixes #9411
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/tree/TreeBasicFeatures.java | 44 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/tree/TreeBasicFeaturesTest.java | 63 |
2 files changed, 92 insertions, 15 deletions
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 9f69f3d760..edcb76e1ca 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,7 +1,11 @@ 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; import com.vaadin.annotations.Widgetset; @@ -12,21 +16,24 @@ import com.vaadin.server.ClassResource; import com.vaadin.server.ThemeResource; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.Registration; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.tests.data.bean.HierarchicalTestBean; import com.vaadin.ui.Component; +import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.IconGenerator; import com.vaadin.ui.MenuBar; import com.vaadin.ui.MenuBar.Command; import com.vaadin.ui.MenuBar.MenuItem; import com.vaadin.ui.Tree; import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Grid.SelectionMode; @Theme("tests-valo-disabled-animations") @Widgetset("com.vaadin.DefaultWidgetSet") public class TreeBasicFeatures extends AbstractTestUIWithLog { + public static final double[] ROW_HEIGHTS = new double[] { 35.5d, 72.78d }; + private Tree<HierarchicalTestBean> tree; private TreeDataProvider<HierarchicalTestBean> inMemoryDataProvider; private IconGenerator<HierarchicalTestBean> iconGenerator = i -> { @@ -69,7 +76,9 @@ public class TreeBasicFeatures extends AbstractTestUIWithLog { MenuItem componentMenu = menu.addItem("Component", null); createIconMenu(componentMenu.addItem("Icons", null)); createCaptionMenu(componentMenu.addItem("Captions", null)); + createContentModeMenu(componentMenu.addItem("ContentMode", null)); createSelectionModeMenu(componentMenu.addItem("Selection Mode", null)); + createRowHeightMenu(componentMenu.addItem("Row Height", null)); componentMenu.addItem("Item Click Listener", new Command() { private Registration registration; @@ -110,6 +119,12 @@ public class TreeBasicFeatures extends AbstractTestUIWithLog { return menu; } + private void createRowHeightMenu(MenuItem rowHeightMenu) { + Stream.concat(Stream.of(-1d), Arrays.stream(ROW_HEIGHTS).boxed()) + .forEach(height -> rowHeightMenu.addItem(String.valueOf(height), + item -> tree.setRowHeight(height))); + } + private void createSelectionModeMenu(MenuItem modeMenu) { for (SelectionMode mode : SelectionMode.values()) { modeMenu.addItem(mode.name(), item -> tree.setSelectionMode(mode)); @@ -117,13 +132,26 @@ public class TreeBasicFeatures extends AbstractTestUIWithLog { } private void createCaptionMenu(MenuItem captionMenu) { - captionMenu.addItem("String.valueOf", - menu -> tree.setItemCaptionGenerator(String::valueOf)); - captionMenu - .addItem("Custom caption", - menu -> tree.setItemCaptionGenerator(i -> "Id: " - + i.getId() + ", Depth: " + i.getDepth() - + ", Index: " + i.getIndex())); + captionMenu.addItem("String.valueOf", menu -> { + tree.setItemCaptionGenerator(String::valueOf); + tree.setContentMode(ContentMode.TEXT); + }); + captionMenu.addItem("Custom caption", menu -> { + tree.setItemCaptionGenerator(i -> "Id: " + i.getId() + "\nDepth: " + + i.getDepth() + ", Index: " + i.getIndex()); + tree.setContentMode(ContentMode.PREFORMATTED); + }); + captionMenu.addItem("HTML caption", menu -> { + tree.setItemCaptionGenerator( + i -> "Id: " + i.getId() + "<br/>Depth: " + i.getDepth() + + "<br/>Index: " + i.getIndex()); + tree.setContentMode(ContentMode.HTML); + }); + } + + private void createContentModeMenu(MenuItem contentModeMenu) { + Arrays.stream(ContentMode.values()).forEach(mode -> contentModeMenu + .addItem(mode.toString(), item -> tree.setContentMode(mode))); } private void createIconMenu(MenuItem iconMenu) { 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 d65523d6ec..4137e11098 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 @@ -1,6 +1,7 @@ package com.vaadin.tests.components.tree; import java.io.IOException; +import java.util.Arrays; import java.util.function.Predicate; import org.junit.Assert; @@ -92,7 +93,8 @@ public class TreeBasicFeaturesTest extends MultiBrowserTest { for (int j = 0; j < 3; ++j) { item = tree.getItem(n++); - Assert.assertEquals((shouldHaveIcon ? "\ue92d" : "") + "1 | " + j, + Assert.assertEquals( + (shouldHaveIcon ? "\ue92d" : "") + "1 | " + j, item.getText()); Assert.assertEquals("Unexpected icon state", shouldHaveIcon, @@ -111,27 +113,62 @@ public class TreeBasicFeaturesTest extends MultiBrowserTest { @Test public void tree_custom_caption() { + // Set row height big enough to show whole content. + selectMenuPath("Component", "Row Height", + String.valueOf(TreeBasicFeatures.ROW_HEIGHTS[1])); + selectMenuPath("Component", "Captions", "Custom caption"); TreeElement tree = $(TreeElement.class).first(); - Assert.assertEquals("Id: /0/0, Depth: 0, Index: 0", + Assert.assertEquals("Id: /0/0\nDepth: 0, Index: 0", tree.getItem(0).getText()); - Assert.assertEquals("Id: /0/1, Depth: 0, Index: 1", + Assert.assertEquals("Id: /0/1\nDepth: 0, Index: 1", tree.getItem(1).getText()); tree.expand(0); - Assert.assertEquals("Id: /0/0/1/0, Depth: 1, Index: 0", + Assert.assertEquals("Id: /0/0/1/0\nDepth: 1, Index: 0", tree.getItem(1).getText()); - Assert.assertEquals("Id: /0/0/1/1, Depth: 1, Index: 1", + Assert.assertEquals("Id: /0/0/1/1\nDepth: 1, Index: 1", tree.getItem(2).getText()); tree.expand(1); - Assert.assertEquals("Id: /0/0/1/0/2/0, Depth: 2, Index: 0", + Assert.assertEquals("Id: /0/0/1/0/2/0\nDepth: 2, Index: 0", tree.getItem(2).getText()); - Assert.assertEquals("Id: /0/0/1/0/2/1, Depth: 2, Index: 1", + Assert.assertEquals("Id: /0/0/1/0/2/1\nDepth: 2, Index: 1", tree.getItem(3).getText()); assertNoErrorNotifications(); } @Test + public void tree_html_caption_and_expander_position() { + // Set row height big enough to show whole content. + selectMenuPath("Component", "Row Height", + String.valueOf(TreeBasicFeatures.ROW_HEIGHTS[1])); + + selectMenuPath("Component", "Captions", "HTML caption"); + TreeElement tree = $(TreeElement.class).first(); + Assert.assertEquals("Id: /0/0\nDepth: 0\nIndex: 0", + tree.getItem(0).getText()); + + Assert.assertEquals("Expander element not aligned to top", + tree.getExpandElement(0).getLocation().getY(), + tree.getItem(0).getLocation().getY()); + + assertNoErrorNotifications(); + } + + @Test + public void tree_html_caption_text_mode() { + // Set row height big enough to show whole content. + selectMenuPath("Component", "Captions", "HTML caption"); + selectMenuPath("Component", "ContentMode", "TEXT"); + + TreeElement tree = $(TreeElement.class).first(); + Assert.assertEquals("Id: /0/0<br/>Depth: 0<br/>Index: 0", + tree.getItem(0).getText()); + + assertNoErrorNotifications(); + } + + @Test public void tree_item_click() { selectMenuPath("Component", "Item Click Listener"); $(TreeElement.class).first().getItem(1).click(); @@ -203,4 +240,16 @@ public class TreeBasicFeaturesTest extends MultiBrowserTest { Assert.assertFalse("First row was not deselected", wrap.getRow(0).isSelected()); } + + @Test + public void tree_row_heigth() { + TreeElement tree = $(TreeElement.class).first(); + TreeGridElement wrap = tree.wrap(TreeGridElement.class); + Arrays.stream(TreeBasicFeatures.ROW_HEIGHTS).boxed() + .map(String::valueOf).forEach(height -> { + selectMenuPath("Component", "Row Height", height); + Assert.assertTrue(wrap.getCell(0, 0).getAttribute("style") + .contains("height: " + height + "px;")); + }); + } } |