Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapThemePanel.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java@06036bc6fb19 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.types.ListGridFieldType; | |
6 import com.smartgwt.client.util.BooleanCallback; | |
7 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.grid.ListGridField; | |
9 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
10 import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickEvent; | |
11 import com.smartgwt.client.widgets.grid.events.HeaderDoubleClickHandler; | |
12 import com.smartgwt.client.widgets.layout.VLayout; | |
13 import com.smartgwt.client.widgets.menu.Menu; | |
14 import com.smartgwt.client.widgets.menu.MenuItem; | |
15 import com.smartgwt.client.widgets.menu.events.ClickHandler; | |
16 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; | |
17 | |
18 import de.intevation.flys.client.client.FLYSConstants; | |
19 import de.intevation.flys.client.client.ui.CollectionView; | |
20 import de.intevation.flys.client.client.ui.ThemePanel; | |
21 import de.intevation.flys.client.shared.model.AttributedTheme; | |
22 import de.intevation.flys.client.shared.model.FacetRecord; | |
23 import de.intevation.flys.client.shared.model.OutputMode; | |
24 import de.intevation.flys.client.shared.model.Theme; | |
25 | |
26 | |
27 /** | |
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
29 */ | |
30 public class MapThemePanel extends ThemePanel { | |
31 | |
32 public static final int CELL_HEIGHT = 25; | |
33 | |
34 | |
35 public interface ActivateCallback { | |
36 void activate(Theme theme, boolean activate); | |
37 } | |
38 | |
39 | |
40 public interface ThemeMovedCallback { | |
41 void onThemeMoved(Theme theme, int oldIdx, int newIdx); | |
42 } | |
43 | |
44 public interface LayerZoomCallback { | |
45 void onLayerZoom(Theme theme, String extent); | |
46 } | |
47 | |
48 | |
49 | |
50 private FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
51 | |
52 | |
53 protected ActivateCallback activateCallback; | |
54 protected ThemeMovedCallback themeMovedCallback; | |
55 protected LayerZoomCallback layerZoomCallback; | |
56 | |
57 protected ListGridRecord[] oldRecords; | |
58 | |
59 | |
60 public static final String GRID_FIELD_ACTIVE = "active"; | |
61 public static final String GRID_FIELD_NAME = "name"; | |
62 | |
63 | |
64 protected MapOutputTab mapOut; | |
65 | |
66 | |
67 public MapThemePanel( | |
68 CollectionView view, | |
69 OutputMode mode, | |
70 MapOutputTab mapOut, | |
71 ActivateCallback activateCallback, | |
72 ThemeMovedCallback themeMovedCallback, | |
73 LayerZoomCallback layerZoomCallback | |
74 ) { | |
75 super(mode, view); | |
76 | |
77 this.mapOut = mapOut; | |
78 this.activateCallback = activateCallback; | |
79 this.themeMovedCallback = themeMovedCallback; | |
80 this.layerZoomCallback = layerZoomCallback; | |
81 | |
82 initGrid(); | |
83 initLayout(); | |
84 | |
85 updateGrid(); | |
86 } | |
87 | |
88 | |
89 protected void initLayout() { | |
90 setWidth100(); | |
91 setHeight100(); | |
92 | |
93 VLayout layout = new VLayout(); | |
94 layout.setWidth100(); | |
95 layout.setHeight100(); | |
96 | |
97 layout.addMember(list); | |
98 layout.addMember(navigation); | |
99 | |
100 addChild(layout); | |
101 } | |
102 | |
103 | |
104 protected void initGrid() { | |
105 list.setCanEdit(true); | |
106 list.setCanSort(false); | |
107 list.setShowRecordComponents(false); | |
108 list.setShowRecordComponentsByCell(true); | |
109 list.setShowHeader(true); | |
110 list.setShowHeaderContextMenu(false); | |
111 list.setCanReorderFields(false); | |
112 list.setWidth100(); | |
113 list.setHeight100(); | |
114 | |
115 list.addHeaderDoubleClickHandler(new HeaderDoubleClickHandler() { | |
116 @Override | |
117 public void onHeaderDoubleClick(HeaderDoubleClickEvent event) { | |
118 // cancel the event. | |
119 return; | |
120 } | |
121 }); | |
122 | |
123 list.setCellHeight(CELL_HEIGHT); | |
124 list.setShowRecordComponents(true); | |
125 list.setShowRecordComponentsByCell(true); | |
126 list.setShowAllRecords(true); | |
127 | |
128 list.addEditCompleteHandler(this); | |
129 | |
130 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); | |
131 active.setType(ListGridFieldType.BOOLEAN); | |
132 active.setCanDragResize(false); | |
133 | |
134 ListGridField name = new ListGridField( | |
135 GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); | |
136 name.setType(ListGridFieldType.TEXT); | |
137 | |
138 list.setFields(active, name); | |
139 } | |
140 | |
141 | |
142 @Override | |
143 protected void clearGrid() { | |
144 oldRecords = list.getRecords(); | |
145 super.clearGrid(); | |
146 } | |
147 | |
148 | |
149 @Override | |
150 protected void addFacetRecord(FacetRecord rec) { | |
151 Theme newTheme = rec.getTheme(); | |
152 boolean isNew = true; | |
153 | |
154 for (ListGridRecord old: getOldRecords()) { | |
155 FacetRecord fr = (FacetRecord) old; | |
156 | |
157 if (newTheme.equals(fr.getTheme())) { | |
158 isNew = false; | |
159 break; | |
160 } | |
161 } | |
162 | |
163 if (isNew && mapOut != null) { | |
164 mapOut.addLayer(mapOut.createWMSLayer(newTheme)); | |
165 } | |
166 | |
167 super.addFacetRecord(rec); | |
168 } | |
169 | |
170 | |
171 @Override | |
172 protected Menu getSingleContextMenu(final ListGridRecord[] records) { | |
173 Menu menu = super.getSingleContextMenu(records); | |
174 | |
175 MenuItem layerZoom = createLayerZoomItem(records); | |
176 if (layerZoom != null) { | |
177 menu.addItem(layerZoom); | |
178 } | |
179 menu.addItem(createMapURLItem(records)); | |
180 | |
181 return menu; | |
182 } | |
183 | |
184 | |
185 protected MenuItem createMapURLItem(final ListGridRecord[] records) { | |
186 final FacetRecord fr = (FacetRecord) records[0]; | |
187 final AttributedTheme at = (AttributedTheme) fr.getTheme(); | |
188 | |
189 MenuItem item = new MenuItem(MSG.wmsURLMenuItem()); | |
190 item.addClickHandler(new ClickHandler() { | |
191 @Override | |
192 public void onClick(MenuItemClickEvent evt) { | |
193 String url = getMapOutputTab().wmsUrls().get(at.getAttr("layers")); | |
194 SC.say(MSG.wmsURLBoxTitle(), url); | |
195 } | |
196 }); | |
197 | |
198 return item; | |
199 } | |
200 | |
201 | |
202 @Override | |
203 protected MenuItem createRemoveItem(final ListGridRecord[] records) { | |
204 MenuItem item = super.createRemoveItem(records); | |
205 item.addClickHandler(new ClickHandler() { | |
206 @Override | |
207 public void onClick(MenuItemClickEvent evt) { | |
208 SC.ask(MSG.askThemeRemove(), new BooleanCallback() { | |
209 @Override | |
210 public void execute(Boolean value) { | |
211 if (value) { | |
212 for (ListGridRecord record: records) { | |
213 FacetRecord facet = (FacetRecord) record; | |
214 | |
215 Theme theme = facet.getTheme(); | |
216 theme.setVisible(0); | |
217 theme.setActive(0); | |
218 | |
219 AttributedTheme at = (AttributedTheme) theme; | |
220 getMapOutputTab().removeLayer(at.getAttr("layers")); | |
221 } | |
222 | |
223 updateCollection(); | |
224 } | |
225 } | |
226 }); | |
227 } | |
228 }); | |
229 | |
230 return item; | |
231 } | |
232 | |
233 | |
234 protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) { | |
235 final FacetRecord fr = (FacetRecord) recs[0]; | |
236 final AttributedTheme at = (AttributedTheme) fr.getTheme(); | |
237 | |
238 final String extent = at.getAttr("extent"); | |
239 | |
240 if (extent == null || extent.length() == 0) { | |
241 return null; | |
242 } | |
243 | |
244 MenuItem zoom = new MenuItem(MSG.zoomToLayer()); | |
245 zoom.addClickHandler(new ClickHandler() { | |
246 @Override | |
247 public void onClick(MenuItemClickEvent evt) { | |
248 if (layerZoomCallback != null) { | |
249 layerZoomCallback.onLayerZoom(at, extent); | |
250 } | |
251 } | |
252 }); | |
253 | |
254 return zoom; | |
255 } | |
256 | |
257 @Override | |
258 public String getWidthAsString() { | |
259 if(!isVisible()) { | |
260 return "0"; | |
261 } | |
262 else { | |
263 return super.getWidthAsString(); | |
264 } | |
265 } | |
266 | |
267 @Override | |
268 public void activateTheme(Theme theme, boolean active) { | |
269 if (activateCallback != null) { | |
270 activateCallback.activate(theme, active); | |
271 } | |
272 | |
273 theme.setActive(active ? 1 : 0); | |
274 } | |
275 | |
276 | |
277 @Override | |
278 protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) { | |
279 if (themeMovedCallback != null) { | |
280 themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx); | |
281 } | |
282 } | |
283 | |
284 | |
285 protected ListGridRecord[] getOldRecords() { | |
286 return oldRecords != null ? oldRecords : new ListGridRecord[0]; | |
287 } | |
288 | |
289 | |
290 protected MapOutputTab getMapOutputTab() { | |
291 return mapOut; | |
292 } | |
293 } | |
294 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |