From dc96788bb924c247c5c916bbe7d34c9713fff855 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Wed, 6 Sep 2023 16:37:59 +0300 Subject: [PATCH] Added Directory link to add-on demos closes #3 --- src/main/java/org/example/Addon.java | 17 +++++++++++++++++ src/main/java/org/example/DefaultLayout.java | 13 +++++++++---- src/main/java/org/example/views/AboutView.java | 2 ++ .../java/org/example/views/MapLibreView.java | 5 +++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/example/Addon.java diff --git a/src/main/java/org/example/Addon.java b/src/main/java/org/example/Addon.java new file mode 100644 index 0000000..fedb44f --- /dev/null +++ b/src/main/java/org/example/Addon.java @@ -0,0 +1,17 @@ +package org.example; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE}) +public @interface Addon { + + /** + * @return The unifying url of the add-on in the Directory + */ + String value(); + +} diff --git a/src/main/java/org/example/DefaultLayout.java b/src/main/java/org/example/DefaultLayout.java index dac6bc7..043d52a 100644 --- a/src/main/java/org/example/DefaultLayout.java +++ b/src/main/java/org/example/DefaultLayout.java @@ -2,12 +2,14 @@ import com.vaadin.flow.component.Component; import com.vaadin.flow.component.html.Anchor; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.dom.Style; import org.vaadin.firitin.appframework.MainLayout; public class DefaultLayout extends MainLayout { Anchor viewSource = new Anchor("", "View source..."); + Anchor viewAddon = new Anchor("", "Directory page"); @Override protected String getDrawerHeader() { @@ -22,11 +24,14 @@ public void setContent(Component content) { super.setContent(content); String name = content.getClass().getName(); viewSource.setHref(baseSourceUrl.formatted(name.replace(".", "/"))); + String addonId = content.getClass().getAnnotation(Addon.class).value(); + viewAddon.setHref("https://vaadin.com/directory/component/%s".formatted(addonId)); if(!viewSource.isAttached()) { - viewSource.getStyle().setPosition(Style.Position.ABSOLUTE); - viewSource.getStyle().setRight("1em"); - viewSource.getStyle().setTop("1em"); - addToNavbar(true, viewSource); + HorizontalLayout links = new HorizontalLayout(viewSource, viewAddon); + links.getStyle().setPosition(Style.Position.ABSOLUTE); + links.getStyle().setRight("1em"); + links.getStyle().setTop("1em"); + addToNavbar(true, links); } } } diff --git a/src/main/java/org/example/views/AboutView.java b/src/main/java/org/example/views/AboutView.java index 1a0b3da..eb08c8c 100644 --- a/src/main/java/org/example/views/AboutView.java +++ b/src/main/java/org/example/views/AboutView.java @@ -4,10 +4,12 @@ import com.vaadin.flow.component.html.Paragraph; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.router.Route; +import org.example.Addon; import org.example.DefaultLayout; import org.vaadin.firitin.components.RichText; @Route(value = "", layout = DefaultLayout.class) +@Addon("flow-viritin") public class AboutView extends VerticalLayout { public AboutView() { diff --git a/src/main/java/org/example/views/MapLibreView.java b/src/main/java/org/example/views/MapLibreView.java index 08aa53d..b811dd9 100644 --- a/src/main/java/org/example/views/MapLibreView.java +++ b/src/main/java/org/example/views/MapLibreView.java @@ -2,9 +2,11 @@ import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.html.Span; +import com.vaadin.flow.component.icon.VaadinIcon; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.router.Route; +import org.example.Addon; import org.example.DefaultLayout; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Polygon; @@ -12,6 +14,7 @@ import org.locationtech.jts.io.WKTReader; import org.vaadin.addons.maplibre.MapLibre; import org.vaadin.addons.maplibre.Marker; +import org.vaadin.firitin.appframework.MenuItem; import org.vaadin.firitin.components.RichText; import org.vaadin.firitin.components.orderedlayout.VHorizontalLayout; import org.vaadin.firitin.geolocation.Geolocation; @@ -20,6 +23,8 @@ import java.net.URISyntaxException; @Route(layout = DefaultLayout.class) +@MenuItem(title = "MapLibreGL JS", icon = VaadinIcon.MAP_MARKER) +@Addon("maplibregl--add-on") public class MapLibreView extends VerticalLayout { private Marker yourPosition;