List of usage examples for com.vaadin.ui Slider Slider
public Slider(int min, int max)
From source file:org.vaadin.miki.widgets.ItemGridUI.java
License:Apache License
@SuppressWarnings("unchecked") @Override//ww w.j ava 2 s .co m protected void init(VaadinRequest request) { this.primary.addContainerProperty("text", String.class, ""); this.primary.addContainerProperty("number", Integer.class, 0); this.primary.addContainerProperty("bool", Boolean.class, false); for (int zmp1 = 0; zmp1 < 15; zmp1++) { Item item = this.primary.addItem(zmp1); item.getItemProperty("text").setValue("number " + zmp1); item.getItemProperty("number").setValue(zmp1 * 3); item.getItemProperty("bool").setValue((zmp1 % 3) == 1); } this.secondary.addContainerProperty("caption", String.class, "default"); this.secondary.addContainerProperty("price", Double.class, 1.99); for (int zmp1 = 5; zmp1 < 60; zmp1 += 3) { Item item = this.secondary.addItem(zmp1); item.getItemProperty("caption").setValue("this is item with id " + zmp1); item.getItemProperty("price").setValue(1.0 / zmp1); } final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); this.setContent(layout); final ItemGrid grid = new ItemGrid(); grid.setContainerDataSource(this.primary); grid.setItemComponentGenerator(this.generator); layout.addComponent(grid); Slider slider = new Slider(1, 20); slider.setCaption("Select number of columns:"); slider.setValue(new Double(grid.getColumnCount())); slider.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140509; @Override public void valueChange(Property.ValueChangeEvent event) { Object number = event.getProperty().getValue(); if (number != null) grid.setColumnCount((int) Math.round((Double) number)); } }); slider.setSizeFull(); layout.addComponent(slider); CheckBox selectable = new CheckBox("Selectable?", grid.isSelectable()); selectable.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140510; @Override public void valueChange(Property.ValueChangeEvent event) { grid.setSelectable((Boolean) event.getProperty().getValue()); } }); layout.addComponent(selectable); CheckBox nullSelection = new CheckBox("Null selection allowed?", grid.isNullSelectionAllowed()); nullSelection.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140512; @Override public void valueChange(Property.ValueChangeEvent event) { grid.setNullSelectionAllowed((Boolean) event.getProperty().getValue()); } }); layout.addComponent(nullSelection); CheckBox multiSelection = new CheckBox("Multiple selection allowed?", grid.isMultiSelect()); multiSelection.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140512; @Override public void valueChange(Property.ValueChangeEvent event) { grid.setMultiSelect((Boolean) event.getProperty().getValue()); } }); layout.addComponent(multiSelection); CheckBox defaultGenerator = new CheckBox("Use ItemGrid's default component generator?"); defaultGenerator.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140513; @Override public void valueChange(Property.ValueChangeEvent event) { if ((Boolean) event.getProperty().getValue()) grid.setItemComponentGenerator(null); else grid.setItemComponentGenerator(ItemGridUI.this.generator); } }); layout.addComponent(defaultGenerator); ListSelect container = new ListSelect("Container data source", Arrays.asList(this.primary, this.secondary)); container.setNullSelectionAllowed(false); container.setItemCaption(this.primary, "Primary container"); container.setItemCaption(this.secondary, "Backup container"); container.select(this.primary); container.setImmediate(true); container.addValueChangeListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 20140514; @Override public void valueChange(ValueChangeEvent event) { grid.setContainerDataSource((Container) event.getProperty().getValue()); } }); layout.addComponent(container); Button addItem = new Button("Add item to current container", new Button.ClickListener() { private static final long serialVersionUID = 20140515; @Override public void buttonClick(ClickEvent event) { grid.getContainerDataSource().addItem(grid.getContainerDataSource().size() + 0.5); } }); layout.addComponent(addItem); }