|
26 | 26 | import com.vaadin.flow.component.grid.Grid; |
27 | 27 | import com.vaadin.flow.component.grid.dataview.GridListDataView; |
28 | 28 | import com.vaadin.flow.shared.Registration; |
29 | | -import elemental.json.JsonObject; |
30 | 29 | import java.io.Serializable; |
31 | 30 | import java.util.Optional; |
32 | 31 | import java.util.stream.Collectors; |
33 | 32 | import java.util.stream.IntStream; |
34 | 33 | import lombok.RequiredArgsConstructor; |
| 34 | +import lombok.experimental.ExtensionMethod; |
35 | 35 |
|
36 | 36 | /** |
37 | 37 | * Add support for multiple items selection using click, arrow up/down, shift+click, shift+arrow |
|
40 | 40 | */ |
41 | 41 | @SuppressWarnings("serial") |
42 | 42 | @RequiredArgsConstructor |
| 43 | +@ExtensionMethod(value = JsonMigration.class, suppressBaseMethods = true) |
43 | 44 | class EnhancedSelectionGridHelper<T> implements Serializable { |
44 | 45 |
|
45 | 46 | private static final String KEY_UP_EVENT_SHIFT_KEY = "event.shiftKey"; |
@@ -103,27 +104,26 @@ void enableEnhancedSelection() { |
103 | 104 | }); |
104 | 105 |
|
105 | 106 | keyUpRegistration = grid.getElement().addEventListener("keyup", ev -> { |
106 | | - JsonObject eventData = JsonMigration.getEventData(ev); |
107 | | - |
108 | | - String keyUp = eventData.getString(KEY_UP_EVENT_KEY); |
| 107 | + String keyUp = ev.getEventData().getString(KEY_UP_EVENT_KEY); |
109 | 108 | boolean arrowsKey = "ArrowDown".equals(keyUp) || "ArrowUp".equals(keyUp); |
110 | 109 |
|
111 | 110 | GridListDataView<T> dataView = grid.getListDataView(); |
112 | 111 |
|
113 | 112 | Optional<T> newFocusedItemMaybe = Optional.empty(); |
114 | | - int newFocusedItemIndex = (int) eventData.getNumber(KEY_UP_ELEMENT_FOCUSED_ITEM_INDEX); |
| 113 | + int newFocusedItemIndex = |
| 114 | + (int) ev.getEventData().getNumber(KEY_UP_ELEMENT_FOCUSED_ITEM_INDEX); |
115 | 115 | if (newFocusedItemIndex >= 0) { |
116 | 116 | newFocusedItemMaybe = dataView.getItems().skip(newFocusedItemIndex).findFirst(); |
117 | 117 | } |
118 | 118 |
|
119 | 119 | if (newFocusedItemMaybe.isPresent()) { |
120 | 120 | T newFocusedItem = newFocusedItemMaybe.get(); |
121 | | - boolean isSpecialKey = eventData.getBoolean(KEY_UP_EVENT_META_KEY) |
122 | | - || eventData.getBoolean(KEY_UP_EVENT_CTRL_KEY) |
123 | | - || eventData.getBoolean(KEY_UP_EVENT_ALT_KEY); |
| 121 | + boolean isSpecialKey = ev.getEventData().getBoolean(KEY_UP_EVENT_META_KEY) |
| 122 | + || ev.getEventData().getBoolean(KEY_UP_EVENT_CTRL_KEY) |
| 123 | + || ev.getEventData().getBoolean(KEY_UP_EVENT_ALT_KEY); |
124 | 124 |
|
125 | 125 | Object lastFocusedItem = ComponentUtil.getData(grid, LAST_FOCUSED_ITEM); |
126 | | - boolean shiftKey = eventData.getBoolean(KEY_UP_EVENT_SHIFT_KEY); |
| 126 | + boolean shiftKey = ev.getEventData().getBoolean(KEY_UP_EVENT_SHIFT_KEY); |
127 | 127 | if (shiftKey) { |
128 | 128 | if (lastFocusedItem == null) { |
129 | 129 | ComponentUtil.setData(grid, LAST_FOCUSED_ITEM, newFocusedItem); |
|
0 commit comments