diff --git a/enhanced-grid-flow-demo/pom.xml b/enhanced-grid-flow-demo/pom.xml index f43bef3..d3f5497 100644 --- a/enhanced-grid-flow-demo/pom.xml +++ b/enhanced-grid-flow-demo/pom.xml @@ -6,7 +6,7 @@ com.vaadin.componentfactory enhanced-grid-flow-demo - 4.0.2-SNAPSHOT + 24.5.0-SNAPSHOT Enhanced Grid Demo war @@ -18,7 +18,7 @@ - 24.0.0 + 24.5.6 17 17 UTF-8 @@ -140,7 +140,7 @@ org.eclipse.jetty jetty-maven-plugin - 11.0.14 + 11.0.22 -1 ${project.artifactId} diff --git a/enhanced-grid-flow/pom.xml b/enhanced-grid-flow/pom.xml index 48a2b68..c4a00db 100644 --- a/enhanced-grid-flow/pom.xml +++ b/enhanced-grid-flow/pom.xml @@ -6,7 +6,7 @@ com.vaadin.componentfactory enhanced-grid-flow - 4.0.2-SNAPSHOT + 24.5.0-SNAPSHOT jar Enhanced Grid @@ -19,7 +19,7 @@ - 24.0.0 + 24.5.6 17 17 UTF-8 @@ -101,11 +101,6 @@ - - com.vaadin.componentfactory - popup - 4.0.0 - diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java index e6c6560..bd340d6 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java @@ -32,7 +32,6 @@ import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.grid.Grid.Column; import com.vaadin.flow.component.grid.SortOrderProvider; -import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.icon.Icon; import com.vaadin.flow.data.renderer.Renderer; @@ -76,10 +75,10 @@ public EnhancedColumn(EnhancedGrid grid, String columnId, Renderer rendere public EnhancedColumn setHeader(String labelText, HasValueAndElement filter) { if(filter != null) { - Component headerComponent = new Span(); - headerComponent.getElement().setText(labelText); - addFilterButtonToHeader(headerComponent, filter); - return setHeader(headerComponent); + Component component = new Span(); + component.getElement().setText(labelText); + addFilterButtonToHeader(component, filter); + return setHeader(component); } return setHeader(labelText); } @@ -109,41 +108,36 @@ public EnhancedColumn setHeader(String labelText) { return (EnhancedColumn) super.setHeader(labelText); } - private void addFilterButtonToHeader(Component headerComponent, HasValueAndElement filter) { + protected void addFilterButtonToHeader(Component headerComponent, HasValueAndElement filter) { this.filter = filter; this.headerComponent = headerComponent; // add filter field (popup component) and set filter as it's filter component filterField = new FilterField(); filterField.addApplyFilterListener(grid); - filterField.addFilterComponent(filter.getElement().getComponent().get()); - - filterField.addPopupOpenChangedEventListener(e -> { + filter.getElement().getComponent() + .ifPresent(filterComponent -> filterField.addFilterComponent(filterComponent)); + + filterField.addOpenedChangeListener(e -> { if(grid.getEditor().getItem() != null) { if(grid.allowCancelEditDialogDisplay()) { - grid.cancelEditWithCancelCallback(() -> filterField.hide()); + grid.cancelEditWithCancelCallback(() -> filterField.close()); } else { grid.getEditor().cancel(); } } }); - // need to add a not visible component so filterField (popup component) can be open - Div div = new Div(); - div.setId(getInternalId()); - div.getElement().getStyle().set("display", "inline-block"); - filterField.setFor(div.getId().get()); - headerComponent.getElement().appendChild(div.getElement()); - // add filter field to header headerComponent.getElement().appendChild(filterField.getElement()); - + filterField.setTarget(headerComponent); + grid.addFilterClickedEventListener(e -> { if(e.buttonId.equals(getInternalId())) { if(filterField.isOpened()) { - filterField.hide(); + filterField.close(); } else { - filterField.show(); + filterField.open(); } } }); @@ -153,7 +147,7 @@ private void addFilterButtonToHeader(Component headerComponent, HasValueAndEleme return filter; } - void updateFilterButtonStyle(){ + protected void updateFilterButtonStyle(){ if(headerComponent != null) { headerComponent.getElement().executeJs("return").then(ignore -> { if(hasFilterSelected()) { diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedGrid.java b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedGrid.java index a7b8d41..e35ffa5 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedGrid.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedGrid.java @@ -89,17 +89,12 @@ public class EnhancedGrid extends Grid implements BeforeLeaveObserver, App private Icon filterIcon; - SerializableFunction selectionDisabled = new SerializableFunction() { - - @Override - public String apply(T item) { - if(!selectionPredicate.test(item)) { - return "selection-disabled"; - } - return ""; - } - - }; + SerializableFunction selectionDisabled = item -> { + if (!selectionPredicate.test(item)) { + return "selection-disabled"; + } + return ""; + }; private SerializableFunction defaultClassNameGenerator = item -> null; @@ -226,7 +221,17 @@ public GridSelectionModel setSelectionMode(SelectionMode selectionMode) { if (selectionMode == SelectionMode.MULTI) { Objects.requireNonNull(selectionMode, "Selection mode cannot be null."); - GridSelectionModel model = new CustomAbstractGridMultiSelectionModel(this) { + GridSelectionModel model = new CustomAbstractGridMultiSelectionModel<>(this) { + + @Override + public void setDragSelect(boolean b) { + // Do nothing + } + + @Override + public boolean isDragSelect() { + return false; + } @Override protected void fireSelectionEvent(SelectionEvent, T> event) { @@ -236,7 +241,7 @@ protected void fireSelectionEvent(SelectionEvent, T> event) { setSelectionModel(model, selectionMode); return model; } else if (selectionMode == SelectionMode.SINGLE) { - GridSelectionModel model = new CustomAbstractGridSingleSelectionModel(this) { + GridSelectionModel model = new CustomAbstractGridSingleSelectionModel<>(this) { @Override protected void fireSelectionEvent(SelectionEvent, T> event) { @@ -247,8 +252,8 @@ protected void fireSelectionEvent(SelectionEvent, T> event) { public void setDeselectAllowed(boolean deselectAllowed) { super.setDeselectAllowed(deselectAllowed); getGrid().getElement().executeJs( - "this.$connector.deselectAllowed = $0", - deselectAllowed); + "this.$connector.deselectAllowed = $0", + deselectAllowed); } }; setSelectionModel(model, selectionMode); @@ -289,11 +294,11 @@ public void editItem(T item) { } T onEditItem = this.getEditor().getItem(); - if(onEditItem != null && item.equals(onEditItem)) { + if(item.equals(onEditItem)) { return; } - if(onEditItem != null && !item.equals(onEditItem) && allowCancelEditDialogDisplay()) { + if(onEditItem != null && allowCancelEditDialogDisplay()) { cancelEditItem(item, null, null); } else { this.getEditor().editItem(item); @@ -328,7 +333,13 @@ protected void cancelEditWithCancelCallback(SerializableRunnable onCancelCallbac } } } - + + /** + * Cancel the edition of the item. + * @param newEditItem - the new item to edit + * @param action - the action to proceed + * @param onCancelCallback - the callback to execute on cancel action + */ protected void cancelEditItem(T newEditItem, ContinueNavigationAction action, SerializableRunnable onCancelCallback) { String text = getTranslation(CANCEL_EDIT_MSG_KEY); String confirmText = getTranslation(CANCEL_EDIT_CONFIRM_BTN_KEY); @@ -337,14 +348,24 @@ protected void cancelEditItem(T newEditItem, ContinueNavigationAction action, Se new CancelEditConfirmDialog(text, confirmText, cancelText, onConfirmCallback, onCancelCallback).open(); } - private void onConfirmEditItem(T newEditItem) { + /** + * Confirm the edition of the item. + * @param newEditItem - the new item to edit + */ + protected void onConfirmEditItem(T newEditItem) { this.getEditor().cancel(); if(newEditItem != null) { this.getEditor().editItem(newEditItem); } } - private void onConfirmEditItem(T newEditItem, ContinueNavigationAction action) { + /** + * Confirm the edition of the item. + * + * @param newEditItem - the new item to edit + * @param action - the action to proceed + */ + protected void onConfirmEditItem(T newEditItem, ContinueNavigationAction action) { this.onConfirmEditItem(null); action.proceed(); } @@ -352,7 +373,7 @@ private void onConfirmEditItem(T newEditItem, ContinueNavigationAction action) { /** * Set showCancelEditDialog value to know if {@link CancelEditConfirmDialog} should be displayed. * - * @param showCancelEditDialog + * @param showCancelEditDialog - the value to set */ public void setShowCancelEditDialog(boolean showCancelEditDialog) { this.showCancelEditDialog = showCancelEditDialog; @@ -488,7 +509,7 @@ protected void applyFilterPredicate(SerializablePredicate finalPredicate) { if(dataProvider instanceof ListDataProvider) { ((ListDataProvider)dataProvider).setFilter(finalPredicate); } else if(dataProvider instanceof ConfigurableFilterDataProvider){ - ((ConfigurableFilterDataProvider)dataProvider).setFilter(new Filter(finalPredicate)); + ((ConfigurableFilterDataProvider)dataProvider).setFilter(new Filter<>(finalPredicate)); } } diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/CustomAbstractGridMultiSelectionModel.java b/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/CustomAbstractGridMultiSelectionModel.java index 0c1d71b..923a60e 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/CustomAbstractGridMultiSelectionModel.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/CustomAbstractGridMultiSelectionModel.java @@ -65,7 +65,7 @@ public abstract class CustomAbstractGridMultiSelectionModel * reference to the grid for which this selection model is * created */ - public CustomAbstractGridMultiSelectionModel(Grid grid) { + protected CustomAbstractGridMultiSelectionModel(Grid grid) { super(grid); selected = new LinkedHashSet<>(); selectionColumn = new CustomGridSelectionColumn(this::clientSelectAll, diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterClickedEvent.java b/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterClickedEvent.java index 0306522..9bac43c 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterClickedEvent.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterClickedEvent.java @@ -20,7 +20,7 @@ * #L% */ -import jakarta.validation.constraints.NotNull; +import jakarta.annotation.Nonnull; import com.vaadin.componentfactory.enhancedgrid.EnhancedGrid; import com.vaadin.flow.component.ComponentEvent; @@ -34,10 +34,9 @@ @DomEvent("filter-clicked") public class FilterClickedEvent extends ComponentEvent> { - @NotNull public final String buttonId; - public FilterClickedEvent(EnhancedGrid source, boolean fromClient, @EventData("event.detail.id") @NotNull String id) { + public FilterClickedEvent(EnhancedGrid source, boolean fromClient, @EventData("event.detail.id") @Nonnull String id) { super(source, fromClient); this.buttonId = id; } diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterField.java b/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterField.java index dcb2710..708a477 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterField.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/flow/component/grid/FilterField.java @@ -22,7 +22,6 @@ * #L% */ -import com.vaadin.componentfactory.Popup; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.HasValue; import com.vaadin.flow.component.button.Button; @@ -31,8 +30,9 @@ import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.popover.Popover; -public class FilterField extends Popup { +public class FilterField extends Popover { private static final String APPLY_BTN_KEY = "filter-field.apply.btn"; @@ -55,6 +55,14 @@ public FilterField() { rootLayout.add(filterComponentDiv, createButtonsLayout()); add(rootLayout); getElement().getThemeList().add("enhanced-grid-filter-field"); + + setOpenOnClick(false); + setOpenOnFocus(true); + setOpenOnHover(false); + + setCloseOnOutsideClick(true); + setCloseOnEsc(true); + setAutofocus(true); } private HorizontalLayout createButtonsLayout() { @@ -71,7 +79,7 @@ private HorizontalLayout createButtonsLayout() { public void applyFilter() { applyFilterListener.onApplyFilter(((HasValue)filterComponent).getValue()); - this.hide(); + this.close(); } public void resetFilter() { diff --git a/pom.xml b/pom.xml index 6e34114..4242014 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.vaadin.componentfactory enhanced-grid-flow-root - 4.0.2-SNAPSHOT + 24.5.0-SNAPSHOT pom enhanced-grid-flow @@ -13,7 +13,7 @@ enhanced-grid-flow - 24.0.0 + 24.5.6 17 17 UTF-8