Skip to content
Snippets Groups Projects
Commit 9933509e authored by Goik Martin's avatar Goik Martin
Browse files

Working integer list example

parent e7d5c455
No related branches found
No related tags found
No related merge requests found
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment