You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServletIntegrationUI.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.vaadin.tests.integration;
  2. import com.vaadin.annotations.DesignRoot;
  3. import com.vaadin.annotations.Theme;
  4. import com.vaadin.annotations.Widgetset;
  5. import com.vaadin.data.util.BeanItemContainer;
  6. import com.vaadin.event.SelectionEvent;
  7. import com.vaadin.server.Resource;
  8. import com.vaadin.server.ThemeResource;
  9. import com.vaadin.server.VaadinRequest;
  10. import com.vaadin.ui.*;
  11. import com.vaadin.ui.declarative.Design;
  12. import com.vaadin.ui.renderers.ImageRenderer;
  13. import java.util.Iterator;
  14. @Widgetset("com.vaadin.DefaultWidgetSet")
  15. @Theme("valo")
  16. public class ServletIntegrationUI extends UI {
  17. public static class Country {
  18. private final String name;
  19. private final String id;
  20. private final Resource icon;
  21. public Country(String name, String id, Resource icon) {
  22. this.name = name;
  23. this.id = id;
  24. this.icon = icon;
  25. }
  26. public String getName() {
  27. return name;
  28. }
  29. public String getId() {
  30. return id;
  31. }
  32. public Resource getIcon() {
  33. return icon;
  34. }
  35. }
  36. @Override
  37. protected void init(VaadinRequest request) {
  38. VerticalLayout layout = new VerticalLayout();
  39. layout.setMargin(true);
  40. setContent(layout);
  41. final BeanItemContainer<Country> container = new BeanItemContainer<Country>(Country.class);
  42. final Grid grid = new Grid(container);
  43. // TODO ImageRenderer does not support ClassResource
  44. grid.getColumn("icon").setWidth(50).setHeaderCaption("").setRenderer(new ImageRenderer());
  45. grid.getColumn("name").setWidth(100).setHeaderCaption("Country");
  46. grid.setColumns("icon", "name");
  47. container.addBean(new Country("Finland", "FI", new ThemeResource("fi.gif")));
  48. container.addBean(new Country("Sweden", "SE", new ThemeResource("se.gif")));
  49. grid.setHeight("200px");
  50. grid.setWidth("200px");
  51. layout.addComponent(grid);
  52. final Label selectedLabel = new LabelFromDesign();
  53. grid.addSelectionListener(new SelectionEvent.SelectionListener() {
  54. public void select(SelectionEvent selectionEvent) {
  55. Iterator<Object> iterator = selectionEvent.getSelected().iterator();
  56. if (iterator.hasNext()) {
  57. selectedLabel.setValue(container.getItem(iterator.next()).getBean().getId());
  58. } else {
  59. selectedLabel.setValue("");
  60. }
  61. }
  62. });
  63. layout.addComponent(selectedLabel);
  64. }
  65. @DesignRoot
  66. public static class LabelFromDesign extends Label {
  67. public LabelFromDesign() {
  68. Design.read(this);
  69. }
  70. }
  71. }