-
Notifications
You must be signed in to change notification settings - Fork 16
/
VGrid.java
98 lines (83 loc) · 2.96 KB
/
VGrid.java
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
package org.vaadin.firitin.components.grid;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.grid.GridSelectionModel;
import com.vaadin.flow.component.grid.GridVariant;
import com.vaadin.flow.data.provider.CallbackDataProvider;
import com.vaadin.flow.data.provider.DataProvider;
import org.vaadin.firitin.fluency.ui.*;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
public class VGrid<T> extends Grid<T>
implements FluentComponent<VGrid<T>>, FluentHasStyle<VGrid<T>>, FluentHasSize<VGrid<T>>,
FluentFocusable<Grid<T>, VGrid<T>>, FluentHasTheme<VGrid<T>> {
public VGrid() {
super();
}
public VGrid(int pageSize) {
super(pageSize);
}
public VGrid(Class<T> beanType) {
super(beanType);
}
public VGrid<T> withSelectionMode(Grid.SelectionMode selectionMode) {
setSelectionMode(selectionMode);
return this;
}
public VGrid<T> withSelectionModel(GridSelectionModel<T> selectionModel, Grid.SelectionMode selectionMode) {
setSelectionModel(selectionModel, selectionMode);
return this;
}
public VGrid<T> withProperties(String... propertyNames) {
setColumns(propertyNames);
return this;
}
public VGrid<T> withThemeVariants(GridVariant... variants) {
addThemeVariants(variants);
return this;
}
public VGrid<T> setDataProvider(CallbackDataProvider.FetchCallback<T, Void> fetchCallback,
CallbackDataProvider.CountCallback<T, Void> countCallback) {
setDataProvider(DataProvider.fromCallbacks(fetchCallback, countCallback));
return this;
}
public VGrid<T> withItems(Collection<T> items) {
setItems(items);
return this;
}
@Deprecated
public VGrid<T> withItems(Stream<T> streamOfItems) {
setItems(streamOfItems);
return this;
}
public VGrid<T> withItems(T... items) {
setItems(items);
return this;
}
/**
* Scrolls to the row presenting the given item.
*
* @param item the item to scroll to
* @deprecated Note, with lazy loaded content, calling this method
* may cause performance issues
*/
@Deprecated
public void scrollToItem(T item) {
int index;
Stream<T> items;
try {
items = getListDataView().getItems();
} catch (IllegalStateException exception) {
// lazy loaded, this might be slow
// TODO, figure out if we could optimze this
// for the rows that happen to be already in
// the viewport
items = getGenericDataView().getItems();
}
AtomicInteger i = new AtomicInteger(); // any mutable integer wrapper
index = items.peek(v -> i.incrementAndGet())
.anyMatch(itm -> itm.equals(item)) ?
i.get() - 1 : -1;
scrollToIndex(index);
}
}