@Test public void test() { Person p1 = new Person(1, "John", LocalDate.of(1990, Month.JANUARY, 2)); Person p2 = new Person(2, "George", LocalDate.of(1991, Month.JUNE, 19)); Person p3 = new Person(3, "Tim", LocalDate.of(1995, Month.APRIL, 7)); List<Person> persons = Arrays.asList(p1, p2, p3); ItemCaptionGenerator<Person> captionGenerator = Person::getName; IconGenerator<Person> iconProvider = person -> VaadinIcons.USER; StyleGenerator<Person> styleGenerator = person -> "test"; FTree<Person> tree = new FTree<Person>().withCaption("My Tree", true) .withContentMode(ContentMode.HTML) .withDescription("description", ContentMode.HTML) .withCollapseListener(event -> System.out.println("collapsed")) .withExpandListener(event -> System.out.println("expanded")) .withAutoRecalculateWidth(false) .withItemCaptionGenerator(captionGenerator) .withItemClickListener(event -> System.out.println("clicked")) .withItemIconGenerator(iconProvider) .withItems(persons) .withItemCollapseAllowedProvider(person -> person.getId() > 1) .withSelectionMode(SelectionMode.MULTI) .withSelectionListener(event -> System.out.println("selected")) .withRowHeight(14) .withStyleGenerator(styleGenerator) .withWidth("50%") .withId("treeId"); assertEquals("My Tree", tree.getCaption()); assertEquals("treeId", tree.getId()); assertEquals("description", tree.getDescription()); assertFalse(tree.isAutoRecalculateWidth()); assertEquals(1, tree.getListeners(CollapseEvent.class).size()); assertEquals(1, tree.getListeners(ExpandEvent.class).size()); assertEquals(1, tree.getListeners(ItemClick.class).size()); assertTrue(tree.getSelectionModel() instanceof MultiSelectionModel); assertEquals(captionGenerator, tree.getItemCaptionGenerator()); assertEquals(iconProvider, tree.getItemIconGenerator()); assertEquals(styleGenerator, tree.getStyleGenerator()); assertEquals(50, tree.getWidth(), 0); assertEquals(Unit.PERCENTAGE, tree.getWidthUnits()); assertTrue(tree.getDataProvider() instanceof HierarchicalDataProvider); }
@Override public void setItemIconGenerator(final IconGenerator<T> itemIconGenerator) { super.setItemIconGenerator(itemIconGenerator); }
/** * Sets the item icon generator that is used to produce custom icons for * items. The generator can return <code>null</code> for items with no icon. * * @see IconGenerator * * @param iconGenerator * the item icon generator to set, not <code>null</code> * @return this for method chaining * @see Tree#setItemIconGenerator(IconGenerator) * @throws NullPointerException * if {@code itemIconGenerator} is {@code null} */ @SuppressWarnings("unchecked") public default THIS withItemIconGenerator(IconGenerator<ITEM> iconGenerator) { ((Tree<ITEM>) this).setItemIconGenerator(iconGenerator); return (THIS) this; }
/** * @see IconGenerator * @see AbstractListing#setItemIconGenerator(IconGenerator) * * @param itemIconGenerator * the item icon generator to set, not null * @return this for method chaining */ @SuppressWarnings("unchecked") public default THIS withItemIconGenerator(IconGenerator<ITEM> itemIconGenerator) { ((ComboBox<ITEM>) this).setItemIconGenerator(itemIconGenerator); return (THIS) this; }
/** * @see IconGenerator * @see AbstractListing#setItemIconGenerator(IconGenerator) * * @param itemIconGenerator * the item icon generator to set, not null * @return this for method chaining */ @SuppressWarnings("unchecked") public default THIS withItemIconGenerator(IconGenerator<VALUE> itemIconGenerator) { ((CheckBoxGroup<VALUE>) this).setItemIconGenerator(itemIconGenerator); return (THIS) this; }
/** * @see IconGenerator * @see RadioButtonGroup#setItemIconGenerator(IconGenerator) * * @param itemIconGenerator * the item icon generator to set, not null * @return this for method chaining */ @SuppressWarnings("unchecked") public default THIS withItemIconGenerator(IconGenerator<ITEM> itemIconGenerator) { ((RadioButtonGroup<ITEM>) this).setItemIconGenerator(itemIconGenerator); return (THIS) this; }