diff --git a/pom.xml b/pom.xml index 26275c2..9c26df3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.flowingcode.vaadin.addons.demo commons-demo - 4.4.0-SNAPSHOT + 5.0.0-SNAPSHOT Commons Demo Common classes for add-ons demo diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/DefaultSourceUrlResolver.java b/src/main/java/com/flowingcode/vaadin/addons/demo/DefaultSourceUrlResolver.java index e854c62..a64c562 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/DefaultSourceUrlResolver.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/DefaultSourceUrlResolver.java @@ -42,7 +42,7 @@ public Optional resolveURL(TabbedDemo demo, Class annotatedClass, DemoSource annotation) { String demoFile; String url = annotation.value(); - if (url.equals(DemoSource.GITHUB_SOURCE) || url.equals(DemoSource.DEFAULT_VALUE)) { + if (url.equals(DemoSource.DEFAULT_VALUE)) { String className; if (annotation.clazz() == DemoSource.class) { className = annotatedClass.getName().replace('.', '/'); 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 81410ab..8b6885c 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 - 2024 Flowing Code + * Copyright (C) 2020 - 2025 Flowing Code * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,10 +46,6 @@ @Target(ElementType.TYPE) public @interface DemoSource { - /** @deprecated. Use {@link #DEFAULT_VALUE} */ - @Deprecated - static final String GITHUB_SOURCE = "__GITHUB__"; - static final String DEFAULT_VALUE = "__DEFAULT__"; /** diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java b/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java deleted file mode 100644 index 1631b36..0000000 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * #%L - * Commons Demo - * %% - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ -package com.flowingcode.vaadin.addons.demo; - -import com.vaadin.flow.component.Component; -import com.vaadin.flow.component.UI; -import com.vaadin.flow.component.tabs.Tab; -import com.vaadin.flow.component.tabs.Tabs; -import com.vaadin.flow.router.BeforeEnterEvent; -import com.vaadin.flow.router.BeforeEnterObserver; -import com.vaadin.flow.router.HighlightConditions; -import com.vaadin.flow.router.Location; -import com.vaadin.flow.router.Route; -import com.vaadin.flow.router.RouterLink; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; - -/** - * Extension of Tabs in order to allow to bind tabs with Routes. - * - * @see https://cookbook.vaadin.com/tabs-with-routes/a - * @deprecated Deprecated for removal. Use {@link EnhancedRouteTabs} instead. - */ -@SuppressWarnings("serial") -@Deprecated(forRemoval = true) -public class RouteTabs extends Tabs implements BeforeEnterObserver { - - private final Map routerLinkTabMap = new LinkedHashMap<>(); - - public void add(RouterLink routerLink) { - routerLink.setHighlightCondition(HighlightConditions.sameLocation()); - routerLink.setHighlightAction( - (link, shouldHighlight) -> { - if (shouldHighlight) { - setSelectedTab(routerLinkTabMap.get(routerLink)); - } - }); - routerLinkTabMap.put(routerLink, new Tab(routerLink)); - add(routerLinkTabMap.get(routerLink)); - } - - @Override - public void beforeEnter(BeforeEnterEvent event) { - setSelectedTab(null); - if (TabbedDemo.class.isAssignableFrom(event.getNavigationTarget())) { - RouterLink first = getFirstRoute(); - if (first != null) { - event.forwardTo(first.getHref()); - } else { - getChildren().findFirst().ifPresent(tab -> setSelectedTab((Tab) tab)); - } - } - } - - public Map getRouterLinkTabMap() { - return routerLinkTabMap; - } - - public RouterLink getFirstRoute() { - Optional first = - routerLinkTabMap.entrySet().stream().map(Map.Entry::getKey).findFirst(); - return first.isPresent() ? first.get() : null; - } - - @Deprecated - public void addLegacyTab(String label, Component content) { - Tab tab = new Tab(label); - add(tab); - addSelectedChangeListener( - ev -> { - if (ev.getSelectedTab() == tab) { - TabbedDemo tabbedDemo = (TabbedDemo) getParent().get(); - String route = tabbedDemo.getClass().getAnnotation(Route.class).value(); - UI.getCurrent().getPage().getHistory().pushState(null, new Location(route)); - tabbedDemo.removeRouterLayoutContent(null); - tabbedDemo.showRouterLayoutContent(content); - } - }); - } -} 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 635e015..7f7fada 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java +++ b/src/main/java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java @@ -2,7 +2,7 @@ * #%L * Commons Demo * %% - * Copyright (C) 2020 - 2024 Flowing Code + * Copyright (C) 2020 - 2025 Flowing Code * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,9 @@ public TabbedDemo() { themeCB.setValue(false); themeCB.addClassName("smallcheckbox"); themeCB.addValueChangeListener(cb -> { - applyTheme(getElement(), themeCB.getValue()); + boolean useDarkTheme = themeCB.getValue(); + String theme = useDarkTheme ? "dark" : ""; + applyThemeAttribute(getElement(), theme); }); footer = new HorizontalLayout(); footer.setWidthFull(); @@ -118,32 +120,6 @@ public TabbedDemo() { setSizeFull(); } - /** - * Add a tab with a {@code demo} component. The tab label and source code URL are retrieved from - * the {@link PageTitle} (required) and {@link DemoSource} (optional) annotations in the demo - * class, respectively. - * - * @param demo the demo instance - */ - @Deprecated - public void addDemo(Component demo) { - String label = Optional.ofNullable(demo.getClass().getAnnotation(PageTitle.class)) - .map(PageTitle::value).orElse(demo.getClass().getSimpleName()); - - addDemo(demo, label, null); - } - - /** - * @param demo the demo instance - * @param label the demo name (tab label) - * @param sourceCodeUrl ignored. - */ - @Deprecated - public void addDemo(Component demo, String label, String sourceCodeUrl) { - tabs.addLegacyTab(label, demo); - updateVisibility(); - } - /** * Add a tab with a demo component. * @@ -186,11 +162,6 @@ public void addDemo(Class clazz) { addDemo(clazz, label); } - @Deprecated - public void addDemo(Component demo, String label) { - addDemo(demo, label, null); - } - @Override public void showRouterLayoutContent(HasElement content) { Component demo = (Component) content; @@ -229,7 +200,7 @@ public void showRouterLayoutContent(HasElement content) { updateFooterButtonsVisibility(); getElement().insertChild(1, content.getElement()); - applyTheme(getElement(), getThemeName()); + applyThemeAttribute(getElement(), getThemeAttribute()); } private static SourceUrlResolver resolver = null; @@ -345,18 +316,12 @@ public void setOrientation(Orientation orientation) { private static final String THEME_NAME = TabbedDemo.class.getName() + "#THEME_NAME"; - public static String getThemeName() { + public static String getThemeAttribute() { return (String) Optional.ofNullable(VaadinSession.getCurrent().getAttribute(THEME_NAME)) .orElse(""); } - @Deprecated - public static void applyTheme(Element element, boolean useDarkTheme) { - String theme = useDarkTheme ? "dark" : ""; - applyTheme(element, theme); - } - - public static void applyTheme(Element element, String theme) { + public static void applyThemeAttribute(Element element, String theme) { VaadinSession.getCurrent().setAttribute(THEME_NAME, theme); String script;