Skip to content

Commit 47f8fd4

Browse files
committed
Add NOT + cleanup
1 parent ffa3538 commit 47f8fd4

File tree

5 files changed

+84
-19
lines changed

5 files changed

+84
-19
lines changed

vaadin-grid-filter-demo/src/main/java/software/xdev/vaadin/ui/DemoView.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.time.LocalDate;
44

55
import com.vaadin.flow.component.AttachEvent;
6-
import com.vaadin.flow.component.button.Button;
76
import com.vaadin.flow.component.grid.Grid;
87
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
98
import com.vaadin.flow.router.AfterNavigationEvent;
@@ -25,21 +24,14 @@ public class DemoView extends VerticalLayout implements AfterNavigationObserver
2524
public DemoView()
2625
{
2726
final GridFilter<Person> filter = GridFilter.createDefault(this.grid)
28-
.withSearchableField("id", Person::id, Integer.class)
29-
.withSearchableField("firstName", Person::firstName, String.class)
30-
.withSearchableField("birthday", Person::birthday, LocalDate.class)
31-
.withSearchableField("married", Person::married, Boolean.class)
32-
.withSearchableField("department", Person::department, Department.class);
33-
this.add(filter);
27+
.withFilterableField("id", Person::id, Integer.class)
28+
.withFilterableField("firstName", Person::firstName, String.class)
29+
.withFilterableField("birthday", Person::birthday, LocalDate.class)
30+
.withFilterableField("married", Person::married, Boolean.class)
31+
.withFilterableField("department", Person::department, Department.class);
32+
this.add(filter, this.grid);
3433

3534
this.queryParameterAdapter = new GridFilterQueryParameterAdapter(filter, "filter");
36-
37-
this.add(new Button("Serialize", ev -> System.out.println(filter.serialize())));
38-
this.add(new Button(
39-
"Fill in",
40-
ev -> filter.deserializeAndApply(
41-
"_OR(id = 1,_AND(birthday = 2024-09-26,firstName contains %2C%29%28%3D+)),id = 1")));
42-
this.add(this.grid);
4335
}
4436

4537
@Override

vaadin-grid-filter/src/main/java/software/xdev/vaadin/gridfilter/AddFilterComponentsButtons.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Consumer;
2020

2121
import com.vaadin.flow.component.button.Button;
22+
import com.vaadin.flow.component.button.ButtonVariant;
2223
import com.vaadin.flow.component.icon.VaadinIcon;
2324
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
2425

@@ -33,7 +34,12 @@ public void update(
3334
{
3435
this.removeAll();
3536
filterComponentSuppliers.stream()
36-
.map(s -> new Button(s.display(), VaadinIcon.PLUS.create(), ev -> onAddButtonClicked.accept(s)))
37+
.map(s -> {
38+
final Button btn =
39+
new Button(s.display(), VaadinIcon.PLUS.create(), ev -> onAddButtonClicked.accept(s));
40+
btn.addThemeVariants(ButtonVariant.LUMO_SMALL);
41+
return btn;
42+
})
3743
.forEach(this::add);
3844
}
3945
}

vaadin-grid-filter/src/main/java/software/xdev/vaadin/gridfilter/GridFilter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import software.xdev.vaadin.gridfilter.filtercomponents.FilterComponentSerialization;
6767
import software.xdev.vaadin.gridfilter.filtercomponents.FilterComponentSupplier;
6868
import software.xdev.vaadin.gridfilter.filtercomponents.block.FilterANDComponentSupplier;
69+
import software.xdev.vaadin.gridfilter.filtercomponents.block.FilterNOTComponentSupplier;
6970
import software.xdev.vaadin.gridfilter.filtercomponents.block.FilterORComponentSupplier;
7071
import software.xdev.vaadin.gridfilter.filtercomponents.condition.FieldFilterConditionComponentSupplier;
7172

@@ -292,7 +293,7 @@ public GridFilter<T> clearFilterComponentSuppliers()
292293
return this;
293294
}
294295

