Search in sources :

Example 1 with BeanItem

use of com.vaadin.data.util.BeanItem in project opennms by OpenNMS.

the class NameEditForm method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent changeEvent) {
    if (parameter != null) {
        try {
            blockListenerOrValidators = true;
            setData(changeEvent.getSelectedBean());
            setItemId(changeEvent.getSelectedItemId());
            final BeanItem beanItem = new BeanItem(changeEvent.getSelectedBean(), parameter.getEditablePropertyName(), parameter.getNonEditablePropertyName());
            // this is a hack, but we need to know if the selection changed
            beanItem.addItemProperty("selected", changeEvent.getSelectedItem().getItemProperty("selected"));
            captionLabel.setValue(String.format("<b>%s</b>", parameter.getCaption()));
            fieldGroup = new FieldGroup();
            fieldGroup.setBuffered(false);
            fieldGroup.bind(selectedField, "selected");
            fieldGroup.bind(editableField, parameter.getEditablePropertyName());
            fieldGroup.bind(nonEditableField, parameter.getNonEditablePropertyName());
            fieldGroup.setItemDataSource(beanItem);
            fieldGroup.getField(parameter.getNonEditablePropertyName()).setCaption(parameter.getNonEditablePropertyCaption());
            fieldGroup.getField(parameter.getNonEditablePropertyName()).setReadOnly(true);
            fieldGroup.getField(parameter.getEditablePropertyName()).setCaption(parameter.getEditablePropertyCaption());
            fieldGroup.getField(parameter.getEditablePropertyName()).setReadOnly(false);
            updateEnabledState();
            UIHelper.validateField(editableField, true);
        } finally {
            blockListenerOrValidators = false;
        }
    }
}
Also used : FieldGroup(com.vaadin.data.fieldgroup.FieldGroup) BeanItem(com.vaadin.data.util.BeanItem)

Aggregations

FieldGroup (com.vaadin.data.fieldgroup.FieldGroup)1 BeanItem (com.vaadin.data.util.BeanItem)1