Skip to content

Commit a8173ad

Browse files
committed
fix(demo): use reflection for RadioButtonGroup.setItems compatibility
Reflection keeps the demo compatible with Vaadin 14 and 24+.
1 parent 3cd1cdb commit a8173ad

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/test/java/com/flowingcode/vaadin/addons/orgchart/EditChartDemo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private VerticalLayout getEditionLayout() {
177177
// Action Selector
178178
actionSelector = new RadioButtonGroup<>();
179179
actionSelector.setLabel("Select Action");
180-
actionSelector.setItems("Add", "Edit", "Delete");
180+
ReflectionUtil.setItems(actionSelector,"Add", "Edit", "Delete");
181181
actionSelector.addValueChangeListener(event -> updateComponentStates());
182182

183183
Div separator = new Div();
@@ -204,7 +204,7 @@ private VerticalLayout getEditionLayout() {
204204
// Relation type selector
205205
typeSelector = new RadioButtonGroup<String>();
206206
typeSelector.setLabel("Select Relation Type:");
207-
typeSelector.setItems("Parent(root)", "Child", "Sibling");
207+
ReflectionUtil.setItems(typeSelector, "Parent(root)", "Child", "Sibling");
208208
typeSelector.setValue("Child");
209209
typeSelector.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
210210

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart;
21+
22+
import java.util.Arrays;
23+
import java.util.Collection;
24+
25+
import com.vaadin.flow.component.radiobutton.RadioButtonGroup;
26+
27+
public class ReflectionUtil {
28+
29+
/** Reflective call in order to mantain binary compatibility with Vaadin 14 - 24+ */
30+
static void setItems(RadioButtonGroup<String> radioButtonGroup,
31+
String... items) {
32+
try {
33+
RadioButtonGroup.class
34+
.getMethod("setItems", Collection.class)
35+
.invoke(radioButtonGroup, Arrays.asList(items));
36+
} catch (Exception e) {
37+
throw new RuntimeException(e);
38+
}
39+
}
40+
41+
}

0 commit comments

Comments
 (0)