Search in sources :

Example 1 with ItemClickListener

use of com.vaadin.ui.components.grid.ItemClickListener in project v-leaflet by mstahv.

the class MapInGridDetailsRow method getTestComponent.

@Override
public Component getTestComponent() {
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    final Grid<String> grid = new Grid<>();
    grid.setSizeFull();
    // Define some columns
    grid.addColumn(r -> r).setCaption("Name");
    grid.addColumn(r -> "").setCaption("Born");
    // Add some data rows
    grid.setItems("Nicolaus Copernicus", "Galileo Galilei", "Johannes Kepler");
    grid.setDetailsGenerator((DetailsGenerator<String>) s -> {
        final LMap leafletMap = new LMap();
        final LTileLayer baselayer = new LTileLayer();
        baselayer.setAttributionString("OpenStreetMap");
        baselayer.setUrl("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
        leafletMap.addLayer(baselayer);
        leafletMap.setWidth("100%");
        leafletMap.setHeight("100px");
        leafletMap.setZoomLevel(3);
        LMarker leafletMarker = new LMarker(-21.54, 30.76);
        leafletMap.addComponent(leafletMarker);
        leafletMap.zoomToContent();
        return leafletMap;
    });
    grid.addItemClickListener((ItemClickListener<String>) event -> grid.setDetailsVisible(event.getItem(), !grid.isDetailsVisible(event.getItem())));
    vl.addComponent(grid);
    return vl;
}
Also used : VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) AbstractTest(org.vaadin.addonhelpers.AbstractTest) DetailsGenerator(com.vaadin.ui.components.grid.DetailsGenerator) Component(com.vaadin.ui.Component) Grid(com.vaadin.ui.Grid) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) Grid(com.vaadin.ui.Grid) VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker)

Aggregations

Component (com.vaadin.ui.Component)1 Grid (com.vaadin.ui.Grid)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1 DetailsGenerator (com.vaadin.ui.components.grid.DetailsGenerator)1 ItemClickListener (com.vaadin.ui.components.grid.ItemClickListener)1 LMap (org.vaadin.addon.leaflet.LMap)1 LMarker (org.vaadin.addon.leaflet.LMarker)1 LTileLayer (org.vaadin.addon.leaflet.LTileLayer)1 AbstractTest (org.vaadin.addonhelpers.AbstractTest)1