From 8c281235c51fa029f01f0b648a7fc1e84a078679 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Mon, 5 Aug 2024 21:01:58 +0200 Subject: [PATCH 1/3] Add a Forwarding Page to forward to other pages --- .../ui/appframe/ForwardingPage.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java diff --git a/src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java b/src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java new file mode 100644 index 0000000..105a6c3 --- /dev/null +++ b/src/main/java/com/penguineering/gartenplus/ui/appframe/ForwardingPage.java @@ -0,0 +1,26 @@ +package com.penguineering.gartenplus.ui.appframe; + +import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.Tag; +import com.vaadin.flow.router.BeforeEnterEvent; +import com.vaadin.flow.router.BeforeEnterObserver; + +import java.util.Objects; + +/** + * A page that forwards to another page. + */ +@Tag("div") +public abstract class ForwardingPage extends Component implements BeforeEnterObserver { + private final Class target; + + public ForwardingPage(Class target) { + Objects.requireNonNull(target, "target must not be null"); + this.target = target; + } + + @Override + public void beforeEnter(BeforeEnterEvent event) { + event.forwardTo(this.target); + } +} From 390ca9fae0fe0ff767c3c1b5f138028fa119e677 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Mon, 5 Aug 2024 21:02:10 +0200 Subject: [PATCH 2/3] Use the ForwardingPage for the settings landing page --- .../ui/content/admin/settings/SettingsPage.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java b/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java index 3c1b84c..9cf728a 100644 --- a/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java +++ b/src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsPage.java @@ -1,9 +1,7 @@ package com.penguineering.gartenplus.ui.content.admin.settings; -import com.penguineering.gartenplus.ui.appframe.GartenplusPage; +import com.penguineering.gartenplus.ui.appframe.ForwardingPage; import com.penguineering.gartenplus.ui.content.admin.settings.users.UsersSettingsPage; -import com.vaadin.flow.router.BeforeEnterEvent; -import com.vaadin.flow.router.BeforeEnterObserver; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import jakarta.annotation.security.RolesAllowed; @@ -11,10 +9,8 @@ @Route(value = "", layout = SettingsLayout.class) @RolesAllowed("ADMINISTRATOR") @PageTitle("GartenPlus | Einstellungen") -public class SettingsPage extends GartenplusPage implements BeforeEnterObserver { - @Override - public void beforeEnter(BeforeEnterEvent event) { - - event.getUI().navigate(UsersSettingsPage.class); +public class SettingsPage extends ForwardingPage { + public SettingsPage() { + super(UsersSettingsPage.class); } } From d0cc311ae943bba77109a8257848add6db3976f5 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Mon, 5 Aug 2024 21:02:19 +0200 Subject: [PATCH 3/3] Use the ForwardingPage for the accounting landing page --- .../gartenplus/ui/content/accounting/AccountingPage.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java b/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java index 873d72b..bb47868 100644 --- a/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java +++ b/src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java @@ -1,5 +1,6 @@ package com.penguineering.gartenplus.ui.content.accounting; +import com.penguineering.gartenplus.ui.appframe.ForwardingPage; import com.penguineering.gartenplus.ui.appframe.GartenplusPage; import com.penguineering.gartenplus.ui.content.accounting.myfinances.MyFinancesPage; import com.vaadin.flow.router.BeforeEnterEvent; @@ -11,10 +12,8 @@ @Route(value = "", layout = AccountingLayout.class) @PermitAll @PageTitle("GartenPlus | Buchhaltung") -public class AccountingPage extends GartenplusPage implements BeforeEnterObserver { - @Override - public void beforeEnter(BeforeEnterEvent event) { - - event.getUI().navigate(MyFinancesPage.class); +public class AccountingPage extends ForwardingPage { + public AccountingPage() { + super(MyFinancesPage.class); } }