Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace popup component with popover component #42

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>5.0.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>5.0.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 @@ -4,7 +4,7 @@
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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 @@ -78,8 +77,8 @@ public EnhancedColumn<T> setHeader(String labelText, HasValueAndElement<?, ? ext
if(filter != null) {
Component headerComponent = new Span();
headerComponent.getElement().setText(labelText);
addFilterButtonToHeader(headerComponent, filter);
return setHeader(headerComponent);
addFilterButtonToHeader(headerComponent, filter);
return setHeader(headerComponent);
}
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 @@ -4,7 +4,7 @@
* #%L
* enhanced-grid-flow
* %%
* Copyright (C) 2020 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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 @@ -228,6 +223,16 @@ public GridSelectionModel<T> setSelectionMode(SelectionMode selectionMode) {
Objects.requireNonNull(selectionMode, "Selection mode cannot be null.");
GridSelectionModel<T> model = new CustomAbstractGridMultiSelectionModel<T>(this) {

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

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

@Override
protected void fireSelectionEvent(SelectionEvent<Grid<T>, T> event) {
ComponentUtil.fireEvent(getGrid(), (ComponentEvent<Grid<?>>) event);
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2023 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

/*-
* #%L
* Custom Grid
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
/*
* Copyright 2000-2017 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.component.grid;

/*-
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.vaadin.flow.component.grid;

import com.vaadin.componentfactory.enhancedgrid.EnhancedGrid;

/*-
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +20,7 @@
* #L%
*/

import com.vaadin.componentfactory.enhancedgrid.EnhancedGrid;
import com.vaadin.flow.function.SerializablePredicate;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Enhanced Grid
* %%
* Copyright (C) 2020 - 2021 Vaadin Ltd
* Copyright (C) 2020 - 2024 Vaadin Ltd
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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
Loading
Loading