diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/DemoSource.java b/src/main/java/com/flowingcode/vaadin/addons/demo/DemoSource.java index 356efc4..32fa014 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/DemoSource.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/DemoSource.java @@ -2,7 +2,7 @@ * #%L * Commons Demo * %% - * Copyright (C) 2020 - 2023 Flowing Code + * Copyright (C) 2020 - 2024 Flowing Code * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,12 +29,12 @@ /** * This annotation is used for configuring the source code URL in a {@link TabbedDemo}. If no {@code - * value} is specified, and the demo view is annotated with {@link GithubLink}, then the source URL - * defaults to the location of the annotated class under {@code src/test/java} and the branch is - * determined from the value of {@link GithubBranch} in the demo view class (if the annotation is - * present) or the containing package of the demo view class. If the source URL is defaulted and no - * {@code GithubBranch} annotation is present either in the demo view class or its containing - * package, then the branch defaults to {@code master}. + * value} or {@code clazz} is specified, and the demo view is annotated with {@link GithubLink}, + * then the source URL defaults to the location of the annotated class under {@code src/test/java} + * and the branch is determined from the value of {@link GithubBranch} in the demo view class (if + * the annotation is present) or the containing package of the demo view class. If the source URL is + * defaulted and no {@code GithubBranch} annotation is present either in the demo view class or its + * containing package, then the branch defaults to {@code master}. * * @author Javier Godoy / Flowing Code */ @@ -47,9 +47,20 @@ static final String DEFAULT_VALUE = "__DEFAULT__"; - /** A link to the source code, if different from the annotated class. */ + /** + * A link to the source code, if different from the annotated class. + *

+ * It is an error if both {@code value} and {@link #clazz()} are specified. + */ String value() default GITHUB_SOURCE; + /** + * The class to display, if different from the annotated class. + *

+ * It is an error if both {@link #value()} and {@code clazz} are specified. + */ + Class clazz() default DemoSource.class; + /** * The caption of the source tab (displayed if several sources are provided). Default to the file * name. diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java index c6317e8..f091e2b 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java @@ -214,7 +214,12 @@ private Optional createSourceCodeTab(Class annotatedClass, Dem String demoFile; String url = annotation.value(); if (url.equals(DemoSource.GITHUB_SOURCE)) { - String className = annotatedClass.getName().replace('.', '/'); + String className; + if (annotation.clazz() == DemoSource.class) { + className = annotatedClass.getName().replace('.', '/'); + } else { + className = annotation.clazz().getName().replace('.', '/'); + } demoFile = "src/test/java/" + className + ".java"; } else if (url.startsWith("/src/test/")) { demoFile = url.substring(1); diff --git a/src/test/java/com/flowingcode/vaadin/addons/demo/MultiSourceDemo.java b/src/test/java/com/flowingcode/vaadin/addons/demo/MultiSourceDemo.java index c7cba9d..c059d54 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/demo/MultiSourceDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/demo/MultiSourceDemo.java @@ -26,8 +26,12 @@ @Route(value = "demo/multisource", layout = Demo.class) @PageTitle("Demo with multiple sources") +// show-source @DemoSource +// show-source @DemoSource("/src/test/resources/META-INF/resources/frontend/multi-source-demo.css") +// show-source @DemoSource(clazz = Demo.class) @DemoSource -@DemoSource(value = "/src/test/resources/META-INF/resources/frontend/multi-source-demo.css") +@DemoSource("/src/test/resources/META-INF/resources/frontend/multi-source-demo.css") +@DemoSource(clazz = Demo.class) @StyleSheet("./multi-source-demo.css") public class MultiSourceDemo extends Div { public MultiSourceDemo() {