Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java @ 1377:b0fe35d4ce6b
Added a 'zoom to layer' menu item to the map theme panel which triggers a zoom to the specific layer/theme.
flys-client/trunk@3122 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 31 Oct 2011 11:52:42 +0000 |
parents | 8a93fb299e64 |
children | 78542ff1f562 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java Fri Oct 28 06:12:51 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java Mon Oct 31 11:52:42 2011 +0000 @@ -12,6 +12,10 @@ import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.menu.Menu; +import com.smartgwt.client.widgets.menu.MenuItem; +import com.smartgwt.client.widgets.menu.events.ClickHandler; +import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; import de.intevation.flys.client.shared.MapUtils; import de.intevation.flys.client.shared.model.AttributedTheme; @@ -42,6 +46,10 @@ void onThemeMoved(Theme theme, int oldIdx, int newIdx); } + public interface LayerZoomCallback { + void onLayerZoom(Theme theme, String extent); + } + private FLYSConstants MSG = GWT.create(FLYSConstants.class); @@ -49,6 +57,7 @@ protected ActivateCallback activateCallback; protected ThemeMovedCallback themeMovedCallback; + protected LayerZoomCallback layerZoomCallback; public static final String GRID_FIELD_ACTIVE = "active"; @@ -64,7 +73,7 @@ OutputMode mode, ActivateCallback activateCallback ) { - this(collection, mode, activateCallback, null); + this(collection, mode, activateCallback, null, null); } @@ -72,12 +81,14 @@ Collection collection, OutputMode mode, ActivateCallback activateCallback, - ThemeMovedCallback themeMovedCallback + ThemeMovedCallback themeMovedCallback, + LayerZoomCallback layerZoomCallback ) { super(collection, mode); this.activateCallback = activateCallback; this.themeMovedCallback = themeMovedCallback; + this.layerZoomCallback = layerZoomCallback; initGrid(); initLayout(); @@ -173,6 +184,43 @@ @Override + protected Menu getSingleContextMenu(final ListGridRecord[] records) { + Menu menu = super.getSingleContextMenu(records); + + MenuItem layerZoom = createLayerZoomItem(records); + if (layerZoom != null) { + menu.addItem(layerZoom); + } + + return menu; + } + + + protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) { + final FacetRecord fr = (FacetRecord) recs[0]; + final AttributedTheme at = (AttributedTheme) fr.getTheme(); + + final String extent = at.getAttr("extent"); + + if (extent == null || extent.length() == 0) { + return null; + } + + MenuItem zoom = new MenuItem(MSG.zoomToLayer()); + zoom.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + if (layerZoomCallback != null) { + layerZoomCallback.onLayerZoom(at, extent); + } + } + }); + + return zoom; + } + + + @Override public void activateTheme(Theme theme, boolean active) { if (activateCallback != null) { activateCallback.activate(theme, active);