Skip to content

Instantly share code, notes, and snippets.

@KrishnaKotari
Last active August 29, 2015 14:19
Show Gist options
  • Save KrishnaKotari/1306fbf5ef9316c2bc5a to your computer and use it in GitHub Desktop.
Save KrishnaKotari/1306fbf5ef9316c2bc5a to your computer and use it in GitHub Desktop.
All code related to Part 4 of my series on Vaadin Grid
//Sets the grid editor to be enabled
grid.setEditorEnabled(true);
// Setting the field group
grid.setEditorFieldGroup(getFieldGroup());
/**
* @return
*/
private FieldGroup getFieldGroup() {
BeanFieldGroup<VehicleInfo> beanFieldGroup = new BeanFieldGroup<VehicleInfo>(
VehicleInfo.class);
beanFieldGroup.addCommitHandler(new CommitHandler() {
/**
*
*/
private static final long serialVersionUID = 6062316515368687380L;
@Override
public void preCommit(CommitEvent commitEvent)
throws CommitException {
}
@Override
public void postCommit(CommitEvent commitEvent)
throws CommitException {
Notification.show("Saved Successfully!!",
Type.TRAY_NOTIFICATION);
}
});
return beanFieldGroup;
}
//Customizing the editor fields
grid.getColumn("manufacturer").setEditorField(
getComboBox("Manufacturer is required!",
Arrays.asList(Manufacturer.values())));
/**
* @return
*/
private Field<?> getComboBox(String requiredErrorMsg, Collection<?> items) {
ComboBox comboBox = new ComboBox();
comboBox.setNullSelectionAllowed(true);
IndexedContainer container = new IndexedContainer(items);
comboBox.setContainerDataSource(container);
comboBox.setRequired(true);
comboBox.setRequiredError(requiredErrorMsg);
return comboBox;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment