comparison 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
comparison
equal deleted inserted replaced
1376:28eb4dfe2cbf 1377:b0fe35d4ce6b
10 import com.smartgwt.client.widgets.grid.ListGrid; 10 import com.smartgwt.client.widgets.grid.ListGrid;
11 import com.smartgwt.client.widgets.grid.ListGridField; 11 import com.smartgwt.client.widgets.grid.ListGridField;
12 import com.smartgwt.client.widgets.grid.ListGridRecord; 12 import com.smartgwt.client.widgets.grid.ListGridRecord;
13 import com.smartgwt.client.widgets.layout.HLayout; 13 import com.smartgwt.client.widgets.layout.HLayout;
14 import com.smartgwt.client.widgets.layout.VLayout; 14 import com.smartgwt.client.widgets.layout.VLayout;
15 import com.smartgwt.client.widgets.menu.Menu;
16 import com.smartgwt.client.widgets.menu.MenuItem;
17 import com.smartgwt.client.widgets.menu.events.ClickHandler;
18 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
15 19
16 import de.intevation.flys.client.shared.MapUtils; 20 import de.intevation.flys.client.shared.MapUtils;
17 import de.intevation.flys.client.shared.model.AttributedTheme; 21 import de.intevation.flys.client.shared.model.AttributedTheme;
18 import de.intevation.flys.client.shared.model.Collection; 22 import de.intevation.flys.client.shared.model.Collection;
19 import de.intevation.flys.client.shared.model.FacetRecord; 23 import de.intevation.flys.client.shared.model.FacetRecord;
40 44
41 public interface ThemeMovedCallback { 45 public interface ThemeMovedCallback {
42 void onThemeMoved(Theme theme, int oldIdx, int newIdx); 46 void onThemeMoved(Theme theme, int oldIdx, int newIdx);
43 } 47 }
44 48
49 public interface LayerZoomCallback {
50 void onLayerZoom(Theme theme, String extent);
51 }
52
45 53
46 54
47 private FLYSConstants MSG = GWT.create(FLYSConstants.class); 55 private FLYSConstants MSG = GWT.create(FLYSConstants.class);
48 56
49 57
50 protected ActivateCallback activateCallback; 58 protected ActivateCallback activateCallback;
51 protected ThemeMovedCallback themeMovedCallback; 59 protected ThemeMovedCallback themeMovedCallback;
60 protected LayerZoomCallback layerZoomCallback;
52 61
53 62
54 public static final String GRID_FIELD_ACTIVE = "active"; 63 public static final String GRID_FIELD_ACTIVE = "active";
55 public static final String GRID_FIELD_STYLE = "style"; 64 public static final String GRID_FIELD_STYLE = "style";
56 public static final String GRID_FIELD_NAME = "name"; 65 public static final String GRID_FIELD_NAME = "name";
62 public MapThemePanel( 71 public MapThemePanel(
63 Collection collection, 72 Collection collection,
64 OutputMode mode, 73 OutputMode mode,
65 ActivateCallback activateCallback 74 ActivateCallback activateCallback
66 ) { 75 ) {
67 this(collection, mode, activateCallback, null); 76 this(collection, mode, activateCallback, null, null);
68 } 77 }
69 78
70 79
71 public MapThemePanel( 80 public MapThemePanel(
72 Collection collection, 81 Collection collection,
73 OutputMode mode, 82 OutputMode mode,
74 ActivateCallback activateCallback, 83 ActivateCallback activateCallback,
75 ThemeMovedCallback themeMovedCallback 84 ThemeMovedCallback themeMovedCallback,
85 LayerZoomCallback layerZoomCallback
76 ) { 86 ) {
77 super(collection, mode); 87 super(collection, mode);
78 88
79 this.activateCallback = activateCallback; 89 this.activateCallback = activateCallback;
80 this.themeMovedCallback = themeMovedCallback; 90 this.themeMovedCallback = themeMovedCallback;
91 this.layerZoomCallback = layerZoomCallback;
81 92
82 initGrid(); 93 initGrid();
83 initLayout(); 94 initLayout();
84 95
85 updateGrid(); 96 updateGrid();
171 return grid; 182 return grid;
172 } 183 }
173 184
174 185
175 @Override 186 @Override
187 protected Menu getSingleContextMenu(final ListGridRecord[] records) {
188 Menu menu = super.getSingleContextMenu(records);
189
190 MenuItem layerZoom = createLayerZoomItem(records);
191 if (layerZoom != null) {
192 menu.addItem(layerZoom);
193 }
194
195 return menu;
196 }
197
198
199 protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) {
200 final FacetRecord fr = (FacetRecord) recs[0];
201 final AttributedTheme at = (AttributedTheme) fr.getTheme();
202
203 final String extent = at.getAttr("extent");
204
205 if (extent == null || extent.length() == 0) {
206 return null;
207 }
208
209 MenuItem zoom = new MenuItem(MSG.zoomToLayer());
210 zoom.addClickHandler(new ClickHandler() {
211 @Override
212 public void onClick(MenuItemClickEvent evt) {
213 if (layerZoomCallback != null) {
214 layerZoomCallback.onLayerZoom(at, extent);
215 }
216 }
217 });
218
219 return zoom;
220 }
221
222
223 @Override
176 public void activateTheme(Theme theme, boolean active) { 224 public void activateTheme(Theme theme, boolean active) {
177 if (activateCallback != null) { 225 if (activateCallback != null) {
178 activateCallback.activate(theme, active); 226 activateCallback.activate(theme, active);
179 } 227 }
180 228

http://dive4elements.wald.intevation.org