easyApp
Build quick application with easy app.
Vaadin-EasyApp
EasyApp builds a ready to use application container.
- Create you views in a dedicated package
- Decorate it with annotations.
Do not care about the UI layout, easyApp will do for you.
Start me with docker : https://hub.docker.com/repository/docker/igolus/easyapp-demo
Sample code
package org.vaadin.easyApp.demo; import java.util.Collections; import org.vaadin.easyapp.EasyAppBuilder; import org.vaadin.easyapp.EasyAppMainView; import org.vaadin.easyapp.event.SearchTrigger; import org.vaadin.easyapp.ui.ViewWithToolBar; import org.vaadin.easyapp.util.ActionContainerBuilder; import org.vaadin.easyapp.util.ActionContainer.InsertPosition; import org.vaadin.easyapp.util.ActionContainer.Position; import com.vaadin.annotations.Push; import com.vaadin.annotations.Theme; import com.vaadin.icons.VaadinIcons; import com.vaadin.server.ThemeResource; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Image; import com.vaadin.ui.Notification; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; /** * VAAIN Easy APP sample */ @Push @Theme("mytheme") public class AddonDemoApplication extends UI { /** * */ private static final long serialVersionUID = 1L; private EasyAppMainView easyAppMainView; @Override protected void init(VaadinRequest vaadinRequest) { final VerticalLayout layout = new VerticalLayout(); layout.setSizeFull(); Image image = new Image(null, new ThemeResource("LogoMakr_7ZbveE.png")); image.setWidth(40, Unit.PIXELS); image.setHeight(40, Unit.PIXELS); //use the package where the views are defined EasyAppBuilder easyAppBuilder = new EasyAppBuilder(Collections.singletonList("org.vaadin.easyApp.demo.view")); easyAppBuilder.withNavigationIcon(image); easyAppBuilder.withTopBarIcon(image); easyAppBuilder.withRessourceBundle(null); easyAppBuilder.withNavigatorStyle("Nav"); easyAppBuilder.withNavigationButtonSelectedStyle("Selected"); easyAppBuilder.withContentStyle("Content"); easyAppBuilder.withActionContainerStyle("Container"); easyAppBuilder.withNavigatorSplitPosition(300); easyAppBuilder.withMenuCollapsable(); easyAppBuilder.withTopBarStyle("TopBar"); easyAppBuilder.withApplicationTitle("EasyApp Laboratory"); easyAppBuilder.withContextualTextLabelStyle("Contextual"); easyAppBuilder.withMenuCollapsable(); ActionContainerBuilder actionContainerBuilder = new ActionContainerBuilder(null); actionContainerBuilder.addImageIcon(image, Position.LEFT, null); actionContainerBuilder.addSearch(this::searchTriggered, Position.RIGHT, null); easyAppBuilder.withActionContainer(actionContainerBuilder.build()); layout.addComponents(easyAppBuilder.build(this)); easyAppMainView = easyAppBuilder.getMainView(); setContent(layout); } public boolean always() { return true; } public void searchTriggered(String search) { Notification.show("Search to be implemented"); } }
package org.vaadin.easyApp.demo.view; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URI; import java.net.URLEncoder; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.log4j.Logger; import org.json.JSONObject; import org.vaadin.easyApp.demo.DemoLayout; import org.vaadin.easyapp.util.ActionContainer; import org.vaadin.easyapp.util.ActionContainer.InsertPosition; import org.vaadin.easyapp.util.ActionContainer.Position; import org.vaadin.easyapp.util.ActionContainerBuilder; import org.vaadin.easyapp.util.annotations.ContentView; import com.vaadin.icons.VaadinIcons; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.tapio.googlemaps.GoogleMap; import com.vaadin.tapio.googlemaps.client.LatLon; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Component; import com.vaadin.ui.Label; import com.vaadin.ui.TextField; //MapRoot.class is the accordion container where this component should be placed @ContentView(sortingOrder=1, viewName = "GoogleMaps", icon = "MAP_MARKER", rootViewParent = MapRoot.class) @SuppressWarnings("serial") public class GoogleMaps extends DemoLayout { //Please get you own key from https://developers.google.com/maps/documentation/javascript/get-api-key private static final String GOOGLE_KEY = "AIzaSyCWrgCsop8-1HEYJdp5QVZl6cR7ShzfMDc"; private GoogleMap googleMap; private TextField searchTextField; private static Logger logger = Logger.getLogger(GoogleMaps.class); public GoogleMaps() { super(); } @Override public Component getComponent() { googleMap = new GoogleMap(GOOGLE_KEY, null, "english"); googleMap.setSizeFull(); googleMap.addMarker("DRAGGABLE: Paavo Nurmi Stadion", new LatLon( 60.442423, 22.26044), true, "VAADIN/1377279006_stadium.png"); googleMap.addMarker("DRAGGABLE: Kakolan vankila", new LatLon(60.44291, 22.242415), true, null); googleMap.addMarker("NOT DRAGGABLE: Iso-Heikkilä", new LatLon( 60.450403, 22.230399), false, null); googleMap.setMinZoom(4); googleMap.setMaxZoom(16); googleMap.setSizeFull(); return googleMap; } public void enterInView(ViewChangeEvent event) { //when entering in the view } @Override public String getVaadinHomeUrl() { return "https://vaadin.com/directory/component/googlemaps-add-on"; } public ActionContainer buildTargetActionContainer() { //This is how we can add interactive components in the view //Add a button targeting search method ActionContainerBuilder builder = new ActionContainerBuilder(null) .addButton(VaadinIcons.SEARCH, this::search, Position.RIGHT); searchTextField = new TextField(); //add the text field builder.addComponent(searchTextField, Position.RIGHT, InsertPosition.BEFORE); Label label = new Label("Search somewhere: "); builder.addComponent(label, Position.RIGHT, InsertPosition.BEFORE); return builder.build(); } /** * Click on search * @param event */ public void search(ClickEvent event) { //use google API URI uri; try { uri = new URIBuilder() .setScheme("https") .setHost("maps.googleapis.com") .setPath("/maps/api/geocode/json") .setParameter("address", URLEncoder.encode(searchTextField.getValue(), "UTF-8")) .setParameter("key", GOOGLE_KEY) .build(); HttpGet httpget = new HttpGet(uri); HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(httpget); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } JSONObject obj = new JSONObject(result.toString()); double limitNElat =obj.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("bounds") .getJSONObject("northeast").getDouble("lat"); double limitNElng = obj.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("bounds") .getJSONObject("northeast").getDouble("lng"); double limitSWlat =obj.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("bounds") .getJSONObject("southwest").getDouble("lat"); double limitSWlng =obj.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("bounds") .getJSONObject("southwest").getDouble("lng"); googleMap.fitToBounds(new LatLon(limitNElat, limitNElng), new LatLon(limitSWlat, limitSWlng)); } catch (Exception e) { logger.error("Unable to get location", e); } } @Override public String getTitle() { return "GoogleMaps"; } }
package org.vaadin.easyApp.demo.view; import org.vaadin.easyapp.util.annotations.RootView; //define the accordion container @RootView(sortingOrder=1, viewName = "Map", icon = "BULLSEYE") public class MapRoot { }
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
- Released
- 2020-02-21
- Maturity
- EXPERIMENTAL
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 8.0+
- Vaadin 7.7+ in 1.0-beta
- Browser
- Firefox
- Google Chrome