Skip to content

Commit

Permalink
Added Directory link to add-on demos
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
mstahv committed Sep 6, 2023
1 parent 741cf75 commit dc96788
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/example/Addon.java
Original file line number Diff line number Diff line change
@@ -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();

}
13 changes: 9 additions & 4 deletions src/main/java/org/example/DefaultLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/example/views/AboutView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/example/views/MapLibreView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

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;
import org.locationtech.jts.io.ParseException;
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;
Expand All @@ -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;
Expand Down

0 comments on commit dc96788

Please sign in to comment.