295-
public <S> GridFilter<T> withSearchableField(
296+
public <S> GridFilter<T> withFilterableField(
296297
final String name,
297298
final Function<T, S> keyExtractor,
298299
final Class<S> clazz)
@@ -319,7 +320,7 @@ public static <T> GridFilter<T> createDefault(final Grid<T> grid)
319320
new SingleValueNotRequiredComponentProvider<>(
320321
Boolean.class,
321322
Checkbox::new,
322-
b -> b ? "1" : "0",
323+
b -> Boolean.TRUE.equals(b) ? "1" : "0",
323324
"1"::equals),
324325
new SingleValueComponentProvider<>(
325326
String.class,
@@ -354,6 +355,7 @@ public static <T> GridFilter<T> createDefault(final Grid<T> grid)
354355
.addFilterComponentSuppliers(List.of(
355356
new FieldFilterConditionComponentSupplier(),
356357
new FilterORComponentSupplier(),
357-
new FilterANDComponentSupplier()));
358+
new FilterANDComponentSupplier(),
359+
new FilterNOTComponentSupplier()));
358360
}
359361
}

vaadin-grid-filter/src/main/java/software/xdev/vaadin/gridfilter/filtercomponents/block/FilterBlockComponent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public FilterBlockComponent(
7979
this.serializationPrefixSupplier = serializationPrefixSupplier;
8080

8181
final Span spBlockIdentifier = new Span(identifierName);
82-
spBlockIdentifier.setMinWidth("2.4em");
82+
spBlockIdentifier.setMinWidth("2.5em");
8383
spBlockIdentifier.getStyle().set("overflow-wrap", "anywhere");
8484

8585
this.filterContainerComponent = new FilterContainerComponent<>(onValueUpdated, true);
@@ -99,6 +99,7 @@ public FilterBlockComponent(
9999
this.getStyle().set("padding-right", "var(--lumo-space-xs)");
100100
}
101101

102+
@SuppressWarnings("java:S1452")
102103
protected FilterComponent<T, ?> addFilterComponent(final FilterComponentSupplier supplier)
103104
{
104105
final FilterComponent<T, ?> filterConditionComponent = supplier.create(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.gridfilter.filtercomponents.block;
17+
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.Set;
21+
import java.util.function.Function;
22+
23+
import software.xdev.vaadin.gridfilter.FilterableField;
24+
import software.xdev.vaadin.gridfilter.business.operation.Operation;
25+
import software.xdev.vaadin.gridfilter.business.typevaluecomp.TypeValueComponentProvider;
26+
import software.xdev.vaadin.gridfilter.business.value.ValueContainer;
27+
import software.xdev.vaadin.gridfilter.business.value.reuse.ValueReUseAdapter;
28+
import software.xdev.vaadin.gridfilter.filtercomponents.FilterComponent;
29+
import software.xdev.vaadin.gridfilter.filtercomponents.FilterComponentSupplier;
30+
31+
32+
public class FilterNOTComponentSupplier implements FilterComponentSupplier
33+
{
34+
@Override
35+
public String display()
36+
{
37+
return "NOT block";
38+
}
39+
40+
@Override
41+
public String serializationPrefix()
42+
{
43+
return "_NOT";
44+
}
45+
46+
@Override
47+
public <T> FilterComponent<T, ?> create(
48+
final List<FilterableField<T, ?>> filterableFields,
49+
final Function<FilterableField<T, ?>, Map<Operation<?>, TypeValueComponentProvider<?>>> fieldDataResolver,
50+
final Map<Class<? extends ValueContainer>, Set<ValueReUseAdapter<?>>> valueReUseAdapters,
51+
final List<FilterComponentSupplier> filterComponentSuppliers,
52+
final Runnable onValueUpdated)
53+
{
54+
return new FilterBlockComponent<>(
55+
filterableFields,
56+
fieldDataResolver,
57+
valueReUseAdapters,
58+
filterComponentSuppliers,
59+
onValueUpdated,
60+
(stream, predicate) -> !stream.allMatch(predicate),
61+
"NOT",
62+
this::serializationPrefix);
63+
}
64+
}

0 commit comments

Comments
 (0)