File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
main/java/com/flowingcode/vaadin/addons/demo
test/java/com/flowingcode/vaadin/addons/demo Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .flowingcode .vaadin .addons .demo ;
2+
3+ import java .lang .annotation .ElementType ;
4+ import java .lang .annotation .Retention ;
5+ import java .lang .annotation .RetentionPolicy ;
6+ import java .lang .annotation .Target ;
7+
8+ /**
9+ * This annotation is used for configuring the source code URL in a {@link TabbedDemo}
10+ *
11+ * @author Javier Godoy / Flowing Code
12+ */
13+ @ Retention (RetentionPolicy .RUNTIME )
14+ @ Target (ElementType .TYPE )
15+ public @interface DemoSource {
16+
17+ String value ();
18+ }
Original file line number Diff line number Diff line change 2727import com .vaadin .flow .component .splitlayout .SplitLayout .Orientation ;
2828import com .vaadin .flow .component .tabs .Tab ;
2929import com .vaadin .flow .component .tabs .Tabs ;
30+ import com .vaadin .flow .router .PageTitle ;
3031import java .util .HashMap ;
3132import java .util .Map ;
33+ import java .util .Optional ;
3234
3335@ StyleSheet ("context://frontend/styles/commons-demo/shared-styles.css" )
3436@ SuppressWarnings ("serial" )
@@ -84,6 +86,26 @@ public TabbedDemo() {
8486 setSizeFull ();
8587 }
8688
89+ /**
90+ * Add a tab with a {@code demo} component. The tab label and source code URL are retrieved from
91+ * the {@link PageTitle} (required) and {@link DemoSource} (optional) annotations in the demo
92+ * class, respectively.
93+ *
94+ * @param demo the demo instance
95+ */
96+ public void addDemo (Component demo ) {
97+ String sourceCodeUrl =
98+ Optional .ofNullable (demo .getClass ().getAnnotation (DemoSource .class ))
99+ .map (DemoSource ::value )
100+ .orElse (null );
101+ String label =
102+ Optional .ofNullable (demo .getClass ().getAnnotation (PageTitle .class ))
103+ .map (PageTitle ::value )
104+ .orElse (demo .getClass ().getName ());
105+
106+ addDemo (demo , label , sourceCodeUrl );
107+ }
108+
87109 /**
88110 * @param demo the demo instance
89111 * @param name the demo name (tab label)
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ public Demo() {
4747 vl3 .add (tf );
4848 tabbedDemo .addDemo (vl3 , "Demo Without Source Code" );
4949
50+ tabbedDemo .addDemo (new SampleDemo ());
51+
5052 add (tabbedDemo );
5153 setSizeFull ();
5254 }
Original file line number Diff line number Diff line change 1+ package com .flowingcode .vaadin .addons .demo ;
2+
3+ import com .vaadin .flow .component .html .Div ;
4+ import com .vaadin .flow .component .html .Span ;
5+ import com .vaadin .flow .router .PageTitle ;
6+
7+ @ PageTitle ("Demo 4" )
8+ @ DemoSource (
9+ "https://github.com/FlowingCode/CommonsDemo/blob/master/src/test/java/com/flowingcode/vaadin/addons/demo/impl/SampleDemo.java" )
10+ public class SampleDemo extends Div {
11+
12+ public SampleDemo () {
13+ add (new Span ("Demo component with annotations" ));
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments