Java 类com.vaadin.ui.ItemCaptionGenerator 实例源码

项目:dungeonstory-java    文件:LanguageSelector.java   
@Override
    public void updateMessageStrings() {
        Messages messages = Messages.getInstance();
        //        setValue(getLocale());
//        setItemCaption(Locale.ENGLISH, messages.getMessage("languageSelector.en"));
//        setItemCaption(Locale.FRENCH, messages.getMessage("languageSelector.fr"));
        setItemCaptionGenerator(new ItemCaptionGenerator<Locale>() {
            private static final long serialVersionUID = -1634395306396320788L;

            @Override
            public String apply(Locale option) {
                if (option == Locale.CANADA_FRENCH) {
                    return messages.getMessage("languageSelector.fr");
                } else if (option == Locale.ENGLISH) {
                    return messages.getMessage("languageSelector.en");
                }
                return "";
            }
        });
    }
项目:demo-spring-vaadin    文件:CityComboboxView.java   
@PostConstruct
void init() {
    // get cities inside germany
    List<City> cities = cityRepository.findByCountryOrderByNameAsc("DE");

    // create combobox
    ComboBox<City> combobox = new ComboBox<City>("Select a City");
    combobox.setItems(cities);
    combobox.setWidth("200px");
    combobox.setItemCaptionGenerator(new ItemCaptionGenerator<City>() {

        private static final long serialVersionUID = -5328245622581583103L;

        @Override
        public String apply(City item) {
            return item.getName();
        }
    }); 

    // select listener
    combobox.addSelectionListener(new SingleSelectionListener<City>() {

        private static final long serialVersionUID = -5456043484862675591L;

        @Override
        public void selectionChange(SingleSelectionEvent<City> event) {
            LOG.info("City <"+event.getSelectedItem().toString()+"> selected.");

        }
    });

    addComponent(combobox);
}
项目:viritin    文件:LocaleSelect.java   
public LocaleSelect() {
    setItemCaptionGenerator(new ItemCaptionGenerator<Locale>() {
        @Override
        public String apply(Locale option) {
            return option.getDisplayName(option);
        }
    });
}
项目:vaadin-fluent-api    文件:FluentAbstractMultiSelect.java   
@SuppressWarnings("unchecked")
public default THIS withItemCaptionGenerator(ItemCaptionGenerator<VALUE> itemCaptionGenerator) {
    ((AbstractMultiSelect<VALUE>) this).setItemCaptionGenerator(itemCaptionGenerator);
    return (THIS) this;
}
项目:vaadin-fluent-api    文件:FTreeTest.java   
@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);
}
项目:dungeonstory-java    文件:SubSetSelector.java   
public void setCaptionGenerator(ItemCaptionGenerator<ET> cg) {
    cb.setItemCaptionGenerator(cg);
}
项目:dungeonstory-java    文件:SubSetSelectorDraggable.java   
public void setCaptionGenerator(ItemCaptionGenerator<ET> cg) {
    itemCaptionGenerator = cg;
}
项目:dungeonstory-java    文件:SubSetSelectorDraggable.java   
public void setDescriptionGenerator(ItemCaptionGenerator<ET> cg) {
    descriptionGenerator = cg;
}
项目:viritin    文件:EnumSelect.java   
public EnumSelect<T> withItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator) {
    setItemCaptionGenerator(itemCaptionGenerator);
    return this;
}
项目:vaadin-fluent-api    文件:FluentTree.java   
/**
 * Sets the item caption generator that is used to produce the strings shown
 * as the text for each item. By default, {@link String#valueOf(Object)} is
 * used.
 *
 * @param captionGenerator
 *            the item caption provider to use, not <code>null</code>
 *            
 * @return this for method chaining
 * @see Tree#setItemCaptionGenerator(ItemCaptionGenerator)
 */
@SuppressWarnings("unchecked")
public default THIS withItemCaptionGenerator(ItemCaptionGenerator<ITEM> captionGenerator) {
    ((Tree<ITEM>) this).setItemCaptionGenerator(captionGenerator);
    return (THIS) this;
}
项目:vaadin-fluent-api    文件:FluentNativeSelect.java   
/**
 * Sets the item caption generator that is used to produce the strings shown
 * in the combo box for each item. By default,
 * {@link String#valueOf(Object)} is used.
 *
 * @param itemCaptionGenerator
 *            the item caption provider to use, not null
 * @return this for method chaining
 * @see NativeSelect#setItemCaptionGenerator(ItemCaptionGenerator)
 */
@SuppressWarnings("unchecked")
public default THIS withItemCaptionGenerator(ItemCaptionGenerator<ITEM> itemCaptionGenerator) {
    ((NativeSelect<ITEM>) this).setItemCaptionGenerator(itemCaptionGenerator);
    return (THIS) this;
}
项目:vaadin-fluent-api    文件:FluentComboBox.java   
/**
 * Sets the item caption generator that is used to produce the strings shown
 * in the combo box for each item. By default,
 * {@link String#valueOf(Object)} is used.
 *
 * @param itemCaptionGenerator
 *            the item caption provider to use, not null
 * @return this for method chaining
 * @see ComboBox#setItemCaptionGenerator(ItemCaptionGenerator)
 */
@SuppressWarnings("unchecked")
public default THIS withItemCaptionGenerator(ItemCaptionGenerator<ITEM> itemCaptionGenerator) {
    ((ComboBox<ITEM>) this).setItemCaptionGenerator(itemCaptionGenerator);
    return (THIS) this;
}
项目:vaadin-fluent-api    文件:FluentRadioButtonGroup.java   
/**
 * Sets the item caption generator that is used to produce the strings shown
 * in the radio button group for each item. By default,
 * {@link String#valueOf(Object)} is used.
 *
 * @param itemCaptionGenerator
 *            the item caption provider to use, not null
 * @return this for method chaining
 * @see RadioButtonGroup#setItemCaptionGenerator(ItemCaptionGenerator)
 */
@SuppressWarnings("unchecked")
public default THIS withItemCaptionGenerator(ItemCaptionGenerator<ITEM> itemCaptionGenerator) {
    ((RadioButtonGroup<ITEM>) this).setItemCaptionGenerator(itemCaptionGenerator);
    return (THIS) this;
}
项目:dungeonstory-java    文件:LabelField.java   
/**
 * Sets the ItemCaptionGenerator for creating the label value.
 *
 * @param captionGenerator the caption generator used to format the
 * displayed property
 */
public void setCaptionGenerator(ItemCaptionGenerator<T> captionGenerator) {
    this.captionGenerator = captionGenerator;
    updateLabel();
}