diff --git a/P/Sda1/Jpa/Company/companyJpa1/src/main/java/de/hdm_stuttgart/mi/company/ui/HelloUi.java b/P/Sda1/Jpa/Company/companyJpa1/src/main/java/de/hdm_stuttgart/mi/company/ui/HelloUi.java index b4843ea27d1113e47688a18ee4fd29c7e98cba48..3e913ac26cf3406ce65f8f085e129e4627aae822 100644 --- a/P/Sda1/Jpa/Company/companyJpa1/src/main/java/de/hdm_stuttgart/mi/company/ui/HelloUi.java +++ b/P/Sda1/Jpa/Company/companyJpa1/src/main/java/de/hdm_stuttgart/mi/company/ui/HelloUi.java @@ -1,14 +1,22 @@ package de.hdm_stuttgart.mi.company.ui; +import java.util.SortedSet; +import java.util.TreeSet; + import javax.servlet.annotation.WebServlet; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Title; import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.util.ObjectProperty; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinServlet; +import com.vaadin.ui.GridLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; @@ -20,51 +28,67 @@ import com.vaadin.ui.VerticalLayout; @Theme("valo") public class HelloUi extends UI { - private static final long serialVersionUID = -307591917714387247L; - - @Override - protected void init(VaadinRequest request) { - // The root of the component hierarchy - VerticalLayout content = new VerticalLayout(); - content.setSizeFull(); // Use entire window - setContent(content); // Attach to the UI - - // Add some component - content.addComponent(new Label("Hello!")); - - // Layout inside layout - HorizontalLayout hor = new HorizontalLayout(); - hor.setSizeFull(); // Use all available space - -// // Couple of horizontally laid out components -// Tree tree = new Tree("My Tree", -// TreeExample.createTreeContent()); -// hor.addComponent(tree); -// -// Table table = new Table("My Table", -// TableExample.generateContent()); -// table.setSizeFull(); -// hor.addComponent(table); -// hor.setExpandRatio(table, 1); // Expand to fill - - content.addComponent(hor); - content.setExpandRatio(hor, 1); // Expand to fill - - } - - /** Deployed as a Servlet or Portlet. - * - * You can specify additional servlet parameters like the URI and UI - * class name and turn on production mode when you have finished developing the application. - */ - @WebServlet(urlPatterns = "/*") - @VaadinServletConfiguration(ui = HelloUi.class, productionMode = false) - public static class MyUIServlet extends VaadinServlet { - - /** - * - */ - private static final long serialVersionUID = -2771410633323765889L; - } + private static final long serialVersionUID = -307591917714387247L; + + static String convert(final SortedSet<Integer> values) { + if (0 == values.size()) { + return ""; + } else { + final StringBuffer ret = new StringBuffer(values.first().toString()); + final Integer v[] = values.toArray(new Integer[values.size()]); + for (int i = 1; i < v.length; i++) { + ret.append(", " + v[i]); + } + return ret.toString(); + } + } + + final SortedSet<Integer> values = new TreeSet<Integer>(); + + @Override + protected void init(VaadinRequest request) { + + final GridLayout grid = new GridLayout(2, 3); + + setContent(grid); // Attach to the UI + + // Add or remove value + final ObjectProperty<Integer> + addInteger = new ObjectProperty<Integer>(0), + removeInteger = new ObjectProperty<Integer>(0); + + final TextField + addEditor = new TextField(addInteger), + removeEditor = new TextField(removeInteger); + + final Label output = new Label(); + + grid.addComponents( + new Label("Add value:"), addEditor, + new Label("Remove value:"), removeEditor, + new Label("Numbers:"), output); + + addEditor.addValueChangeListener(event -> { + final Integer i = addInteger.getValue(); + if (null != i && values.add(i)) { + output.setValue(convert(values)); + } + }); + + removeEditor.addValueChangeListener(event -> { + final Integer i = removeInteger.getValue(); + if (null != i && values.remove(i)) { + output.setValue(convert(values)); + } + }); + } + /** Deployment description . + * + */ + @WebServlet(urlPatterns = "/*") + @VaadinServletConfiguration(ui = HelloUi.class, productionMode = false) + public static class MyUIServlet extends VaadinServlet { + private static final long serialVersionUID = -2771410633323765889L; + } }