From 3b319c40dbe616a11bf1618dafd765ecce971744 Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 10:18:30 -0300
Subject: [PATCH 1/5] build: set version to 4.1.0-SNAPSHOT
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 41701ea..0c9ce01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.flowingcode.vaadin.addons.demo
commons-demo
- 4.0.1-SNAPSHOT
+ 4.1.0-SNAPSHOT
Commons Demo
Common classes for add-ons demo
From 9e254f46d89ae104eda87c2084e8169589e0d577 Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 10:18:55 -0300
Subject: [PATCH 2/5] build: set vaadin version to 24.3.13
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 0c9ce01..93b22f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
UTF-8
17
17
- 24.3.2
+ 24.3.13
11.0.12
From a18cacd819d9bbe315b71266394c1c60866b362f Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 10:20:20 -0300
Subject: [PATCH 3/5] feat: implement EnhancedRouteTabs
---
pom.xml | 6 ++
.../vaadin/addons/demo/EnhancedRouteTabs.java | 95 +++++++++++++++++++
2 files changed, 101 insertions(+)
create mode 100644 src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
diff --git a/pom.xml b/pom.xml
index 93b22f4..fc1192f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,12 @@
provided
+
+ com.flowingcode.vaadin.addons
+ enhanced-tabs-addon
+ 1.0.0
+
+
junit
junit
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
new file mode 100644
index 0000000..4df0b45
--- /dev/null
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/EnhancedRouteTabs.java
@@ -0,0 +1,95 @@
+/*-
+ * #%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.flowingcode.vaadin.addons.enhancedtabs.EnhancedTabs;
+import com.vaadin.flow.component.Component;
+import com.vaadin.flow.component.UI;
+import com.vaadin.flow.component.tabs.Tab;
+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 EnhancedTabs in order to allow to bind tabs with Routes.
+ *
+ * @see https://cookbook.vaadin.com/tabs-with-routes/a
+ */
+public class EnhancedRouteTabs extends EnhancedTabs 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);
+ }
+ });
+ }
+}
From ab49b7f94afb31659c4d3a5e716157c472be118c Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 10:35:47 -0300
Subject: [PATCH 4/5] feat: replace RouteTabs with EnhancedRouteTabs in
TabbedDemo
---
.../java/com/flowingcode/vaadin/addons/demo/TabbedDemo.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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 bd8de0a..d1d6ae2 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 - 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.
@@ -54,7 +54,7 @@ public class TabbedDemo extends VerticalLayout implements RouterLayout {
private static final Logger logger = LoggerFactory.getLogger(TabbedDemo.class);
private static final int MOBILE_DEVICE_BREAKPOINT_WIDTH = 768;
- private RouteTabs tabs;
+ private EnhancedRouteTabs tabs;
private HorizontalLayout footer;
private SplitLayoutDemo currentLayout;
private Checkbox orientationCB;
@@ -68,7 +68,7 @@ public class TabbedDemo extends VerticalLayout implements RouterLayout {
public TabbedDemo() {
demoHelperViewer = new DialogDemoHelperViewer();
- tabs = new RouteTabs();
+ tabs = new EnhancedRouteTabs();
tabs.setWidthFull();
// Footer
From 876cba51802d8f7feb996fe2f74f8ff059d85b0b Mon Sep 17 00:00:00 2001
From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
Date: Wed, 12 Jun 2024 10:36:11 -0300
Subject: [PATCH 5/5] deprecate: deprecate RouteTabs
---
.../java/com/flowingcode/vaadin/addons/demo/RouteTabs.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java b/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java
index 480280f..1631b36 100644
--- a/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.java
+++ b/src/main/java/com/flowingcode/vaadin/addons/demo/RouteTabs.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.
@@ -37,7 +37,10 @@
* 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<>();