use of org.vaadin.example.bookstore.backend.data.Category in project bookstore-example by vaadin.
the class MockDataGenerator method createCategory.
private static Category createCategory(String name) {
Category c = new Category();
c.setId(nextCategoryId++);
c.setName(name);
return c;
}
use of org.vaadin.example.bookstore.backend.data.Category in project bookstore-example by vaadin.
the class MockDataGenerator method createCategories.
static List<Category> createCategories() {
List<Category> categories = new ArrayList<Category>();
for (String name : categoryNames) {
Category c = createCategory(name);
categories.add(c);
}
return categories;
}
use of org.vaadin.example.bookstore.backend.data.Category in project bookstore-example by vaadin.
the class AdminView method createCategoryEditor.
private Component createCategoryEditor(Category category) {
final TextField nameField = new TextField();
if (category.getId() < 0) {
nameField.focus();
}
final Button deleteButton = new Button(VaadinIcon.MINUS_CIRCLE_O.create(), event -> {
// Ask for confirmation before deleting stuff
final ConfirmDialog dialog = new ConfirmDialog("Please confirm", "Are you sure you want to delete the category? Books in this category will not be deleted.", "Delete", () -> {
DataService.get().deleteCategory(category.getId());
dataProvider.getItems().remove(category);
dataProvider.refreshAll();
Notification.show("Category Deleted.");
});
dialog.open();
});
deleteButton.addThemeVariants(ButtonVariant.LUMO_ERROR);
final BeanValidationBinder<Category> binder = new BeanValidationBinder<>(Category.class);
binder.forField(nameField).bind("name");
binder.setBean(category);
binder.addValueChangeListener(event -> {
if (binder.isValid()) {
DataService.get().updateCategory(category);
deleteButton.setEnabled(true);
newCategoryButton.setEnabled(true);
Notification.show("Category Saved.");
}
});
deleteButton.setEnabled(category.getId() > 0);
final HorizontalLayout layout = new HorizontalLayout(nameField, deleteButton);
layout.setFlexGrow(1);
return layout;
}
Aggregations