Skip to content

Commit 3e56609

Browse files
Adjusted doc. Added FilterComponentUtl. The reset button will now be deactivated if the initial state was restored.
1 parent 1435036 commit 3e56609

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

vaadin-simple-grid-filter/src/main/java/software/xdev/vaadin/FilterComponent.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import software.xdev.vaadin.model.FilterField;
8282
import software.xdev.vaadin.model.FilterFieldEnumExtension;
8383
import software.xdev.vaadin.model.SimpleFilterField;
84+
import software.xdev.vaadin.utl.FilterComponentUtl;
8485
import software.xdev.vaadin.utl.QueryParameterUtil;
8586

8687

@@ -515,8 +516,23 @@ private void deactivateDeleteButtonFromChipComponents(
515516
this.addQueryParameter(badge);
516517
}
517518

518-
// Activate the reset button
519-
this.btnResetFilter.setEnabled(true);
519+
// When no initial filter is existing
520+
if(this.initialChipBadges.isEmpty() && this.chipBadges.isEmpty())
521+
{
522+
this.btnResetFilter.setEnabled(false);
523+
}
524+
else
525+
{
526+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> initialChipBadgesCopy
527+
= new ArrayList<>(this.initialChipBadges);
528+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> chipBadgesCopy
529+
= new ArrayList<>(this.chipBadges);
530+
531+
// Check if just the initial filter are currently applied. Then enable/disable the reset button as
532+
// appropriate.
533+
this.btnResetFilter.setEnabled(
534+
!new FilterComponentUtl<T>().equalLists(initialChipBadgesCopy, chipBadgesCopy));
535+
}
520536
});
521537
}
522538
}
@@ -1289,7 +1305,7 @@ private String createMultipleQueryParameterString()
12891305
/**
12901306
* Method for adding a specific filter condition as query parameter.
12911307
*
1292-
* @param filterCondition The condition which should be converted to query parameter.
1308+
* @param chipBadge The condition which should be converted to query parameter.
12931309
*/
12941310
private void addQueryParameter(final ChipBadgeExtension<FilterCondition<T, ?>> chipBadge)
12951311
{
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.vaadin.utl;
17+
18+
import java.util.ArrayList;
19+
import java.util.Comparator;
20+
import java.util.List;
21+
22+
import software.xdev.vaadin.model.ChipBadge;
23+
import software.xdev.vaadin.model.ChipBadgeExtension;
24+
import software.xdev.vaadin.model.FilterCondition;
25+
26+
27+
public final class FilterComponentUtl<T>
28+
{
29+
public FilterComponentUtl()
30+
{
31+
}
32+
33+
/**
34+
* Check if the lists contains the same chip badges objects
35+
*
36+
* @param one List one
37+
* @param two List two
38+
* @return True if the lists contains the same objects
39+
*/
40+
public boolean equalLists(
41+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> one,
42+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> two)
43+
{
44+
if(one == null && two == null)
45+
{
46+
return true;
47+
}
48+
49+
if(one == null || two == null || one.size() != two.size())
50+
{
51+
return false;
52+
}
53+
54+
// to avoid messing the order of the lists we will use a copy
55+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> oneCopy = new ArrayList<>(one);
56+
final List<ChipBadgeExtension<FilterCondition<T, ?>>> twoCopy = new ArrayList<>(two);
57+
58+
oneCopy.sort(Comparator.comparing(ChipBadge::getBadgeId));
59+
twoCopy.sort(Comparator.comparing(ChipBadge::getBadgeId));
60+
return one.equals(two);
61+
}
62+
}

0 commit comments

Comments
 (0)