Search in sources :

Example 1 with ValueChangeNotifier

use of com.vaadin.data.Property.ValueChangeNotifier in project VaadinUtils by rlsutton1.

the class CheckboxColumnGenerator method generateCell.

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    // Need a layout to set center alignment on the checkbox.
    // http://dev.vaadin.com/ticket/12027
    final VerticalLayout layout = new VerticalLayout();
    final CheckBox checkbox = new CheckBox();
    layout.addComponent(checkbox);
    layout.setComponentAlignment(checkbox, Alignment.MIDDLE_CENTER);
    @SuppressWarnings("unchecked") final Property<Boolean> property = source.getItem(itemId).getItemProperty(columnId);
    checkbox.setValue(property.getValue());
    checkbox.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            property.setValue((Boolean) event.getProperty().getValue());
        }
    });
    ((ValueChangeNotifier) property).addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            checkbox.setValue((Boolean) event.getProperty().getValue());
        }
    });
    return layout;
}
Also used : ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.data.Property.ValueChangeListener) CheckBox(com.vaadin.ui.CheckBox) VerticalLayout(com.vaadin.ui.VerticalLayout) ValueChangeNotifier(com.vaadin.data.Property.ValueChangeNotifier)

Aggregations

ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)1 ValueChangeListener (com.vaadin.data.Property.ValueChangeListener)1 ValueChangeNotifier (com.vaadin.data.Property.ValueChangeNotifier)1 CheckBox (com.vaadin.ui.CheckBox)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1