]> source.dussan.org Git - vaadin-framework.git/blob
0d4010beaa31b69416a9b6c2ac036df6fb95bcfa
[vaadin-framework.git] /
1 package com.vaadin.tests.integration;
2
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;
14
15 @Widgetset("com.vaadin.DefaultWidgetSet")
16 public class ServletIntegrationUI extends UI {
17
18     public static class Country {
19         private final String name;
20         private final String id;
21         private final Resource icon;
22
23         public Country(String name, String id, Resource icon) {
24             this.name = name;
25             this.id = id;
26             this.icon = icon;
27         }
28
29         public String getName() {
30             return name;
31         }
32
33         public String getId() {
34             return id;
35         }
36
37         public Resource getIcon() {
38             return icon;
39         }
40     }
41
42     @Override
43     protected void init(VaadinRequest request) {
44         VerticalLayout layout = new VerticalLayout();
45         layout.setMargin(true);
46         setContent(layout);
47
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);
59
60         final Label selectedLabel = new LabelFromDesign();
61         grid.addSelectionListener(event -> selectedLabel.setValue(
62                 event.getFirstSelectedItem().map(c -> c.getId()).orElse("")));
63         layout.addComponent(selectedLabel);
64     }
65
66     @DesignRoot
67     public static class LabelFromDesign extends Label {
68         public LabelFromDesign() {
69             Design.read(this);
70         }
71     }
72 }