2929import java .util .function .BiFunction ;
3030import java .util .function .Supplier ;
3131import java .util .stream .Collectors ;
32+ import life .qbic .datamanager .views .general .grid .component .GridConfiguration .ConfiguredGrid ;
3233import life .qbic .logging .api .Logger ;
3334import life .qbic .logging .service .LoggerFactory ;
3435import org .springframework .lang .NonNull ;
@@ -107,16 +108,13 @@ public final class FilterGrid<T, F> extends Div {
107108 static final String FLEX_HORIZONTAL_CSS = "flex-horizontal" ;
108109 static final String GAP_04_CSS = "gap-04" ;
109110
110- private static final int DEFAULT_QUERY_SIZE = 150 ;
111- private static final int MAX_QUERY_SIZE = 350 ;
112111 private static final String DEFAULT_ITEM_DISPLAY_LABEL = "item" ;
113112 private static final Logger log = LoggerFactory .logger (FilterGrid .class );
114113
115114 private final Class <T > type ;
116115 private final Class <F > filterType ;
117116
118- private final Grid <T > grid ;
119- private final GridConfiguration <T , F > gridConfiguration ;
117+ private final ConfiguredGrid <T , F > configuredGrid ;
120118 private final Div selectionDisplay = new SelectionNotification ();
121119 private final Div secondaryActionGroup = createSecondaryActionGroup ();
122120
@@ -129,36 +127,32 @@ public final class FilterGrid<T, F> extends Div {
129127 public static <T , F > FilterGrid <T , F > create (
130128 Class <T > itemType ,
131129 Class <F > filterType ,
132- Grid < T > grid ,
130+ ConfiguredGrid < T , F > configuredGrid ,
133131 Supplier <F > filterSupplier ,
134- SearchTermFilterCombiner <F > searchTermFilterCombiner ,
135- GridConfiguration <T , F > gridConfiguration ) {
132+ SearchTermFilterCombiner <F > searchTermFilterCombiner ) {
136133
137- return new FilterGrid <>(itemType , filterType , grid , filterSupplier ,
138- searchTermFilterCombiner , gridConfiguration );
134+ return new FilterGrid <>(itemType , filterType , configuredGrid , filterSupplier ,
135+ searchTermFilterCombiner );
139136 }
140137
141138
142139 private FilterGrid (
143140 Class <T > itemType ,
144141 Class <F > filterType ,
145- Grid < T > grid ,
142+ ConfiguredGrid < T , F > configuredGrid ,
146143 Supplier <F > filterSupplier ,
147- SearchTermFilterCombiner <F > searchTermFilterUpdater ,
148- GridConfiguration <T , F > gridConfiguration ) {
144+ SearchTermFilterCombiner <F > searchTermFilterUpdater ) {
149145 //assign fields
150146 this .type = Objects .requireNonNull (itemType );
151147 this .filterType = Objects .requireNonNull (filterType );
152- this .grid = Objects .requireNonNull (grid );
153- this .gridConfiguration = gridConfiguration ;
148+ this .configuredGrid = Objects .requireNonNull (configuredGrid );
154149
155- configureGridForMultiSelect (grid );
156- optimizeGrid (grid , DEFAULT_QUERY_SIZE );
157- gridConfiguration .applyConfiguration (grid );
158150 //construct filter Grid component
159- constructComponent (grid );
151+ var primaryGridControls = getPrimaryGridControls (configuredGrid .getColumns ());
152+ add (primaryGridControls , configuredGrid );
153+ addClassNames ("flex-vertical" , "gap-03" , "height-full" , "width-full" );
160154
161- listenToSelection ();
155+ forwardGridSelectionEvents ();
162156 //update the filter
163157 searchField .addValueChangeListener (
164158 event -> updateFilter (searchTermFilterUpdater , filterSupplier .get (), event .getValue ()));
@@ -168,8 +162,8 @@ private FilterGrid(
168162 * Refreshes the grid and clears the selection.
169163 */
170164 public void refreshAll () {
171- this .grid . getDataProvider () .refreshAll ();
172- this .grid .deselectAll ();
165+ this .configuredGrid .refreshAll ();
166+ this .configuredGrid .deselectAll ();
173167 }
174168
175169
@@ -240,16 +234,9 @@ default F apply(String searchTerm, F filter) {
240234 }
241235
242236
243- private void constructComponent (Grid <T > grid ) {
244- var primaryGridControls = getPrimaryGridControls (grid .getColumns ());
245- add (primaryGridControls , grid );
246- addClassNames ("flex-vertical" , "gap-03" , "height-full" , "width-full" );
247-
248- }
249-
250- private void listenToSelection () {
237+ private void forwardGridSelectionEvents () {
251238 updateSelectionDisplay (
252- this .grid . getSelectionModel () .getSelectedItems ().size ());
239+ this .configuredGrid .getSelectedItems ().size ());
253240 addSelectionListener (event -> updateSelectionDisplay (event .selectedItems ().size ()));
254241 }
255242
@@ -265,7 +252,7 @@ private void updateFilter(SearchTermFilterCombiner<F> searchTermFilterCombiner,
265252 F filter ,
266253 String searchTerm ) {
267254 F updatedFilter = searchTermFilterCombiner .apply (searchTerm , filter );
268- gridConfiguration . applyConfiguration ( grid ) .setFilter (updatedFilter );
255+ configuredGrid .setFilter (updatedFilter );
269256 fireEvent (new FilterUpdateEvent <>(this .filterType , this , false , filter , updatedFilter ));
270257 }
271258
@@ -282,8 +269,7 @@ public Registration addItemCountListener(
282269 ComponentEventListener <ItemCountChangeEvent <FilterGrid <T , F >>> listener ) {
283270 ComponentEventListener <ItemCountChangeEvent <?>> itemCountComponentListener = it -> listener .onComponentEvent (
284271 new ItemCountChangeEvent <>(this , it .getItemCount (), it .isItemCountEstimated ()));
285- return gridConfiguration .applyConfiguration (grid ).addItemCountChangeListener (
286- itemCountComponentListener );
272+ return configuredGrid .addItemCountChangeListener (itemCountComponentListener );
287273 }
288274
289275 /**
@@ -292,7 +278,7 @@ public Registration addItemCountListener(
292278 * @return the assumed number of items.
293279 */
294280 public int getItemCount () {
295- return grid . getDataCommunicator () .getItemCount ();
281+ return configuredGrid .getItemCount ();
296282 }
297283
298284 /**
@@ -449,20 +435,6 @@ private TextField createSearchField() {
449435 return field ;
450436 }
451437
452- private static void optimizeGrid (Grid <?> grid , int pageSize ) {
453- if (grid .getDataProvider ().isInMemory ()) {
454- return ;
455- }
456- var computedPageSize = Math .clamp (pageSize , 100 , MAX_QUERY_SIZE );
457- grid .setPageSize (computedPageSize );
458- // Grid height must not be determined by rows in lazy mode
459- grid .setAllRowsVisible (false );
460- }
461-
462- private static boolean hasContent (String text ) {
463- return text != null && !text .isBlank ();
464- }
465-
466438 /**
467439 * Defines a custom placeholder for the search field. Default is <i>"Filter"</i>
468440 * @param placeholder the text to use as placeholder
@@ -537,7 +509,7 @@ public void setSecondaryActionGroup(Button firstButton, Button... buttons) {
537509 * @since 1.12.0
538510 */
539511 public @ NonNull Set <T > selectedElements () {
540- return grid .getSelectedItems ();
512+ return configuredGrid .getSelectedItems ();
541513 }
542514
543515 /**
@@ -573,7 +545,7 @@ public void itemDisplayLabel(String label) {
573545 * @see Grid#deselectAll()
574546 */
575547 public void deselectAll () {
576- grid .deselectAll ();
548+ configuredGrid .deselectAll ();
577549 }
578550
579551 /**
@@ -588,7 +560,7 @@ public void deselectAll() {
588560 */
589561 public Registration addSelectionListener (
590562 ComponentEventListener <FilterGridSelectionEvent <T >> listener ) {
591- return grid .addSelectionListener (it -> listener .onComponentEvent (
563+ return configuredGrid .addSelectionListener (it -> listener .onComponentEvent (
592564 new FilterGridSelectionEvent <>(this , it .getAllSelectedItems (), it .isFromClient ())));
593565 }
594566
0 commit comments