1 package com.vaadin.tests.integration;
3 import com.vaadin.annotations.DesignRoot;
4 import com.vaadin.annotations.Widgetset;
5 import com.vaadin.server.ClassResource;
6 import com.vaadin.server.Resource;
7 import com.vaadin.server.VaadinRequest;
8 import com.vaadin.ui.Grid;
9 import com.vaadin.ui.Image;
10 import com.vaadin.ui.Label;
11 import com.vaadin.ui.UI;
12 import com.vaadin.ui.VerticalLayout;
13 import com.vaadin.ui.declarative.Design;
15 @Widgetset("com.vaadin.DefaultWidgetSet")
16 public class ServletIntegrationUI extends UI {
18 public static class Country {
19 private final String name;
20 private final String id;
21 private final Resource icon;
23 public Country(String name, String id, Resource icon) {
29 public String getName() {
33 public String getId() {
37 public Resource getIcon() {
43 protected void init(VaadinRequest request) {
44 VerticalLayout layout = new VerticalLayout();
45 layout.setMargin(true);
48 final Grid<Country> grid = new Grid<>();
49 // TODO ImageRenderer does not support ClassResource
50 grid.addComponentColumn(country -> new Image(null, country.getIcon()))
51 .setWidth(50).setCaption("");
52 grid.addColumn(country -> country.getName()).setWidth(100)
53 .setCaption("Country");
54 grid.setItems(new Country("Finland", "FI", new ClassResource("fi.gif")),
55 new Country("Sweden", "SE", new FlagSeResource()));
56 grid.setHeight("200px");
57 grid.setWidth("200px");
58 layout.addComponent(grid);
60 final Label selectedLabel = new LabelFromDesign();
61 grid.addSelectionListener(event -> selectedLabel.setValue(
62 event.getFirstSelectedItem().map(c -> c.getId()).orElse("")));
63 layout.addComponent(selectedLabel);
67 public static class LabelFromDesign extends Label {
68 public LabelFromDesign() {