Skip to content

Commit

Permalink
demo refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor committed Mar 20, 2020
1 parent c9bdd15 commit bf28b44
Show file tree
Hide file tree
Showing 31 changed files with 221 additions and 197 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Maven files
target/

# Visual Studio Code
.vscode

# Eclipse files
.project
.settings
Expand Down
24 changes: 8 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.vaadin</groupId>
<artifactId>leaflet4vaadin</artifactId>
<version>0.2.5-beta</version>
<version>0.2.6-beta</version>
<name>Leaflet4Vaadin</name>
<description>Integration of Leaflet map for Vaadin platform LTS 14</description>
<scm>
Expand Down Expand Up @@ -168,11 +166,6 @@
<artifactId>vaadin-testbench</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.appreciated</groupId>
<artifactId>app-layout-addon</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -339,6 +332,7 @@
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
</goals>
</execution>
Expand Down Expand Up @@ -476,7 +470,7 @@
<executions>
<execution>
<id>copy-test-libs</id>
<phase>package</phase>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
Expand Down Expand Up @@ -510,7 +504,7 @@
</manifestEntries>
</archive>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archiveClasses>true</archiveClasses>
<archiveClasses>false</archiveClasses>
<webResources>
<resource>
<directory>${basedir}/src/test/resources</directory>
Expand All @@ -520,10 +514,6 @@
<directory>${project.build.directory}/classes/META-INF/VAADIN</directory>
<targetPath>WEB-INF/classes/META-INF/VAADIN</targetPath>
</resource>
<resource>
<directory>${project.build.directory}/frontend</directory>
<targetPath>frontend</targetPath>
</resource>
<resource>
<directory>${project.build.directory}/test-classes</directory>
<targetPath>WEB-INF/classes</targetPath>
Expand Down Expand Up @@ -567,7 +557,9 @@
<execution>
<id>copy-webapp-runner</id>
<phase>package</phase>
<goals><goal>copy</goal></goals>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
Expand Down
155 changes: 103 additions & 52 deletions src/test/java/com/vaadin/addon/leaflet4vaadin/demo/LeafletDemoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@

package com.vaadin.addon.leaflet4vaadin.demo;

import com.github.appreciated.app.layout.annotations.Caption;
import com.github.appreciated.app.layout.component.appbar.AppBarBuilder;
import com.github.appreciated.app.layout.component.applayout.LeftLayouts.LeftResponsiveHybrid;
import com.github.appreciated.app.layout.component.builder.AppLayoutBuilder;
import com.github.appreciated.app.layout.component.menu.left.builder.LeftAppMenuBuilder;
import com.github.appreciated.app.layout.component.menu.left.builder.LeftSubMenuBuilder;
import com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem;
import com.github.appreciated.app.layout.component.router.AppLayoutRouterLayout;
import com.vaadin.addon.leaflet4vaadin.demo.components.ExampleContainer;
import com.vaadin.addon.leaflet4vaadin.demo.view.controls.ControlPositionExample;
import com.vaadin.addon.leaflet4vaadin.demo.view.controls.RemoveDefaultControlsExample;
import com.vaadin.addon.leaflet4vaadin.demo.view.controls.ScaleControlExample;
Expand Down Expand Up @@ -50,77 +41,137 @@
import com.vaadin.addon.leaflet4vaadin.demo.view.path.PathsEventPropagationExample;
import com.vaadin.addon.leaflet4vaadin.demo.view.path.TypeOfPathsExample;
import com.vaadin.addon.leaflet4vaadin.demo.view.plugins.FullScreenPluginExample;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.accordion.Accordion;
import com.vaadin.flow.component.accordion.AccordionPanel;
import com.vaadin.flow.component.applayout.AppLayout;
import com.vaadin.flow.component.applayout.DrawerToggle;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.details.DetailsVariant;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.theme.Theme;
import com.vaadin.flow.theme.lumo.Lumo;

