|
|
@@ -5,49 +5,61 @@ import com.vaadin.annotations.Widgetset; |
|
|
|
import com.vaadin.server.ClassResource; |
|
|
|
import com.vaadin.server.Resource; |
|
|
|
import com.vaadin.server.VaadinRequest; |
|
|
|
import com.vaadin.ui.Grid; |
|
|
|
import com.vaadin.ui.Image; |
|
|
|
import com.vaadin.ui.Label; |
|
|
|
import com.vaadin.ui.UI; |
|
|
|
import com.vaadin.ui.VerticalLayout; |
|
|
|
import com.vaadin.ui.declarative.Design; |
|
|
|
import com.vaadin.v7.data.Item; |
|
|
|
import com.vaadin.v7.data.Property.ValueChangeEvent; |
|
|
|
import com.vaadin.v7.data.Property.ValueChangeListener; |
|
|
|
import com.vaadin.v7.ui.Table; |
|
|
|
|
|
|
|
@Widgetset("com.vaadin.v7.Vaadin7WidgetSet") |
|
|
|
@Widgetset("com.vaadin.DefaultWidgetSet") |
|
|
|
public class ServletIntegrationUI extends UI { |
|
|
|
|
|
|
|
public static class Country { |
|
|
|
private final String name; |
|
|
|
private final String id; |
|
|
|
private final Resource icon; |
|
|
|
|
|
|
|
public Country(String name, String id, Resource icon) { |
|
|
|
this.name = name; |
|
|
|
this.id = id; |
|
|
|
this.icon = icon; |
|
|
|
} |
|
|
|
|
|
|
|
public String getName() { |
|
|
|
return name; |
|
|
|
} |
|
|
|
|
|
|
|
public String getId() { |
|
|
|
return id; |
|
|
|
} |
|
|
|
|
|
|
|
public Resource getIcon() { |
|
|
|
return icon; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void init(VaadinRequest request) { |
|
|
|
VerticalLayout layout = new VerticalLayout(); |
|
|
|
layout.setMargin(true); |
|
|
|
setContent(layout); |
|
|
|
|
|
|
|
final Table table = new Table(); |
|
|
|
table.addContainerProperty("icon", Resource.class, null); |
|
|
|
table.setItemIconPropertyId("icon"); |
|
|
|
table.addContainerProperty("country", String.class, null); |
|
|
|
table.setRowHeaderMode(Table.RowHeaderMode.ICON_ONLY); |
|
|
|
table.setImmediate(true); |
|
|
|
table.setSelectable(true); |
|
|
|
table.setVisibleColumns(new Object[] { "country" }); |
|
|
|
layout.addComponent(table); |
|
|
|
table.setWidth("112px"); |
|
|
|
|
|
|
|
Item item = table.addItem("FI"); |
|
|
|
item.getItemProperty("icon").setValue(new ClassResource("fi.gif")); |
|
|
|
item.getItemProperty("country").setValue("Finland"); |
|
|
|
item = table.addItem("SE"); |
|
|
|
item.getItemProperty("icon").setValue(new FlagSeResource()); |
|
|
|
item.getItemProperty("country").setValue("Sweden"); |
|
|
|
final Grid<Country> grid = new Grid<>(); |
|
|
|
// TODO ImageRenderer does not support ClassResource |
|
|
|
grid.addComponentColumn(country -> new Image(null, country.getIcon())) |
|
|
|
.setWidth(50).setCaption(""); |
|
|
|
grid.addColumn(country -> country.getName()).setWidth(100) |
|
|
|
.setCaption("Country"); |
|
|
|
grid.setItems(new Country("Finland", "FI", new ClassResource("fi.gif")), |
|
|
|
new Country("Sweden", "SE", new FlagSeResource())); |
|
|
|
grid.setHeight("200px"); |
|
|
|
grid.setWidth("200px"); |
|
|
|
layout.addComponent(grid); |
|
|
|
|
|
|
|
final Label selectedLabel = new LabelFromDesign(); |
|
|
|
table.addValueChangeListener(new ValueChangeListener() { |
|
|
|
@Override |
|
|
|
public void valueChange(ValueChangeEvent event) { |
|
|
|
selectedLabel.setValue(String.valueOf(table.getValue())); |
|
|
|
} |
|
|
|
}); |
|
|
|
grid.addSelectionListener(event -> selectedLabel.setValue( |
|
|
|
event.getFirstSelectedItem().map(c -> c.getId()).orElse(""))); |
|
|
|
layout.addComponent(selectedLabel); |
|
|
|
} |
|
|
|
|