forked from FlowingCode/GridHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridHelper.java
More file actions
655 lines (568 loc) · 24.4 KB
/
GridHelper.java
File metadata and controls
655 lines (568 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
/*-
* #%L
* Grid Helpers Add-on
* %%
* Copyright (C) 2022 - 2025 Flowing Code
* %%
* 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.
* #L%
*/
package com.flowingcode.vaadin.addons.gridhelpers;
import com.flowingcode.vaadin.addons.gridhelpers.CheckboxColumn.CheckboxColumnConfiguration;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.grid.FooterRow;
import com.vaadin.flow.component.grid.FooterRow.FooterCell;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.Grid.Column;
import com.vaadin.flow.component.grid.Grid.SelectionMode;
import com.vaadin.flow.component.grid.GridMultiSelectionModel;
import com.vaadin.flow.component.grid.GridSelectionModel;
import com.vaadin.flow.component.grid.GridSingleSelectionModel;
import com.vaadin.flow.component.grid.HeaderRow;
import com.vaadin.flow.component.grid.HeaderRow.HeaderCell;
import com.vaadin.flow.component.grid.ItemClickEvent;
import com.vaadin.flow.function.SerializableFunction;
import com.vaadin.flow.function.SerializablePredicate;
import com.vaadin.flow.shared.Registration;
import java.io.Serializable;
import java.util.Collection;
import lombok.AccessLevel;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("serial")
@JsModule("./fcGridHelper/connector.js")
@CssImport(value = "./fcGridHelper/vaadin-menu-bar.css", themeFor = "vaadin-menu-bar")
@CssImport(value = GridHelper.GRID_STYLES, themeFor = "vaadin-grid")
@CssImport(
value = "./fcGridHelper/vaadin-context-menu-item.css",
themeFor = "vaadin-context-menu-item")
@CssImport(
value = "./fcGridHelper/vaadin-context-menu-list-box.css",
themeFor = "vaadin-context-menu-list-box")
@CssImport(
value = "./fcGridHelper/vaadin-menu-bar-item.css",
themeFor = "vaadin-menu-bar-item")
@CssImport(
value = "./fcGridHelper/vaadin-menu-bar-list-box.css",
themeFor = "vaadin-menu-bar-list-box")
@CssImport(
value = "./fcGridHelper/vaadin-checkbox.css",
themeFor = "vaadin-checkbox")
public final class GridHelper<T> implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(GridHelper.class);
private static final String ARROW_SELECTION_PROPERTY = "_fcghArrowSelection";
private static final String ENHANCED_SELECTION_PROPERTY = "_fcghEnhancedSelection";
public static final String GRID_STYLES = "./fcGridHelper/vaadin-grid.css";
/** Compact row styling for Vaadin Grid */
// https://cookbook.vaadin.com/grid-dense-theme
private static final String DENSE_THEME_NAME = "fcGh-dense";
/**
* Compact row styling for Vaadin Grid.
*
* @deprecated Use {@link #setDenseTheme(Grid, boolean)} instead. Direct use of this constant
* bypasses the bytecode reference to {@code GridHelper}, which prevents the Vaadin production
* bundle scanner from discovering the required {@code @CssImport} annotations.
*/
@Deprecated(since = "2.1.0", forRemoval = true)
public static final String DENSE_THEME = DENSE_THEME_NAME;
/**
* Adds or removes compact row styling on the given grid.
*
* <p>Prefer this method over {@code grid.addThemeName(GridHelper.DENSE_THEME)} because it
* creates a bytecode reference to {@code GridHelper}, ensuring that the Vaadin production
* bundle scanner discovers the required {@code @CssImport} annotations.
*
* @param grid the grid to style
* @param dense {@code true} to enable dense theme, {@code false} to remove it
*/
public static void setDenseTheme(Grid<?> grid, boolean dense) {
if (dense) {
grid.addThemeName(DENSE_THEME_NAME);
} else {
grid.removeThemeName(DENSE_THEME_NAME);
}
}
/**
* Returns whether the dense theme is currently applied to the given grid.
*
* @param grid the grid to check
* @return {@code true} if the dense theme is applied
*/
public static boolean isDenseTheme(Grid<?> grid) {
return grid.hasThemeName(DENSE_THEME_NAME);
}
@Getter(value = AccessLevel.PACKAGE)
private final Grid<T> grid;
private final GridHelperPartNameGenerator<T> helperPartNameGenerator;
protected void setHelperPartNameGenerator(
Class<?> clazz, SerializableFunction<T, String> generator) {
getHelper(grid).helperPartNameGenerator.setHelperPartNameGenerator(clazz, generator);
grid.getDataCommunicator().reset();
}
private boolean selectOnClick;
private GridHelper(Grid<T> grid) {
this.grid = grid;
helperPartNameGenerator = new GridHelperPartNameGenerator<>();
setPartNameGenerator(grid.getPartNameGenerator());
grid.addItemClickListener(this::onItemClick);
grid.addAttachListener(this::onAttach);
if (grid.isAttached()) {
initConnector();
}
}
@SuppressWarnings("unchecked")
private static <T> GridHelper<T> getHelper(Column<T> column) {
return getHelper((Grid<T>) column.getGrid());
}
private static <T> GridHelper<T> getHelper(Grid<T> grid) {
@SuppressWarnings("unchecked")
GridHelper<T> helper = ComponentUtil.getData(grid, GridHelper.class);
if (helper == null) {
helper = new GridHelper<>(grid);
ComponentUtil.setData(grid, GridHelper.class, helper);
}
return helper;
}
private void initConnector() {
grid.getUI()
.orElseThrow(() -> new IllegalStateException(
"Connector can only be initialized for an attached Grid"))
.getPage()
.executeJs("window.Vaadin.Flow.fcGridHelperConnector.initLazy($0)", grid.getElement());
}
private void onAttach(AttachEvent event) {
initConnector();
selectionColumnHelper.onAttach();
}
private void onItemClick(ItemClickEvent<T> event) {
if (selectOnClick && getSelectionMode(grid) == SelectionMode.MULTI) {
T item = event.getItem();
// https://cookbook.vaadin.com/grid-conditional-select
if (!selectionFilterHelper.canSelect(item)) {
return;
}
if (grid.getSelectedItems().contains(item)) {
grid.deselect(item);
} else {
grid.select(item);
}
}
}
/** Return the grid selection mode */
public static SelectionMode getSelectionMode(Grid<?> grid) {
GridSelectionModel<?> model = grid.getSelectionModel();
if (model instanceof GridSingleSelectionModel) {
return SelectionMode.SINGLE;
}
if (model instanceof GridMultiSelectionModel) {
return SelectionMode.MULTI;
}
return SelectionMode.NONE;
}
/**
* Sets the function that is used for generating CSS part names for all the cells in the rows in
* this grid. Returning {@code null} from the generator results in no custom part name being set.
* Multiple part names can be returned from the generator as space-separated.
*
* <p>
* If {@link Column#setPartNameGenerator(SerializableFunction)} is used together with this method,
* resulting part names from both methods will be effective.
*
* @param partNameGenerator the part name generator to set.
* @see Column#setPartNameGenerator(SerializableFunction)
*/
public void setPartNameGenerator(SerializableFunction<T, String> partNameGenerator) {
grid.setPartNameGenerator(helperPartNameGenerator);
if (partNameGenerator instanceof GridHelperPartNameGenerator) {
helperPartNameGenerator.setGridPartNameGenerator(
((GridHelperPartNameGenerator<T>) partNameGenerator).getGridPartNameGenerator());
} else {
helperPartNameGenerator.setGridPartNameGenerator(partNameGenerator);
}
}
// Select on click
public static void setSelectOnClick(Grid<?> grid, boolean selectOnClick) {
getHelper(grid).selectOnClick = selectOnClick;
}
public static boolean isSelectOnClick(Grid<?> grid) {
return getHelper(grid).selectOnClick;
}
// Arrow Selection
/** Allows Grid rows to be selected using up/down arrow keys. */
public static void setArrowSelectionEnabled(Grid<?> grid, boolean value) {
grid.getElement().setProperty(ARROW_SELECTION_PROPERTY, value);
}
/** Returns whether Grid rows can be selected using up/down arrow keys. */
public static boolean isArrowSelectionEnabled(Grid<?> grid) {
return grid.getElement().getProperty(ARROW_SELECTION_PROPERTY, false);
}
// Selection Column
private final SelectionColumnHelper selectionColumnHelper = new SelectionColumnHelper(this);
/** Sets whether the multiselect selection column is hidden. */
public static void setSelectionColumnHidden(Grid<?> grid, boolean value) {
getHelper(grid).selectionColumnHelper.setSelectionColumnHidden(value);
}
/** Sets whether the multiselect selection column is frozen. */
@Deprecated
public static void setSelectionColumnFrozen(Grid<?> grid, boolean value) {
if (getSelectionMode(grid) == SelectionMode.MULTI) {
// https://cookbook.vaadin.com/grid-frozen-selection-column
((GridMultiSelectionModel<?>) grid.getSelectionModel()).setSelectionColumnFrozen(value);
}
}
/** Returns whether the multiselect selection column is hidden. */
public static boolean isSelectionColumnHidden(Grid<?> grid) {
return getHelper(grid).selectionColumnHelper.isSelectionColumnHidden();
}
/** Returns whether the multiselect selection column is frozen. */
@Deprecated
public static boolean isSelectionColumnFrozen(Grid<?> grid) {
return getSelectionMode(grid) == SelectionMode.MULTI
&& ((GridMultiSelectionModel<?>) grid.getSelectionModel()).isSelectionColumnFrozen();
}
// Selection Filter
private final SelectionFilterHelper<T> selectionFilterHelper = new SelectionFilterHelper<>(this);
/**
* Sets a predicate for determining which rows are selectable.
*
* <p>After a call to {@link Grid#setSelectionMode(SelectionMode)} the selection filter is lost
* and it has to be configured again:
*
* <pre>
* GridHelper.setSelectionFilter(grid, GridHelper.getSelectionFilter(grid)); // static call
* grid.setSelectionFilter(grid.getSelectionFilter()); // with lombok extension
* </pre>
*/
public static <T> void setSelectionFilter(Grid<T> grid, SerializablePredicate<T> predicate) {
getHelper(grid).selectionFilterHelper.setSelectionFilter(predicate);
}
/** Returns the predicate for determining which rows are selectable. */
public static <T> SerializablePredicate<T> getSelectionFilter(Grid<T> grid) {
return getHelper(grid).selectionFilterHelper.getSelectionFilter();
}
// Column Toggle
private final ColumnToggleHelper<T> columnToggleHelper = new ColumnToggleHelper<>(this);
/** Shows a menu to toggle the visibility of grid columns. */
public static void setColumnToggleVisible(Grid<?> grid, boolean visible) {
getHelper(grid).columnToggleHelper.setColumnToggleVisible(visible);
}
/** Returns whether the menu to toggle the visibility of grid columns is visible. */
public static boolean isColumnToggleVisible(Grid<?> grid) {
return getHelper(grid).columnToggleHelper.isColumnToggleVisible();
}
/**
* Returns whether this column can be hidden by the user. Default is {@code false}.
*
* @return {@code true} if the user can hide the column, {@code false} if not.
*/
public static <T> boolean isHidable(Column<T> column) {
return getHelper(column.getGrid()).columnToggleHelper.isHidable(column);
}
/**
* Sets whether this column can be hidden by the user. Hidable columns can be hidden and shown via
* the sidebar menu.
*
* @param column the column to be configured
* @param hidable {@code true} if the column may be hidden by the user via UI interaction
* @return the column.
*/
public static <T> Column<T> setHidable(Column<T> column, boolean hidable) {
getHelper(column.getGrid()).columnToggleHelper.setHidable(column, hidable);
return column;
}
/**
* Adds a listener that is notified when column visibility is modified through the sidebar menu.
*/
public static <T> Registration addColumnToggleListener(
Grid<T> grid, ComponentEventListener<ColumnToggleEvent<T>> listener) {
return getHelper(grid).columnToggleHelper.addColumnToggleListener(listener);
}
/**
* Sets the caption of the hiding toggle for this column. Shown in the toggle for this column in
* the grid's sidebar when the column is {@linkplain #isHidable(Column) hidable}.
*
* <p>
* If the value is <code>null</code>, the column cannot be hidden via the sidebar menu.
*
* @param column the column for which the hiding toggle caption is set
* @param caption the text to show in the column hiding toggle
*/
public static <T> void setHidingToggleCaption(Column<T> column, String caption) {
getHelper(column.getGrid()).columnToggleHelper.setHidingToggleCaption(column, caption);
}
/**
* Returns the caption of the hiding toggle for this column.
*
* @return the text shown in the column hiding toggle
*/
public static <T> String getHidingToggleCaption(Column<T> column) {
return getHelper(column.getGrid()).columnToggleHelper.getHidingToggleCaption(column);
}
public static boolean isMenuToggleColumn(Column<?> column) {
return column == getHelper(column).columnToggleHelper.getMenuToggleColumn();
}
// Empty Label
private final EmptyLabelGridHelper emptyLabel = new EmptyLabelGridHelper(this);
/** Sets a component that is displayed when the Grid would show an empty data set. */
public static void setEmptyGridLabel(Grid<?> grid, Component component) {
getHelper(grid).emptyLabel.setEmptyGridLabel(component);
}
/** Returns the component that is displayed when the Grid would show an empty data set. */
public static Component getEmptyGridLabel(Grid<?> grid) {
return getHelper(grid).emptyLabel.getEmptyGridLabel();
}
// FooterToolbar
private final FooterToolbarGridHelper footerToolbar = new FooterToolbarGridHelper(this);
/**
* Adds a toolbar component to the footer of the grid.
* <p>
* Note: The grid must have its columns configured before calling this method.
* Otherwise, an {@link IllegalStateException} will be thrown.
*
* @param grid the grid to add the toolbar to
* @param toolBar the toolbar component to add
* @throws IllegalStateException if the grid columns have not been configured
*/
public static void addToolbarFooter(Grid<?> grid, Component toolBar) {
getHelper(grid).footerToolbar.setFooterToolbar(toolBar);
}
@Deprecated
public static String getHeader(Grid<?> grid, Column<?> column) {
return column.getHeaderText();
}
@Deprecated
public static String getFooter(Grid<?> grid, Column<?> column) {
return column.getFooterText();
}
private final EnhancedSelectionGridHelper<T> enhancedSelectionGridHelper =
new EnhancedSelectionGridHelper<>(this);
/**
* When enabled, enhances grid row selection support adding support for these combinations: click,
* arrow up/down, shift+click, shift+arrow up/down, ctrl+click and ctrl+space.
*
* @param grid
* @param enabled
*/
public static final void setEnhancedSelectionEnabled(Grid<?> grid, boolean enabled) {
grid.getElement().setProperty(ENHANCED_SELECTION_PROPERTY, enabled);
if (enabled) {
getHelper(grid).enhancedSelectionGridHelper.enableEnhancedSelection();
} else {
getHelper(grid).enhancedSelectionGridHelper.disableEnhancedSelection();
}
}
/** Returns whether the enhanced selection is enabled. */
public static boolean isEnhancedSelectionEnabled(Grid<?> grid) {
return getHelper(grid).enhancedSelectionGridHelper.isEnhancedSelectionEnabled();
}
// HeaderFooterVisibilityHelper
private final HeaderFooterVisibilityHelper headerFooterVisibility =
new HeaderFooterVisibilityHelper(this);
public static void setHeaderVisible(Grid<?> grid, boolean visible) {
getHelper(grid).headerFooterVisibility.setHeaderVisible(visible);
}
/**
* Returns the visibility of the header section.
*
* @return true if visible, false otherwise.
*/
public static boolean isHeaderVisible(Grid<?> grid) {
return getHelper(grid).headerFooterVisibility.isHeaderVisible();
}
/**
* Sets the visibility of the footer section.
*
* @param visible true to show footer section, false to hide
*/
public static void setFooterVisible(Grid<?> grid, boolean visible) {
getHelper(grid).headerFooterVisibility.setFooterVisible(visible);
}
/**
* Returns the visibility of the footer section.
*
* @return true if visible, false otherwise.
*/
public static boolean isFooterVisible(Grid<?> grid) {
return getHelper(grid).headerFooterVisibility.isFooterVisible();
}
private final HeaderFooterStylesHelper headerFooterStylesHelper =
new HeaderFooterStylesHelper(this);
/**
* Returns a helper for managing CSS styles on cells within a header row.
*
* @param grid the grid containing the header row
* @param row the header row to style
* @return a {@link GridStylesHelper} for managing styles on the header row's cells
* @deprecated Use {@link HeaderCell#setPartName(String)} and {@link HeaderCell#getPartName()}
*/
@Deprecated
public static GridStylesHelper getHeaderStyles(Grid<?> grid, HeaderRow row) {
return getHelper(grid).headerFooterStylesHelper.getStyles(row);
}
/**
* Returns a helper for managing CSS styles on cells within a footer row.
*
* @param grid the grid containing the footer row
* @param row the footer row to style
* @return a {@link GridStylesHelper} for managing styles on the footer row's cells
* @deprecated Use {@link FooterCell#setPartName(String)} and {@link FooterCell#getPartName()}
*/
@Deprecated
public static GridStylesHelper getFooterStyles(Grid<?> grid, FooterRow row) {
return getHelper(grid).headerFooterStylesHelper.getStyles(row);
}
/**
* Returns a helper for managing CSS styles on a specific header cell.
*
* @param grid the grid containing the header cell
* @param cell the header cell to style
* @return a {@link GridStylesHelper} for managing styles on the header cell
* @deprecated Use {@link HeaderCell#setPartName(String)} and {@link HeaderCell#getPartName()}
*/
@Deprecated
public static GridStylesHelper getHeaderStyles(Grid<?> grid, HeaderCell cell) {
return getHelper(grid).headerFooterStylesHelper.getStyles(cell);
}
/**
* Returns a helper for managing CSS styles on a specific footer cell.
*
* @param grid the grid containing the footer cell
* @param cell the footer cell to style
* @return a {@link GridStylesHelper} for managing styles on the footer cell
* @deprecated Use {@link FooterCell#setPartName(String)} and {@link FooterCell#getPartName()}
*/
@Deprecated
public static GridStylesHelper getFooterStyles(Grid<?> grid, FooterCell cell) {
return getHelper(grid).headerFooterStylesHelper.getStyles(cell);
}
private final HeightByRowsHelper heightByRowsHelper = new HeightByRowsHelper(this);
/**
* Sets the number of rows that should be visible in Grid's body, while
* {@link #getHeightMode(Grid)} is {@link HeightMode#ROW}.
*
* <p>
* The algorithm assumes that all data rows have the same height and considers headers, footers,
* and the horizontal scrollbar when the method is called. However, if data rows, headers, or
* footers are inserted or removed after the initial calculation, the grid may not automatically
* adjust the size of the grid to accommodate the changed number of rows.
*
* @param rows The height in terms of number of rows displayed in Grid's body. If Grid doesn't
* contain enough rows, white space is displayed instead.
* @throws IllegalArgumentException if {@code rows} is zero or less
* @throws IllegalArgumentException if {@code rows} is {@link Double#isInfinite(double) infinite}
* @throws IllegalArgumentException if {@code rows} is {@link Double#isNaN(double) NaN}
*/
public static void setHeightByRows(Grid<?> grid, double rows) {
getHelper(grid).heightByRowsHelper.setHeightByRows(rows);
}
/**
* Sets the number of rows that should be visible in Grid's body, while
* {@link #getHeightMode(Grid)} is {@link HeightMode#ROW}.
*
* <p>
* If Grid is currently not in {@link HeightMode#ROW}, the given value is remembered, and applied
* once the mode is applied. @See {@link #setHeightByRows(Grid, double)}
*/
public static void setHeightByRows(Grid<?> grid, int rows) {
// this overload is a workaround for a lombok issue "bad type on operand stack"
// when setHeightByRows(Grid, double) is called with actual parameter of type int
setHeightByRows(grid, (double) rows);
}
/**
* Gets the amount of rows in Grid's body that are shown, while {@link #getHeightMode(Grid)} is
* {@link HeightMode#ROW}.
*
* @return the amount of rows that are being shown in Grid's body
* @see #setHeightByRows(Grid, double)
*/
public static double getHeightByRows(Grid<?> grid) {
return getHelper(grid).heightByRowsHelper.getHeightByRows();
}
/**
* Defines the mode in which the Grid's height is calculated.
*
* <p>
* If {@link HeightMode#CSS} is given, Grid will respect the values given via a {@code
* setHeight}-method, and behave as a traditional Component.
*
* <p>
* If {@link HeightMode#ROW} is given, Grid will make sure that the body will display as many rows
* as {@link #getHeightByRows(Grid)} defines.
*
* @param heightMode the mode in to which Grid should be set
*/
public static void setHeightMode(Grid<?> grid, HeightMode heightMode) {
getHelper(grid).heightByRowsHelper.setHeightMode(heightMode);
}
/**
* Defines the mode in which the Grid's height is calculated.
*
* <p>
* If {@link HeightMode#CSS} is given, Grid will respect the CSS height as a traditional
* Component.
*
* <p>
* If {@link HeightMode#ROW} is given, Grid will make sure that the body will display as many rows
* as {@link #getHeightByRows(Grid)} defines.
*
* @return the mode in which the Grid is set
*/
public static HeightMode getHeightMode(Grid<?> grid) {
return getHelper(grid).heightByRowsHelper.getHeightMode();
}
private final ResponsiveGridHelper<T> responsiveGridHelper = new ResponsiveGridHelper<>(this);
/** Get or create a responsive steps for the given {@code grid} and minimum width. */
public static <T> GridResponsiveStep<T> responsiveStep(Grid<T> grid, int minWidth) {
return getHelper(grid).responsiveGridHelper.getOrCreate(minWidth);
}
/** Return the responsive steps of the given {@code grid}. */
public static <T> Collection<GridResponsiveStep<T>> getResponsiveSteps(Grid<T> grid) {
return getHelper(grid).responsiveGridHelper.getAll();
}
private final CheckboxColumnGridHelper<T> checkboxColumnGridHelper =
new CheckboxColumnGridHelper<>(this);
public static <T> CheckboxColumn<T> addCheckboxColumn(Grid<T> grid,
CheckboxColumnConfiguration<T> config) {
return getHelper(grid).checkboxColumnGridHelper.addCheckboxColumn(config);
}
private final LazySelectAllGridHelper<T> lazySelectAllGridHelper =
new LazySelectAllGridHelper<>(this);
/**
* Toggles select all checkbox visibility in the grid's default header row for the selection
* column.
* <p>
* Only works when Grid uses {@link SelectionMode#MULTI} and the data provider supplies a count
* callback.
* <p>
* <i>Note: enabling the select all checkbox when grid uses a lazy data source could lead to
* memory and performance issues.</i>
*
* @see LazySelectAllGridHelper
*
* @param visible true to show the select all checkbox, false to hide it.
*/
public static <T> void toggleSelectAllCheckbox(Grid<T> grid, boolean visible) {
getHelper(grid).lazySelectAllGridHelper.toggleSelectAllCheckbox(visible);
}
private final GridRadioSelectionColumnHelper<T> radioButtonSelectionColumnHelper =
new GridRadioSelectionColumnHelper<>(this);
public static <T> GridRadioSelectionColumn showRadioSelectionColumn(Grid<T> grid) {
return getHelper(grid).radioButtonSelectionColumnHelper.showRadioSelectionColumn();
}
}