Skip to content

Commit

Permalink
Merge pull request #1 from alejandro-du/master
Browse files Browse the repository at this point in the history
merge latest master from alejandro with my changes
  • Loading branch information
frialey63 authored Jun 9, 2022
2 parents cc243a9 + 88d17ed commit 10f8697
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Say, you have the following domain/entity/Java Bean class:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion add-on/src/main/java/org/vaadin/crudui/crud/impl/GridCrud.java
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -335,6 +335,7 @@ protected Button buildCancelButton(ComponentEventListener<ClickEvent<Button>> cl

protected Component buildFooter(CrudOperation operation, T domainObject, ComponentEventListener<ClickEvent<Button>> cancelButtonClickListener, ComponentEventListener<ClickEvent<Button>> operationButtonClickListener) {
Button operationButton = buildOperationButton(operation, domainObject, operationButtonClickListener);
operationButton.addClickShortcut(Key.ENTER);
Button cancelButton = buildCancelButton(cancelButtonClickListener);

HorizontalLayout footerLayout = new HorizontalLayout();
Expand Down

0 comments on commit 10f8697

Please sign in to comment.