From b623752443cabb5d7e6f4289c6f6129836114cdf Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 27 May 2022 22:04:09 +0100 Subject: [PATCH 1/5] provide ENTER shortcut for operation button on the form --- .../crudui/form/AbstractAutoGeneratedCrudFormFactory.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/add-on/src/main/java/org/vaadin/crudui/form/AbstractAutoGeneratedCrudFormFactory.java b/add-on/src/main/java/org/vaadin/crudui/form/AbstractAutoGeneratedCrudFormFactory.java index c95a853..a9d372e 100644 --- a/add-on/src/main/java/org/vaadin/crudui/form/AbstractAutoGeneratedCrudFormFactory.java +++ b/add-on/src/main/java/org/vaadin/crudui/form/AbstractAutoGeneratedCrudFormFactory.java @@ -317,9 +317,9 @@ public void showError(CrudOperation operation, Exception e) { errorListener.accept(e); } else { if (CrudOperationException.class.isAssignableFrom(e.getClass())) { - Notification.show(e.getMessage()); + Notification.show(e.getMessage()); } else { - Notification.show("Error"); + Notification.show("Error"); throw new RuntimeException("Error executing " + operation.name() + " operation", e); } } @@ -335,6 +335,7 @@ protected Button buildCancelButton(ComponentEventListener> cl protected Component buildFooter(CrudOperation operation, T domainObject, ComponentEventListener> cancelButtonClickListener, ComponentEventListener> operationButtonClickListener) { Button operationButton = buildOperationButton(operation, domainObject, operationButtonClickListener); + operationButton.addClickShortcut(Key.ENTER); Button cancelButton = buildCancelButton(cancelButtonClickListener); HorizontalLayout footerLayout = new HorizontalLayout(); From 9f1455025f720e843e2248bdaeccb5adbad5dd1c Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 27 May 2022 22:05:58 +0100 Subject: [PATCH 2/5] only show success notification if no CrudOperationException; show error messages from CrudOperationException --- .../crudui/crud/impl/AbstractGridCrud.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/add-on/src/main/java/org/vaadin/crudui/crud/impl/AbstractGridCrud.java b/add-on/src/main/java/org/vaadin/crudui/crud/impl/AbstractGridCrud.java index 7aad33a..3579708 100755 --- a/add-on/src/main/java/org/vaadin/crudui/crud/impl/AbstractGridCrud.java +++ b/add-on/src/main/java/org/vaadin/crudui/crud/impl/AbstractGridCrud.java @@ -1,5 +1,14 @@ package org.vaadin.crudui.crud.impl; +import org.vaadin.crudui.crud.AbstractCrud; +import org.vaadin.crudui.crud.CrudListener; +import org.vaadin.crudui.crud.CrudOperation; +import org.vaadin.crudui.crud.CrudOperationException; +import org.vaadin.crudui.form.CrudFormFactory; +import org.vaadin.crudui.form.impl.form.factory.DefaultCrudFormFactory; +import org.vaadin.crudui.layout.CrudLayout; +import org.vaadin.crudui.layout.impl.WindowBasedCrudLayout; + import com.vaadin.flow.component.AttachEvent; import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.Component; @@ -12,14 +21,6 @@ import com.vaadin.flow.data.provider.Query; import com.vaadin.flow.data.provider.hierarchy.HierarchicalDataProvider; import com.vaadin.flow.data.provider.hierarchy.HierarchicalQuery; -import org.vaadin.crudui.crud.AbstractCrud; -import org.vaadin.crudui.crud.CrudListener; -import org.vaadin.crudui.crud.CrudOperation; -import org.vaadin.crudui.crud.CrudOperationException; -import org.vaadin.crudui.form.CrudFormFactory; -import org.vaadin.crudui.form.impl.form.factory.DefaultCrudFormFactory; -import org.vaadin.crudui.layout.CrudLayout; -import org.vaadin.crudui.layout.impl.WindowBasedCrudLayout; /** * @author Alejandro Duarte @@ -172,6 +173,7 @@ protected void addButtonClicked() { T addedObject = addOperation.perform(domainObject); refreshGrid(); grid.asSingleSelect().setValue(addedObject); + showNotification(savedMessage); // TODO: grid.scrollTo(addedObject); } catch (IllegalArgumentException ignore) { } catch (CrudOperationException e1) { @@ -191,10 +193,12 @@ protected void updateButtonClicked() { grid.asSingleSelect().clear(); refreshGrid(); grid.asSingleSelect().setValue(updatedObject); + showNotification(savedMessage); // TODO: grid.scrollTo(updatedObject); } catch (IllegalArgumentException ignore) { } catch (CrudOperationException e1) { refreshGrid(); + showNotification(e1.getMessage()); throw e1; } catch (Exception e2) { refreshGrid(); @@ -210,7 +214,9 @@ protected void deleteButtonClicked() { deleteOperation.perform(domainObject); refreshGrid(); grid.asSingleSelect().clear(); + showNotification(deletedMessage); } catch (CrudOperationException e1) { + showNotification(e1.getMessage()); refreshGrid(); } catch (Exception e2) { refreshGrid(); @@ -234,7 +240,6 @@ protected void showForm(CrudOperation operation, T domainObject, boolean readOnl if (!clickRowToUpdate) { crudLayout.hideForm(); } - showNotification(successMessage); }); String caption = crudFormFactory.buildCaption(operation, domainObject); crudLayout.showForm(operation, form, caption); From 7528fed4abed1ce51584a66e90ea03f70d57f34b Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 27 May 2022 22:07:30 +0100 Subject: [PATCH 3/5] new method on grid to add an Update button column --- .../org/vaadin/crudui/crud/impl/GridCrud.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/add-on/src/main/java/org/vaadin/crudui/crud/impl/GridCrud.java b/add-on/src/main/java/org/vaadin/crudui/crud/impl/GridCrud.java index ebff00d..48d1c79 100755 --- a/add-on/src/main/java/org/vaadin/crudui/crud/impl/GridCrud.java +++ b/add-on/src/main/java/org/vaadin/crudui/crud/impl/GridCrud.java @@ -1,12 +1,16 @@ package org.vaadin.crudui.crud.impl; -import com.vaadin.flow.component.grid.Grid; import java.util.Collection; + import org.vaadin.crudui.crud.CrudListener; import org.vaadin.crudui.crud.LazyFindAllCrudOperationListener; import org.vaadin.crudui.form.CrudFormFactory; import org.vaadin.crudui.layout.CrudLayout; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.grid.Grid; +import com.vaadin.flow.component.icon.VaadinIcon; + /** * @author Alejandro Duarte */ @@ -53,4 +57,16 @@ public void refreshGrid() { } } + public void addUpdateButtonColumn() { + grid.addComponentColumn(item -> { + Button button = new Button(VaadinIcon.PENCIL.create()); + button.addClickListener(e -> { + grid.select(item); + updateButtonClicked(); + }); + + return button; + }); + } + } \ No newline at end of file From 0c0c43740c99a6c164ad2827456d836200ede7b9 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 30 May 2022 17:39:44 +0100 Subject: [PATCH 4/5] updated readme with patch info for this fork --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index c0a79a3..7bace81 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,18 @@ The API is defined through 4 interfaces: The add-on includes several implementations of these interfaces. +# Enhancements in this fork + +There is one minor fix in this forked version: + +- Only show success notification if no CrudOperationException encountered; show error messages from CrudOperationException when relevant + +There are two minor enhancements in this forked version: + +- Provide ENTER shortcut for operation button on the form + +- New method on grid to add an optional Update button column + # Basic usage Say, you have the following domain/entity/Java Bean class: From ba644f640a267b808eca7aede397cff8eb97c5e3 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 30 May 2022 17:41:37 +0100 Subject: [PATCH 5/5] updated readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7bace81..4fcfd59 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ The add-on includes several implementations of these interfaces. There is one minor fix in this forked version: -- Only show success notification if no CrudOperationException encountered; show error messages from CrudOperationException when relevant +- Only show success notification if no CrudOperationException encountered -There are two minor enhancements in this forked version: +There are three minor enhancements in this forked version: +- Show error messages from CrudOperationException when relevant - Provide ENTER shortcut for operation button on the form - - New method on grid to add an optional Update button column # Basic usage