Skip to content

Commit 34623ed

Browse files
Datagrid - Add filter group to allow disjunction
1 parent 393615c commit 34623ed

19 files changed

+536
-447
lines changed

ponysdk/src/main/java/com/ponysdk/core/ui/datagrid2/column/ColumnActionListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface ColumnActionListener<V> {
4848
/**
4949
* Called when this column is filtered
5050
*
51-
* @see ColumnController#filter(Object, BiPredicate, boolean)
51+
* @see ColumnController#filter(Object, BiPredicate, boolean, boolean)
5252
*/
5353
void onFilter(Object key, BiPredicate<V, Supplier<Object>> filter, boolean reinforcing);
5454

ponysdk/src/main/java/com/ponysdk/core/ui/datagrid2/column/ColumnController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.ponysdk.core.ui.datagrid2.column;
2525

26+
import java.util.List;
2627
import java.util.function.BiPredicate;
2728
import java.util.function.Supplier;
2829

@@ -54,6 +55,7 @@ public interface ColumnController<V> {
5455
* arguments are the model value and a {@code Supplier}
5556
* that provides the rendering helper that was supplied
5657
* by {@link ColumnDefinition#getRenderingHelper(Object)}
58+
* @param isActive a {@code Supplier} that provide values uses by filter
5759
* @param reinforcing {@code true} if the predicate is at least as
5860
* intolerant as the replaced predicate of the same key
5961
* (i.e. the predicate doesn't accept any value that was
@@ -64,7 +66,7 @@ public interface ColumnController<V> {
6466
* replacing an existing one, the value of the
6567
* {@code reinforcing} argument has no impact.
6668
*/
67-
void filter(Object key, BiPredicate<V, Supplier<Object>> filter, boolean reinforcing);
69+
void filter(Object key, BiPredicate<V, Supplier<Object>> filter, boolean isActive, boolean reinforcing);
6870

6971
/**
7072
* Cancels the filter, corresponding to {@code key}, from the view

ponysdk/src/main/java/com/ponysdk/core/ui/datagrid2/column/ColumnDefinition.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.ponysdk.core.ui.datagrid2.column;
2525

26+
import java.util.function.BiPredicate;
2627
import java.util.function.Supplier;
2728

2829
import com.ponysdk.core.ui.basic.IsPWidget;
@@ -87,7 +88,7 @@ public interface ColumnDefinition<V> extends ColumnActionListener<V> {
8788
* {@link ColumnDefinition#compare(Object, Supplier, Object, Supplier)} to
8889
* be used for sorting purposes, or inside the {@code BiPredicate} argument
8990
* of
90-
* {@link ColumnController#filter(Object, java.util.function.BiPredicate, boolean)}
91+
* {@link ColumnController#filter(Object, BiPredicate, boolean, boolean)}
9192
* to be used for filtering purposes.
9293
* For example: for a date column, this method can return a formatted
9394
* {@code String} of the date value, to avoid recalculating the
@@ -156,8 +157,7 @@ public interface ColumnDefinition<V> extends ColumnActionListener<V> {
156157
/**
157158
* @return {@code true} if data can be filtered based on this column,
158159
* {@code false} otherwise
159-
* @see ColumnController#filter(Object, java.util.function.BiPredicate,
160-
* boolean)
160+
* @see ColumnController#filter(Object, BiPredicate, boolean, boolean)
161161
*/
162162
boolean isFilterable();
163163

@@ -195,6 +195,11 @@ public interface ColumnDefinition<V> extends ColumnActionListener<V> {
195195
* @return the maximum width for this column
196196
*/
197197
int getMaxWidth();
198+
199+
/**
200+
* @return the group that the column belongs to. Null if it is not affiliated with a group.
201+
*/
202+
String getGroup();
198203

199204
/**
200205
* The state of a column regarding its visibility and pinning.

ponysdk/src/main/java/com/ponysdk/core/ui/datagrid2/column/DecoratorColumnDefinition.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,9 @@ public IsPWidget getDraggableHeaderElement() {
179179
public void onMoved() {
180180
column.onMoved();
181181
}
182+
183+
@Override
184+
public String getGroup() {
185+
return column.getGroup();
186+
}
182187
}

ponysdk/src/main/java/com/ponysdk/core/ui/datagrid2/column/DefaultColumnDefinition.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323

2424
package com.ponysdk.core.ui.datagrid2.column;
2525

26-
import java.util.function.BiConsumer;
27-
import java.util.function.BiPredicate;
28-
import java.util.function.Function;
29-
import java.util.function.Supplier;
30-
3126
import com.ponysdk.core.ui.basic.Element;
3227
import com.ponysdk.core.ui.basic.IsPWidget;
3328
import com.ponysdk.core.ui.basic.PComplexPanel;
3429
import com.ponysdk.core.ui.basic.PLabel;
3530
import com.ponysdk.core.ui.datagrid2.cell.LabelCell;
3631
import com.ponysdk.core.ui.datagrid2.cell.PrimaryCell;
3732

33+
import java.util.function.BiConsumer;
34+
import java.util.function.BiPredicate;
35+
import java.util.function.Function;
36+
import java.util.function.Supplier;
37+
3838
/**
3939
* @author mbagdouri
4040
*/
@@ -47,16 +47,21 @@ public class DefaultColumnDefinition<V> implements ColumnDefinition<V> {
4747
private final PLabel columnNameLabel = Element.newPLabel();
4848
private final PLabel pinLabel = Element.newPLabel();
4949
private final PLabel hideLabel = Element.newPLabel();
50+
private final String group;
5051
private ColumnController<V> columnController;
5152
private Boolean sort;
5253
private State state = getDefaultState();
5354

54-
public DefaultColumnDefinition(final String columnName, final Function<V, Object> columnValueFn,
55-
final BiConsumer<V, String> columnEditFn) {
55+
public DefaultColumnDefinition(final String columnName, final Function<V, Object> columnValueFn, final BiConsumer<V, String> columnEditFn) {
56+
this(columnName, columnValueFn, columnEditFn, null);
57+
}
58+
59+
public DefaultColumnDefinition(final String columnName, final Function<V, Object> columnValueFn, final BiConsumer<V, String> columnEditFn, String group) {
5660
super();
5761
this.columnName = columnName;
5862
this.columnValueFn = columnValueFn;
5963
this.columnEditFn = columnEditFn;
64+
this.group = group;
6065
initHeader();
6166
}
6267

@@ -113,13 +118,13 @@ public String toString() {
113118
}
114119

115120
@Override
116-
public void setController(final ColumnController<V> columnController) {
117-
this.columnController = columnController;
121+
public ColumnController<V> getController() {
122+
return columnController;
118123
}
119124

120125
@Override
121-
public ColumnController<V> getController() {
122-
return columnController;
126+
public void setController(final ColumnController<V> columnController) {
127+
this.columnController = columnController;
123128
}
124129

125130
@Override
@@ -223,4 +228,9 @@ public IsPWidget getDraggableHeaderElement() {
223228
@Override
224229
public void onMoved() {
225230
}
231+
232+
@Override
233+
public String getGroup() {
234+
return group;
235+
}
226236
}

ponysdk/src/main/java/com/ponysdk/core/ui/datagrid2/controller/DataGridController.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323

2424
package com.ponysdk.core.ui.datagrid2.controller;
2525

26-
import java.util.Collection;
27-
import java.util.Comparator;
28-
import java.util.Map;
29-
import java.util.function.BiPredicate;
30-
import java.util.function.Consumer;
31-
import java.util.function.Predicate;
32-
import java.util.function.Supplier;
33-
3426
import com.ponysdk.core.server.service.query.PResultSet;
3527
import com.ponysdk.core.ui.datagrid2.adapter.DataGridAdapter;
3628
import com.ponysdk.core.ui.datagrid2.cell.Cell;
@@ -41,6 +33,14 @@
4133
import com.ponysdk.core.ui.datagrid2.view.DataGridView;
4234
import com.ponysdk.core.util.Pair;
4335

36+
import java.util.Collection;
37+
import java.util.Comparator;
38+
import java.util.Map;
39+
import java.util.function.BiPredicate;
40+
import java.util.function.Consumer;
41+
import java.util.function.Predicate;
42+
import java.util.function.Supplier;
43+
4444
/**
4545
* @author mbagdouri
4646
*/
@@ -53,14 +53,13 @@ public interface DataGridController<K, V> {
5353

5454
boolean isSelectable(K k);
5555

56-
public PResultSet<V> getFilteredData();
56+
PResultSet<V> getFilteredData();
57+
58+
PResultSet<V> getLiveSelectedData();
5759

58-
public PResultSet<V> getLiveSelectedData();
59-
60-
public PResultSet<V> getLastRequestedData();
60+
PResultSet<V> getLastRequestedData();
6161

6262
/**
63-
*
6463
* @return the number of selected data
6564
*/
6665
int getLiveSelectedDataCount();
@@ -90,9 +89,10 @@ public interface DataGridController<K, V> {
9089

9190
void sort();
9291

93-
void setFilter(Object key, ColumnDefinition<V> column, BiPredicate<V, Supplier<Object>> filter, boolean reinforcing);
92+
void setFilter(Object key, ColumnDefinition<V> column, BiPredicate<V, Supplier<Object>> filter, boolean isActive,
93+
boolean reinforcing);
9494

95-
void setFilter(Object key, String id, Predicate<V> filter, boolean reinforcing);
95+
void setFilter(Object key, String id, Predicate<V> filter, boolean isActive, boolean reinforcing);
9696

9797
void clearFilter(Object key);
9898

@@ -117,8 +117,8 @@ public interface DataGridController<K, V> {
117117
void enrichConfigBuilder(DataGridConfigBuilder<V> builder);
118118

119119
/**
120-
* Performs a full refresh; i.e. same as {@link #refreshOnNextDraw()} but with a forced redraw on
121-
* {@link DataGridView} afterwards.
120+
* Performs a full refresh; i.e. same as {@link #refreshOnNextDraw()} but with a
121+
* forced redraw on {@link DataGridView} afterwards.
122122
*/
123123
void refresh();
124124

@@ -129,7 +129,7 @@ public interface DataGridController<K, V> {
129129
* Indeed, a performance mechanism limits the rows which gets refreshed during a draw and this refresh ensures the
130130
* whole dataset will be refreshed.<br>
131131
* <br>
132-
*
132+
* <p>
133133
* splits the data in 2 zones: a constant one and a variable one.
134134
* The variable zone is the only one that gets updated during a draw and it is constantly narrowed down for better
135135
* performance.<br>
@@ -183,6 +183,11 @@ void prepareLiveDataOnScreen(int dataSrcRowIndex, int dataSize, DataGridSnapshot
183183
*/
184184
V removeData(K k);
185185

186+
/**
187+
* Whether the model is bound to the view.
188+
*/
189+
boolean getBound();
190+
186191
/**
187192
* If {@code bound} is true (default), the view is notified when the model
188193
* is updated. Otherwise, the view is not notified but it will continue to
@@ -192,9 +197,4 @@ void prepareLiveDataOnScreen(int dataSrcRowIndex, int dataSize, DataGridSnapshot
192197
*/
193198
void setBound(boolean bound);
194199

195-
/**
196-
* Whether the model is bound to the view.
197-
*/
198-
boolean getBound();
199-
200200
}

0 commit comments

Comments
 (0)