Skip to content

Commit

Permalink
* com.vaadin.componentfactory:popup:4.0.0 removed
Browse files Browse the repository at this point in the history
* Moved to Vaadin-24.5.6
* Component Popover from Vaadin 24.5.x used
* Dependency of jakarta.validation.constraints.NotNull removed
* Version set to 24.5.0 to visualize which Version of Vaadin is used
  • Loading branch information
blackbluegl committed Nov 29, 2024
1 parent 94aa1c7 commit 1fd6e66
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 62 deletions.
6 changes: 3 additions & 3 deletions enhanced-grid-flow-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow-demo</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>24.5.0-SNAPSHOT</version>

<name>Enhanced Grid Demo</name>
<packaging>war</packaging>
Expand All @@ -18,7 +18,7 @@
</organization>

<properties>
<vaadin.version>24.0.0</vaadin.version>
<vaadin.version>24.5.6</vaadin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -140,7 +140,7 @@
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>11.0.14</version>
<version>11.0.22</version>
<configuration>
<scanIntervalSeconds>-1</scanIntervalSeconds>
<stopKey>${project.artifactId}</stopKey>
Expand Down
9 changes: 2 additions & 7 deletions enhanced-grid-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>24.5.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Enhanced Grid</name>
Expand All @@ -19,7 +19,7 @@
</organization>

<properties>
<vaadin.version>24.0.0</vaadin.version>
<vaadin.version>24.5.6</vaadin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -101,11 +101,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.vaadin.componentfactory</groupId>
<artifactId>popup</artifactId>
<version>4.0.0</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,10 +75,10 @@ public EnhancedColumn(EnhancedGrid<T> grid, String columnId, Renderer<T> rendere

public EnhancedColumn<T> setHeader(String labelText, HasValueAndElement<?, ? extends FilterFieldDto> 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);
}
Expand Down Expand Up @@ -109,41 +108,36 @@ public EnhancedColumn<T> setHeader(String labelText) {
return (EnhancedColumn<T>) super.setHeader(labelText);
}

private void addFilterButtonToHeader(Component headerComponent, HasValueAndElement<?, ? extends FilterFieldDto> filter) {
protected void addFilterButtonToHeader(Component headerComponent, HasValueAndElement<?, ? extends FilterFieldDto> 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();
}
}
});
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,12 @@ public class EnhancedGrid<T> extends Grid<T> implements BeforeLeaveObserver, App

private Icon filterIcon;

SerializableFunction<T, String> selectionDisabled = new SerializableFunction<T, String>() {

@Override
public String apply(T item) {
if(!selectionPredicate.test(item)) {
return "selection-disabled";
}
return "";
}

};
SerializableFunction<T, String> selectionDisabled = item -> {
if (!selectionPredicate.test(item)) {
return "selection-disabled";
}
return "";
};

private SerializableFunction<T, String> defaultClassNameGenerator = item -> null;

Expand Down Expand Up @@ -226,7 +221,17 @@ public GridSelectionModel<T> setSelectionMode(SelectionMode selectionMode) {
if (selectionMode == SelectionMode.MULTI) {

Objects.requireNonNull(selectionMode, "Selection mode cannot be null.");
GridSelectionModel<T> model = new CustomAbstractGridMultiSelectionModel<T>(this) {
GridSelectionModel<T> model = new CustomAbstractGridMultiSelectionModel<>(this) {

@Override
public void setDragSelect(boolean b) {
// Do nothing
}

@Override
public boolean isDragSelect() {
return false;
}

@Override
protected void fireSelectionEvent(SelectionEvent<Grid<T>, T> event) {
Expand All @@ -236,7 +241,7 @@ protected void fireSelectionEvent(SelectionEvent<Grid<T>, T> event) {
setSelectionModel(model, selectionMode);
return model;
} else if (selectionMode == SelectionMode.SINGLE) {
GridSelectionModel<T> model = new CustomAbstractGridSingleSelectionModel<T>(this) {
GridSelectionModel<T> model = new CustomAbstractGridSingleSelectionModel<>(this) {

@Override
protected void fireSelectionEvent(SelectionEvent<Grid<T>, T> event) {
Expand All @@ -247,8 +252,8 @@ protected void fireSelectionEvent(SelectionEvent<Grid<T>, 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -337,22 +348,32 @@ 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();
}

/**
* 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;
Expand Down Expand Up @@ -488,7 +509,7 @@ protected void applyFilterPredicate(SerializablePredicate<T> finalPredicate) {
if(dataProvider instanceof ListDataProvider<?>) {
((ListDataProvider<T>)dataProvider).setFilter(finalPredicate);
} else if(dataProvider instanceof ConfigurableFilterDataProvider){
((ConfigurableFilterDataProvider<T, Void, Filter>)dataProvider).setFilter(new Filter<T>(finalPredicate));
((ConfigurableFilterDataProvider<T, Void, Filter>)dataProvider).setFilter(new Filter<>(finalPredicate));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public abstract class CustomAbstractGridMultiSelectionModel<T>
* reference to the grid for which this selection model is
* created
*/
public CustomAbstractGridMultiSelectionModel(Grid<T> grid) {
protected CustomAbstractGridMultiSelectionModel(Grid<T> grid) {
super(grid);
selected = new LinkedHashSet<>();
selectionColumn = new CustomGridSelectionColumn(this::clientSelectAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,10 +34,9 @@
@DomEvent("filter-clicked")
public class FilterClickedEvent<T> extends ComponentEvent<EnhancedGrid<T>> {

@NotNull
public final String buttonId;

public FilterClickedEvent(EnhancedGrid<T> source, boolean fromClient, @EventData("event.detail.id") @NotNull String id) {
public FilterClickedEvent(EnhancedGrid<T> source, boolean fromClient, @EventData("event.detail.id") @Nonnull String id) {
super(source, fromClient);
this.buttonId = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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() {
Expand All @@ -71,7 +79,7 @@ private HorizontalLayout createButtonsLayout() {

public void applyFilter() {
applyFilterListener.onApplyFilter(((HasValue<?,?>)filterComponent).getValue());
this.hide();
this.close();
}

public void resetFilter() {
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.vaadin.componentfactory</groupId>
<artifactId>enhanced-grid-flow-root</artifactId>
<version>4.0.2-SNAPSHOT</version>
<version>24.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>enhanced-grid-flow</module>
Expand All @@ -13,7 +13,7 @@
<description>enhanced-grid-flow</description>

<properties>
<vaadin.version>24.0.0</vaadin.version>
<vaadin.version>24.5.6</vaadin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 1fd6e66

Please sign in to comment.