Skip to content

Commit 28f5df9

Browse files
committed
feat: add addDemo overload with default label
1 parent 20621a9 commit 28f5df9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ public void addDemo(Class<? extends Component> clazz, String label) {
128128
tabs.add(tab);
129129
}
130130

131+
/**
132+
* Add a tab with a {@code demo} component. The tab label is retrieved from
133+
* the {@link PageTitle} annotations in the demo class.
134+
*
135+
* @param clazz the class of routed demo view component
136+
*/
137+
public void addDemo(Class<? extends Component> clazz) {
138+
String label =
139+
Optional.ofNullable(clazz.getClass().getAnnotation(PageTitle.class))
140+
.map(PageTitle::value)
141+
.orElse(clazz.getSimpleName());
142+
143+
addDemo(clazz, label);
144+
}
145+
131146
public void addDemo(Component demo, String label) {
132147
addDemo(demo, label, null);
133148
}

0 commit comments

Comments
 (0)