Search in sources :

Example 1 with Category

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;
}
Also used : Category(org.vaadin.example.bookstore.backend.data.Category)

Example 2 with Category

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;
}
Also used : Category(org.vaadin.example.bookstore.backend.data.Category) ArrayList(java.util.ArrayList)

Example 3 with Category

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;
}
Also used : Category(org.vaadin.example.bookstore.backend.data.Category) Button(com.vaadin.flow.component.button.Button) TextField(com.vaadin.flow.component.textfield.TextField) BeanValidationBinder(com.vaadin.flow.data.binder.BeanValidationBinder) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Aggregations

Category (org.vaadin.example.bookstore.backend.data.Category)3 Button (com.vaadin.flow.component.button.Button)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 TextField (com.vaadin.flow.component.textfield.TextField)1 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)1 ArrayList (java.util.ArrayList)1