File tree Expand file tree Collapse file tree 6 files changed +61
-8
lines changed
main/java/com/flowingcode/vaadin/addons
test/java/com/flowingcode/vaadin/addons/demo Expand file tree Collapse file tree 6 files changed +61
-8
lines changed Original file line number Diff line number Diff line change 2626import java .lang .annotation .Target ;
2727
2828/**
29- * This annotation is used for configuring the URL in the {@code GitHubCorner}
29+ * This annotation is used for configuring the URL in the {@code GitHubCorner} and {@code DemoClass}
3030 *
3131 * @author Javier Godoy / Flowing Code
3232 */
Original file line number Diff line number Diff line change 2525import java .lang .annotation .Target ;
2626
2727/**
28- * This annotation is used for configuring the source code URL in a {@link TabbedDemo}
28+ * This annotation is used for configuring the source code URL in a {@link TabbedDemo}. If no
29+ * {@code value} is specified, and the demo view is annotated with {@link @GithubLink}, the source
30+ * URL defaults to the location of the annotated class under {@code src/java/test} in the master
31+ * branch of the repository.
2932 *
3033 * @author Javier Godoy / Flowing Code
3134 */
3235@ Retention (RetentionPolicy .RUNTIME )
3336@ Target (ElementType .TYPE )
3437public @interface DemoSource {
3538
36- String value ();
39+ static final String GITHUB_SOURCE = "__GITHUB__" ;
40+
41+ /** A link to the source code, if different from the annotated class. */
42+ String value () default GITHUB_SOURCE ;
43+
3744}
Original file line number Diff line number Diff line change 1919 */
2020package com .flowingcode .vaadin .addons .demo ;
2121
22+ import com .flowingcode .vaadin .addons .GithubLink ;
2223import com .vaadin .flow .component .Component ;
2324import com .vaadin .flow .component .checkbox .Checkbox ;
2425import com .vaadin .flow .component .dependency .StyleSheet ;
@@ -94,10 +95,19 @@ public TabbedDemo() {
9495 * @param demo the demo instance
9596 */
9697 public void addDemo (Component demo ) {
97- String sourceCodeUrl =
98- Optional .ofNullable (demo .getClass ().getAnnotation (DemoSource .class ))
99- .map (DemoSource ::value )
98+ DemoSource demoSource = demo .getClass ().getAnnotation (DemoSource .class );
99+
100+ String sourceCodeUrl = null ;
101+ if (demoSource != null ) {
102+ sourceCodeUrl = demoSource .value ();
103+ if (sourceCodeUrl .equals (DemoSource .GITHUB_SOURCE )) {
104+ sourceCodeUrl = Optional .ofNullable (this .getClass ().getAnnotation (GithubLink .class ))
105+ .map (githubLink -> githubLink .value () + "/blob/master/src/test/java/"
106+ + demo .getClass ().getName ().replace ('.' , '/' ))
100107 .orElse (null );
108+ }
109+ }
110+
101111 String label =
102112 Optional .ofNullable (demo .getClass ().getAnnotation (PageTitle .class ))
103113 .map (PageTitle ::value )
Original file line number Diff line number Diff line change 1919 */
2020package com .flowingcode .vaadin .addons .demo ;
2121
22+ import com .flowingcode .vaadin .addons .GithubLink ;
2223import com .vaadin .flow .component .orderedlayout .VerticalLayout ;
2324import com .vaadin .flow .component .textfield .TextField ;
2425import com .vaadin .flow .router .Route ;
2526
2627/** Hello world! */
2728@ Route ("" )
29+ @ GithubLink ("https://github.com/FlowingCode/CommonsDemo" )
2830public class Demo extends TabbedDemo {
2931
3032 public Demo () {
@@ -47,5 +49,6 @@ public Demo() {
4749 addDemo (vl3 , "Demo Without Source Code" );
4850
4951 addDemo (new SampleDemo ());
52+ addDemo (new SampleDemoDefault ());
5053 }
5154}
Original file line number Diff line number Diff line change 2424import com .vaadin .flow .router .PageTitle ;
2525
2626@ PageTitle ("Demo 4" )
27- @ DemoSource (
28- "https://github.com/FlowingCode/CommonsDemo/blob/master/src/test/java/com/flowingcode/vaadin/addons/demo/SampleDemo.java" )
27+ @ DemoSource ("https://github.com/FlowingCode/CommonsDemo/blob/master/src/test/java/com/flowingcode/vaadin/addons/demo/SampleDemo.java" )
2928public class SampleDemo extends Div {
3029
3130 public SampleDemo () {
Original file line number Diff line number Diff line change 1+ /*-
2+ * #%L
3+ * Commons Demo
4+ * %%
5+ * Copyright (C) 2020 - 2021 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 .demo ;
21+
22+ import com .vaadin .flow .component .html .Div ;
23+ import com .vaadin .flow .component .html .Span ;
24+ import com .vaadin .flow .router .PageTitle ;
25+
26+ @ PageTitle ("Demo 5" )
27+ @ DemoSource
28+ public class SampleDemoDefault extends Div {
29+
30+ public SampleDemoDefault () {
31+ add (new Span ("Demo component with defaulted @DemoSource annotation" ));
32+ }
33+
34+ }
You can’t perform that action at this time.
0 commit comments