@Route("")
@Theme(value = Lumo.class, variant = Lumo.LIGHT)
public class LeafletDemoApp extends AppLayoutRouterLayout<LeftResponsiveHybrid> {
public class LeafletDemoApp extends AppLayout {

private static final long serialVersionUID = -9119767347112138141L;

public LeafletDemoApp() {
addToNavbar(true, new DrawerToggle());

// Leaflet Icon
Image image = new Image("https://leafletjs.com/docs/images/logo.png", "icon");
image.setHeight("30px");
image.getStyle().set("margin", "10px");
image.addClickListener((e) -> UI.getCurrent().getPage().setLocation("https://leafletjs.com/"));
addToNavbar(image);

// External links in navbar
initActionButtons();

// Application menubar
initializeDemoMenu();
}

private void initActionButtons() {
HorizontalLayout actions = new HorizontalLayout();
actions.setPadding(true);
actions.setWidthFull();
actions.setJustifyContentMode(JustifyContentMode.END);

// Vaadin directory button
Button directoryButton = new Button("Vaddin directory", new Icon(VaadinIcon.VAADIN_H));
directoryButton.addClickListener(
(e) -> UI.getCurrent().getPage().setLocation("https://vaadin.com/directory/component/leaflet4vaadin"));
directoryButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY, ButtonVariant.LUMO_ERROR);

// Github button
Button githubButton = new Button("Github");
githubButton.addClickListener(
(e) -> UI.getCurrent().getPage().setLocation("https://github.com/Gubancs/leaflet4vaadin"));
githubButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
actions.add(directoryButton, githubButton);

Image image = new Image("https://leafletjs.com/docs/images/logo.png", "icon");
image.setHeight("var(--app-layout-menu-button-height)");
image.getStyle().set("margin", "var(--app-layout-space-s)");
image.addClickListener((e) -> UI.getCurrent().getPage().setLocation("https://leafletjs.com/"));

init(AppLayoutBuilder.get(LeftResponsiveHybrid.class).withTitle("Vaadin 14 - Leaflet examples")
.withAppBar(AppBarBuilder.get().add(actions).build()).withIconComponent(image)
.withAppMenu(LeftAppMenuBuilder.get()
.add(LeftSubMenuBuilder.get("Map", new Icon(VaadinIcon.GLOBE))
.add(menuItem(MapEventsExample.class)).add(menuItem(MapDarkThemeExample.class))
.add(menuItem(MapPollListenerExample.class)).add(menuItem(MapFunctionsExample.class))
.add(menuItem(MapGeolocationExample.class))
.add(menuItem(MapConversionMethodsExample.class))
.build())
.add(LeftSubMenuBuilder.get("Markers", new Icon(VaadinIcon.MAP_MARKER))
.add(menuItem(MarkersSimpleExample.class)).add(menuItem(MarkersWithEventsExample.class))
.add(menuItem(MarkersAddAndRemoveExample.class))
.add(menuItem(MarkersChangingIconExample.class))
.add(menuItem(MarkersGroupExample.class)).add(menuItem(MarkersEventsExample.class))
.add(menuItem(MarkersRemoveOnClickExample.class))
.add(menuItem(MarkerMethodCallExample.class)).build())
.add(LeftSubMenuBuilder.get("Paths", new Icon(VaadinIcon.PUZZLE_PIECE))
.add(menuItem(PathSimpleExample.class)).add(menuItem(TypeOfPathsExample.class))
.add(menuItem(Paths3000Example.class)).add(menuItem(PathsEventPropagationExample.class))
.add(menuItem(FlyToPolygonBoundsExample.class)).build())
.add(LeftSubMenuBuilder.get("Controls", new Icon(VaadinIcon.CROSSHAIRS))
.add(menuItem(RemoveDefaultControlsExample.class))
.add(menuItem(ControlPositionExample.class)).add(menuItem(ScaleControlExample.class))
.build())
.add(LeftSubMenuBuilder.get("Layers", new Icon(VaadinIcon.GRID_BIG))
.add(menuItem(TileLayerExample.class)).add(menuItem(MultipleBaseLayersExample.class))
.add(menuItem(GeoJSONLayerExample.class)).build())
.add(LeftSubMenuBuilder.get("Mixin", new Icon(VaadinIcon.EYE))
.add(menuItem(WorldMapFlagsExample.class)).build())
.add(LeftSubMenuBuilder.get("Plugins", new Icon(VaadinIcon.PLUG))
.add(menuItem(FullScreenPluginExample.class)).build())
.withStickyFooter().build())
.build());
addToNavbar(actions);

}

public LeftNavigationItem menuItem(Class<? extends ExampleContainer> view) {
return new LeftNavigationItem(view.getAnnotation(Caption.class).value(), new Icon("lumo", "space"), view);
private void initializeDemoMenu() {
Accordion accordion = new Accordion();

// Map examples
MenuItem.create("Map").addSubMenu(MapEventsExample.class).addSubMenu(MapDarkThemeExample.class)
.addSubMenu(MapPollListenerExample.class).addSubMenu(MapGeolocationExample.class)
.addSubMenu(MapFunctionsExample.class).addSubMenu(MapConversionMethodsExample.class).addTo(accordion);

// Marker examples
MenuItem.create("Markers").addSubMenu(MarkersSimpleExample.class).addSubMenu(MarkersEventsExample.class)
.addSubMenu(MarkersWithEventsExample.class).addSubMenu(MarkersGroupExample.class)
.addSubMenu(MarkersAddAndRemoveExample.class).addSubMenu(MarkersChangingIconExample.class)
.addSubMenu(MarkersRemoveOnClickExample.class).addSubMenu(MarkerMethodCallExample.class)
.addTo(accordion);

// Layers examples
MenuItem.create("Layers").addSubMenu(TileLayerExample.class).addSubMenu(MultipleBaseLayersExample.class)
.addSubMenu(GeoJSONLayerExample.class).addTo(accordion);

// Paths examples
MenuItem.create("Paths").addSubMenu(PathSimpleExample.class).addSubMenu(TypeOfPathsExample.class)
.addSubMenu(PathsEventPropagationExample.class).addSubMenu(FlyToPolygonBoundsExample.class)
.addSubMenu(Paths3000Example.class).addTo(accordion);

// Controls examples
MenuItem.create("Controls").addSubMenu(RemoveDefaultControlsExample.class)
.addSubMenu(ControlPositionExample.class).addSubMenu(ScaleControlExample.class).addTo(accordion);

// Mixins examples
MenuItem.create("Mixin").addSubMenu(WorldMapFlagsExample.class).addTo(accordion);

// Plugins examples
MenuItem.create("Plugins").addSubMenu(FullScreenPluginExample.class).addTo(accordion);

addToDrawer(accordion);
}

private static class MenuItem extends VerticalLayout {

private static final long serialVersionUID = 6428270908323350266L;
private final String title;

public MenuItem(String title) {
this.title = title;
setSpacing(false);
setPadding(false);
}

public AccordionPanel addTo(Accordion accordion) {
AccordionPanel menuPanel = new AccordionPanel(title, this);
menuPanel.addThemeVariants(DetailsVariant.FILLED, DetailsVariant.REVERSE);
accordion.add(menuPanel);
return menuPanel;
}

public MenuItem addSubMenu(Class<? extends Component> navigationTarget) {
Button menuButton = new Button(navigationTarget.getAnnotation(PageTitle.class).value());
menuButton.setWidthFull();
menuButton.addThemeVariants(ButtonVariant.LUMO_SMALL);
menuButton.addClickListener((event) -> UI.getCurrent().navigate(navigationTarget));
add(menuButton);
return this;
}

public static MenuItem create(String title) {
return new MenuItem(title);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package com.vaadin.addon.leaflet4vaadin.demo.components;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand All @@ -24,6 +28,8 @@
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.HasComponents;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.html.Pre;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.tabs.Tab;
Expand All @@ -39,6 +45,7 @@ public abstract class ExampleContainer extends VerticalLayout {
private Tabs tabs = new Tabs();
private Map<Tab, Component> tabsToPages = new HashMap<>();
private Set<Component> pagesShown;
private final String gitHubDir = "https://raw.githubusercontent.com/Gubancs/leaflet4vaadin/master/src/test/java/";

protected ExampleContainer() {
super();
Expand Down Expand Up @@ -83,6 +90,22 @@ protected void initApiContent(HasComponents apiContent) {
}

protected void initSourceContent(HasComponents tabContent) {
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.setSpacing(false);
verticalLayout.setPadding(false);
try {
Pre code = new Pre(getSourceCode());
code.getStyle().set("padding", "30px");
code.getStyle().set("background", "#3a3a3a");
code.getStyle().set("color", "#fff");
code.getStyle().set("font-size", "14px");
code.getStyle().set("-webkit-font-smoothing", "antialiased");
verticalLayout.add(code);
} catch (Exception e) {
verticalLayout.add(new Label("Unable to get source code from GitHub. :("));
e.printStackTrace();
}
tabContent.add(verticalLayout);
}

protected Component initDemoLayout() {
Expand All @@ -96,4 +119,29 @@ protected Component initDemoLayout() {
}

protected abstract void initMap(Div mapContainer);

private String getSourceCode() throws Exception {
URL website = new URL(getGitHubPath());
URLConnection connection = website.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

StringBuilder response = new StringBuilder();
String inputLine;

while ((inputLine = in.readLine()) != null) {
if (inputLine.startsWith("import ") || inputLine.startsWith("// ") || inputLine.startsWith("package ")) {
continue;
}
response.append(inputLine);
response.append("\n");
}

in.close();

return response.toString().trim();
}

private String getGitHubPath() {
return gitHubDir + getClass().getName().replaceAll("\\.", "/") + ".java";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.vaadin.addon.leaflet4vaadin.demo.view.controls;

import com.github.appreciated.app.layout.annotations.Caption;
import com.vaadin.addon.leaflet4vaadin.LeafletMap;
import com.vaadin.addon.leaflet4vaadin.controls.LeafletControl.ControlPosition;
import com.vaadin.addon.leaflet4vaadin.controls.ZoomControl;
Expand All @@ -24,15 +23,13 @@
import com.vaadin.addon.leaflet4vaadin.layer.map.options.MapOptions;
import com.vaadin.addon.leaflet4vaadin.types.LatLng;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

@Caption("Control position")
@PageTitle("Control position")
@Route(value = "controls/positioning", layout = LeafletDemoApp.class)
public class ControlPositionExample extends ExampleContainer {

/**
*
*/
private static final long serialVersionUID = 4742537288905986507L;

@Override
Expand Down
Loading

0 comments on commit bf28b44

Please sign in to comment.