Skip to content

Commit 7e6f887

Browse files
javier-godoypaodb
authored andcommitted
feat: add json-migration-helper
Close #142
1 parent 7bbc7ff commit 7e6f887

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
<artifactId>vaadin-core</artifactId>
125125
<optional>true</optional>
126126
</dependency>
127+
<dependency>
128+
<groupId>com.flowingcode.vaadin</groupId>
129+
<artifactId>json-migration-helper</artifactId>
130+
<version>0.0.1-SNAPSHOT</version>
131+
</dependency>
127132
<dependency>
128133
<groupId>org.slf4j</groupId>
129134
<artifactId>slf4j-simple</artifactId>

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/EnhancedSelectionGridHelper.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
package com.flowingcode.vaadin.addons.gridhelpers;
2222

23+
import com.flowingcode.vaadin.jsonmigration.JsonMigration;
2324
import com.vaadin.flow.component.ComponentUtil;
2425
import com.vaadin.flow.component.UI;
2526
import com.vaadin.flow.component.grid.Grid;
2627
import com.vaadin.flow.component.grid.dataview.GridListDataView;
2728
import com.vaadin.flow.shared.Registration;
29+
import elemental.json.JsonObject;
2830
import java.io.Serializable;
2931
import java.util.Optional;
3032
import java.util.stream.Collectors;
@@ -101,26 +103,27 @@ void enableEnhancedSelection() {
101103
});
102104

103105
keyUpRegistration = grid.getElement().addEventListener("keyup", ev -> {
104-
String keyUp = ev.getEventData().getString(KEY_UP_EVENT_KEY);
106+
JsonObject eventData = JsonMigration.getEventData(ev);
107+
108+
String keyUp = eventData.getString(KEY_UP_EVENT_KEY);
105109
boolean arrowsKey = "ArrowDown".equals(keyUp) || "ArrowUp".equals(keyUp);
106110

107111
GridListDataView<T> dataView = grid.getListDataView();
108112

109113
Optional<T> newFocusedItemMaybe = Optional.empty();
110-
int newFocusedItemIndex =
111-
(int) ev.getEventData().getNumber(KEY_UP_ELEMENT_FOCUSED_ITEM_INDEX);
114+
int newFocusedItemIndex = (int) eventData.getNumber(KEY_UP_ELEMENT_FOCUSED_ITEM_INDEX);
112115
if (newFocusedItemIndex >= 0) {
113116
newFocusedItemMaybe = dataView.getItems().skip(newFocusedItemIndex).findFirst();
114117
}
115118

116119
if (newFocusedItemMaybe.isPresent()) {
117120
T newFocusedItem = newFocusedItemMaybe.get();
118-
boolean isSpecialKey = ev.getEventData().getBoolean(KEY_UP_EVENT_META_KEY)
119-
|| ev.getEventData().getBoolean(KEY_UP_EVENT_CTRL_KEY)
120-
|| ev.getEventData().getBoolean(KEY_UP_EVENT_ALT_KEY);
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);
121124

122125
Object lastFocusedItem = ComponentUtil.getData(grid, LAST_FOCUSED_ITEM);
123-
boolean shiftKey = ev.getEventData().getBoolean(KEY_UP_EVENT_SHIFT_KEY);
126+
boolean shiftKey = eventData.getBoolean(KEY_UP_EVENT_SHIFT_KEY);
124127
if (shiftKey) {
125128
if (lastFocusedItem == null) {
126129
ComponentUtil.setData(grid, LAST_FOCUSED_ITEM, newFocusedItem);

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/ResponsiveGridHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Grid Helpers Add-on
44
* %%
5-
* Copyright (C) 2022 - 2024 Flowing Code
5+
* Copyright (C) 2022 - 2025 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.gridhelpers;
2121

22+
import com.flowingcode.vaadin.jsonmigration.JsonMigration;
2223
import com.vaadin.flow.component.grid.Grid;
2324
import com.vaadin.flow.dom.DebouncePhase;
2425
import com.vaadin.flow.shared.Registration;
@@ -76,7 +77,7 @@ GridResponsiveStep<T> getOrCreate(int minWidth) {
7677
private void initialize() {
7778
Grid<T> grid = helper.getGrid();
7879
grid.getElement().addEventListener("fcgh-responsive-step", ev -> {
79-
apply((int) ev.getEventData().getNumber("event.detail.step"), false);
80+
apply((int) JsonMigration.getEventData(ev).getNumber("event.detail.step"), false);
8081
}).addEventData("event.detail.step").debounce(200, DebouncePhase.TRAILING);
8182
sendSteps();
8283
}

0 commit comments

Comments
 (0)