PageRenderTime 49ms CodeModel.GetById 20ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/webportal/src/main/java/org/ala/spatial/analysis/web/ContextualMenu.java

http://alageospatialportal.googlecode.com/
Java | 681 lines | 539 code | 79 blank | 63 comment | 179 complexity | bea19a560da581617a480340280e97a1 MD5 | raw file
  1package org.ala.spatial.analysis.web;
  2
  3import au.org.emii.portal.composer.MapComposer;
  4import au.org.emii.portal.composer.UtilityComposer;
  5import au.org.emii.portal.menu.MapLayer;
  6import au.org.emii.portal.settings.SettingsSupplementary;
  7import au.org.emii.portal.util.LayerUtilities;
  8import java.util.ArrayList;
  9import java.util.Hashtable;
 10import java.util.List;
 11import org.ala.spatial.data.Query;
 12import org.ala.spatial.util.ScatterplotData;
 13import org.zkoss.zhtml.Li;
 14import org.zkoss.zhtml.Ul;
 15import org.zkoss.zk.ui.Component;
 16import org.zkoss.zk.ui.event.Event;
 17import org.zkoss.zk.ui.event.EventListener;
 18import org.zkoss.zk.ui.event.Events;
 19import org.zkoss.zul.A;
 20import org.zkoss.zul.Vbox;
 21import org.zkoss.zk.ui.util.Clients;
 22
 23/**
 24 *
 25 * @author ajay
 26 */
 27public class ContextualMenu extends UtilityComposer {
 28
 29    SettingsSupplementary settingsSupplementary;
 30    Vbox contents;
 31
 32    public void refresh() {
 33        for (int i = contents.getChildren().size() - 1; i >= 0; i--) {
 34            ((Component) contents.getChildren().get(i)).detach();
 35        }
 36
 37        ArrayList<Action> actions = getActions();
 38
 39        Ul ul = new Ul();
 40        ul.setStyle("margin:0px");
 41        ul.setParent(contents);
 42
 43        for (int i = 0; i < actions.size(); i++) {
 44            Li li = new Li();
 45            li.setParent(ul);
 46            A a = new A(actions.get(i).label);
 47            a.addEventListener("onClick", actions.get(i).eventListener);
 48            a.setParent(li);
 49        }
 50    }
 51
 52    ArrayList<Action> getActions() {
 53        ArrayList<Action> actions = new ArrayList<Action>();
 54        ArrayList<MapLayer> layers = getVisibleLayers();
 55
 56        MapLayer speciesLayer = null;
 57        MapLayer polygonLayer = null;
 58        MapLayer gridLayer = null;
 59
 60        MapLayer firstLayer = null;
 61        for (int i = 0; i < layers.size() /*&& actions.size() < 5*/; i++) {
 62            if (layers.get(i).getData("query") != null
 63                    && layers.get(i).getSubType() != LayerUtilities.SCATTERPLOT) {
 64                if (speciesLayer == null) {
 65                    speciesLayer = layers.get(i);
 66                }
 67                if (firstLayer == null) {
 68                    firstLayer = layers.get(i);
 69                }
 70            } else if (layers.get(i).isPolygonLayer()
 71                    && layers.get(i).getSubType() != LayerUtilities.ALOC) {
 72                if (polygonLayer == null) {
 73                    polygonLayer = layers.get(i);
 74                }
 75                if (firstLayer == null) {
 76                    firstLayer = layers.get(i);
 77                }
 78            } else if (layers.get(i).isGridLayer()
 79                    && layers.get(i).getSubType() != LayerUtilities.MAXENT
 80                    && layers.get(i).getSubType() != LayerUtilities.GDM
 81                    && layers.get(i).getSubType() != LayerUtilities.ALOC) {
 82                //TODO: grid test
 83                if (gridLayer == null) {
 84                    gridLayer = layers.get(i);
 85                }
 86                if (firstLayer == null) {
 87                    firstLayer = layers.get(i);
 88                }
 89            } else if (layers.get(i).getMapLayerMetadata() != null
 90                    && layers.get(i).getSubType() != LayerUtilities.SCATTERPLOT) {
 91                if (firstLayer == null) {
 92                    firstLayer = layers.get(i);
 93                }
 94            }
 95        }
 96
 97        //actions rules
 98        if (polygonLayer != null) {
 99            actions.add(new Action("View area report for \"" + polygonLayer.getDisplayName() + "\"",
100                    new AreaReportEvent(getMapComposer(), polygonLayer.getName())));
101        }
102        if (firstLayer != null) {
103            actions.add(new Action("View metadata for \"" + firstLayer.getDisplayName() + "\"",
104                    new MetadataEvent(getMapComposer(), firstLayer.getName())));
105        }
106        if (polygonLayer != null) {
107            actions.add(new Action("Download species list for \"" + polygonLayer.getDisplayName() + "\"",
108                    new SpeciesListEvent(getMapComposer(), polygonLayer.getName())));
109        }
110        if (speciesLayer != null) {
111            actions.add(new Action("Download all records for \"" + speciesLayer.getDisplayName() + "\""
112                    + ((polygonLayer != null) ? " in \"" + polygonLayer.getDisplayName() + "\"" : ""),
113                    new SamplingEvent(getMapComposer(), speciesLayer.getName(),
114                    (polygonLayer != null) ? polygonLayer.getName() : null, null)));
115        } else if (polygonLayer != null) {
116            actions.add(new Action("Download all records "
117                    + ((polygonLayer != null) ? " for " + "\"" + polygonLayer.getDisplayName() + "\"" : ""),
118                    new SamplingEvent(getMapComposer(), null, polygonLayer.getName(), null)));
119        }
120        if (polygonLayer != null) {
121            actions.add(new Action("Generate classification for \"" + polygonLayer.getDisplayName() + "\"",
122                    new ClassificationEvent(getMapComposer(), polygonLayer.getName(), null)));
123        }
124        if (speciesLayer != null) {
125            actions.add(new Action("Produce scatterplot for \"" + speciesLayer.getDisplayName() + "\""
126                    + ((polygonLayer != null) ? " in \"" + polygonLayer.getDisplayName() + "\"" : ""),
127                    new ScatterplotEvent(getMapComposer(), speciesLayer.getName(),
128                    (polygonLayer != null) ? polygonLayer.getName() : null, null)));
129        }
130        if (speciesLayer != null) {
131            actions.add(new Action("Generate prediction for \"" + speciesLayer.getDisplayName() + "\""
132                    + ((polygonLayer != null) ? " in \"" + polygonLayer.getDisplayName() + "\"" : ""),
133                    new PredictionEvent(getMapComposer(), speciesLayer.getName(),
134                    (polygonLayer != null) ? polygonLayer.getName() : null, null)));
135        }
136        if (speciesLayer != null) {
137            actions.add(new Action("Produce points to grid for \"" + speciesLayer.getDisplayName() + "\""
138                    + ((polygonLayer != null) ? " in \"" + polygonLayer.getDisplayName() + "\"" : ""),
139                    new SitesBySpeciesEvent(getMapComposer(), speciesLayer.getName(),
140                    (polygonLayer != null) ? polygonLayer.getName() : null, null)));
141        }
142        if (speciesLayer != null) {
143            actions.add(new Action("Produce GDM using species \"" + speciesLayer.getDisplayName() + "\""
144                    + ((polygonLayer != null) ? " in \"" + polygonLayer.getDisplayName() + "\"" : ""),
145                    new GDMEvent(getMapComposer(), speciesLayer.getName(),
146                    (polygonLayer != null) ? polygonLayer.getName() : null, null)));
147        }
148        if (polygonLayer != null) {
149            actions.add(new Action("Export area \"" + polygonLayer.getDisplayName() + "\"",
150                    new ExportAreaEvent(getMapComposer(), polygonLayer.getName())));
151        }
152        if (speciesLayer != null
153                && (speciesLayer == getMapComposer().getActiveLayersSelection(false)
154                || (getMapComposer().getActiveLayersSelection(false) == null && layers != null && speciesLayer == layers.get(0)))) {
155            actions.add(new Action("Display facet of \"" + speciesLayer.getDisplayName() + "\"",
156                    new OpenFacetsEvent(getMapComposer(), speciesLayer.getName())));
157        }
158
159//        if (gridLayer != null) {
160//            //actions.add(new Action("Browse environmental point values for " + gridLayer.getDisplayName(), new GridLayerHoverEvent(getMapComposer(), gridLayer.getName())));
161//            actions.add(new Action("Browse environmental point values", new GridLayerHoverEvent(getMapComposer(), gridLayer.getName())));
162//        }
163//        if (polygonLayer != null) {
164//            //actions.add(new Action("Browse environmental point values for " + gridLayer.getDisplayName(), new GridLayerHoverEvent(getMapComposer(), gridLayer.getName())));
165//            actions.add(new Action("Browse contextual point values", new GridLayerHoverEvent(getMapComposer(), polygonLayer.getName())));
166//        }
167
168        //default actions
169        if (actions.size() == 0) {
170            actions.add(new Action("Map species occurrences", new AddToMap(getMapComposer(), "species")));
171            actions.add(new Action("Map area", new AddToMap(getMapComposer(), "area")));
172            actions.add(new Action("Map layer", new AddToMap(getMapComposer(), "layer")));
173            actions.add(new Action("Map facet", new AddToMap(getMapComposer(), "facet")));
174        }
175
176        return actions;
177    }
178
179    ArrayList<MapLayer> getVisibleLayers() {
180        ArrayList<MapLayer> list = new ArrayList<MapLayer>();
181        List<MapLayer> allLayers = getPortalSession().getActiveLayers();
182        for (int i = 0; i < allLayers.size(); i++) {
183            if (allLayers.get(i).isDisplayed()) {
184                list.add(allLayers.get(i));
185            }
186        }
187
188        return list;
189    }
190}
191
192class Action {
193
194    public String label;
195    public EventListener eventListener;
196
197    //defaults
198    public Action(String label, EventListener eventListener) {
199        this.label = label;
200        this.eventListener = eventListener;
201    }
202}
203
204class SamplingEvent implements EventListener {
205
206    String speciesLayerName;
207    String polygonLayerName;
208    String environmentalLayerName;
209    MapComposer mc;
210    int steps_to_skip;
211    boolean[] geospatialKosher;
212
213    public SamplingEvent(MapComposer mc, String speciesLayerName, String polygonLayerName, String environmentalLayerName) {
214        this.mc = mc;
215        this.speciesLayerName = speciesLayerName;
216        this.polygonLayerName = polygonLayerName;
217        this.environmentalLayerName = environmentalLayerName;
218        this.steps_to_skip = 0;
219        this.geospatialKosher = null;
220    }
221
222    public SamplingEvent(MapComposer mc, String speciesLayerName, String polygonLayerName, String environmentalLayerName, int steps_to_skip, boolean[] geospatialKosher) {
223        this.mc = mc;
224        this.speciesLayerName = speciesLayerName;
225        this.polygonLayerName = polygonLayerName;
226        this.environmentalLayerName = environmentalLayerName;
227        this.steps_to_skip = steps_to_skip;
228        this.geospatialKosher = geospatialKosher;
229    }
230
231    @Override
232    public void onEvent(Event event) throws Exception {
233        Hashtable<String, Object> params = new Hashtable<String, Object>();
234        if (speciesLayerName != null) {
235            params.put("speciesLayerName", speciesLayerName);
236        } else {
237            params.put("speciesLayerName", "none");
238        }
239        if (polygonLayerName != null) {
240            params.put("polygonLayerName", polygonLayerName);
241        } else {
242            params.put("polygonLayerName", "none");
243        }
244        if (environmentalLayerName != null) {
245            params.put("environmentalLayerName", environmentalLayerName);
246        } else {
247            params.put("environmentalLayerName", "none");
248        }
249        AddToolSamplingComposer window = (AddToolSamplingComposer) mc.openModal("WEB-INF/zul/AddToolSampling.zul", params, "addtoolwindow");
250
251        window.setGeospatialKosherCheckboxes(geospatialKosher);
252
253        int skip = steps_to_skip;
254        while (skip > 0) {
255            window.onClick$btnOk(event);
256            skip--;
257        }
258        //window.onClick$btnOk(event);
259        //window.onClick$btnOk(event);
260    }
261}
262
263class PredictionEvent implements EventListener {
264
265    String speciesLayerName;
266    String polygonLayerName;
267    String environmentalLayerName;
268    MapComposer mc;
269
270    public PredictionEvent(MapComposer mc, String speciesLayerName, String polygonLayerName, String environmentalLayerName) {
271        this.mc = mc;
272        this.speciesLayerName = speciesLayerName;
273        this.polygonLayerName = polygonLayerName;
274        this.environmentalLayerName = environmentalLayerName;
275    }
276
277    @Override
278    public void onEvent(Event event) throws Exception {
279        Hashtable<String, Object> params = new Hashtable<String, Object>();
280        if (speciesLayerName != null) {
281            params.put("speciesLayerName", speciesLayerName);
282        } else {
283            params.put("speciesLayerName", "none");
284        }
285        if (polygonLayerName != null) {
286            params.put("polygonLayerName", polygonLayerName);
287        } else {
288            params.put("polygonLayerName", "none");
289        }
290        if (environmentalLayerName != null) {
291            params.put("environmentalLayerName", environmentalLayerName);
292        } else {
293            params.put("environmentalLayerName", "none");
294        }
295        AddToolMaxentComposer window = (AddToolMaxentComposer) mc.openModal("WEB-INF/zul/AddToolMaxent.zul", params, "addtoolwindow");
296        //window.onClick$btnOk(event);
297        //window.onClick$btnOk(event);
298    }
299}
300
301class GDMEvent implements EventListener {
302
303    String speciesLayerName;
304    String polygonLayerName;
305    String environmentalLayerName;
306    MapComposer mc;
307
308    public GDMEvent(MapComposer mc, String speciesLayerName, String polygonLayerName, String environmentalLayerName) {
309        this.mc = mc;
310        this.speciesLayerName = speciesLayerName;
311        this.polygonLayerName = polygonLayerName;
312        this.environmentalLayerName = environmentalLayerName;
313    }
314
315    @Override
316    public void onEvent(Event event) throws Exception {
317        Hashtable<String, Object> params = new Hashtable<String, Object>();
318        if (speciesLayerName != null) {
319            params.put("speciesLayerName", speciesLayerName);
320        } else {
321            params.put("speciesLayerName", "none");
322        }
323        if (polygonLayerName != null) {
324            params.put("polygonLayerName", polygonLayerName);
325        } else {
326            params.put("polygonLayerName", "none");
327        }
328        if (environmentalLayerName != null) {
329            params.put("environmentalLayerName", environmentalLayerName);
330        } else {
331            params.put("environmentalLayerName", "none");
332        }
333        AddToolGDMComposer window = (AddToolGDMComposer) mc.openModal("WEB-INF/zul/AddToolGDM.zul", params, "addtoolwindow");
334        //window.onClick$btnOk(event);
335        //window.onClick$btnOk(event);
336    }
337}
338
339class ClassificationEvent implements EventListener {
340
341    String polygonLayerName;
342    String environmentalLayerName;
343    MapComposer mc;
344
345    public ClassificationEvent(MapComposer mc, String polygonLayerName, String environmentalLayerName) {
346        this.mc = mc;
347        this.polygonLayerName = polygonLayerName;
348        this.environmentalLayerName = environmentalLayerName;
349    }
350
351    @Override
352    public void onEvent(Event event) throws Exception {
353        Hashtable<String, Object> params = new Hashtable<String, Object>();
354        if (polygonLayerName != null) {
355            params.put("polygonLayerName", polygonLayerName);
356        } else {
357            params.put("polygonLayerName", "none");
358        }
359        if (environmentalLayerName != null) {
360            params.put("environmentalLayerName", environmentalLayerName);
361        } else {
362            params.put("environmentalLayerName", "none");
363        }
364        AddToolALOCComposer window = (AddToolALOCComposer) mc.openModal("WEB-INF/zul/AddToolALOC.zul", params, "addtoolwindow");
365        //window.onClick$btnOk(event);
366    }
367}
368
369class ScatterplotEvent implements EventListener {
370
371    String speciesLayerName;
372    String polygonLayerName;
373    String environmentalLayerName;
374    MapComposer mc;
375
376    public ScatterplotEvent(MapComposer mc, String speciesLayerName, String polygonLayerName, String environmentalLayerName) {
377        this.mc = mc;
378        this.speciesLayerName = speciesLayerName;
379        this.polygonLayerName = polygonLayerName;
380        this.environmentalLayerName = environmentalLayerName;
381    }
382
383    @Override
384    public void onEvent(Event event) throws Exception {
385        Hashtable<String, Object> params = new Hashtable<String, Object>();
386        if (speciesLayerName != null) {
387            params.put("speciesLayerName", speciesLayerName);
388        } else {
389            params.put("speciesLayerName", "none");
390        }
391        if (polygonLayerName != null) {
392            params.put("polygonLayerName", polygonLayerName);
393        } else {
394            params.put("polygonLayerName", "none");
395        }
396        if (environmentalLayerName != null) {
397            params.put("environmentalLayerName", environmentalLayerName);
398        } else {
399            params.put("environmentalLayerName", "default");
400        }
401        AddToolComposer window = (AddToolComposer) mc.openModal("WEB-INF/zul/AddToolScatterplot.zul", params, "addtoolwindow");
402        //window.onClick$btnOk(event);
403        //window.onClick$btnOk(event);
404    }
405}
406
407class SitesBySpeciesEvent implements EventListener {
408
409    String speciesLayerName;
410    String polygonLayerName;
411    String environmentalLayerName;
412    MapComposer mc;
413
414    public SitesBySpeciesEvent(MapComposer mc, String speciesLayerName, String polygonLayerName, String environmentalLayerName) {
415        this.mc = mc;
416        this.speciesLayerName = speciesLayerName;
417        this.polygonLayerName = polygonLayerName;
418        this.environmentalLayerName = environmentalLayerName;
419    }
420
421    @Override
422    public void onEvent(Event event) throws Exception {
423        Hashtable<String, Object> params = new Hashtable<String, Object>();
424        if (speciesLayerName != null) {
425            params.put("speciesLayerName", speciesLayerName);
426        } else {
427            params.put("speciesLayerName", "none");
428        }
429        if (polygonLayerName != null) {
430            params.put("polygonLayerName", polygonLayerName);
431        } else {
432            params.put("polygonLayerName", "none");
433        }
434        if (environmentalLayerName != null) {
435            params.put("environmentalLayerName", environmentalLayerName);
436        } else {
437            params.put("environmentalLayerName", "default");
438        }
439        AddToolComposer window = (AddToolComposer) mc.openModal("WEB-INF/zul/AddToolSitesBySpecies.zul", params, "addtoolwindow");
440        //window.onClick$btnOk(event);
441        //window.onClick$btnOk(event);
442    }
443}
444
445class SpeciesListEvent implements EventListener {
446
447    String polygonLayerName;
448    MapComposer mc;
449    int steps_to_skip;
450    boolean[] geospatialKosher;
451    boolean chooseEndemic =false;
452    String extraParams;
453
454    public SpeciesListEvent(MapComposer mc, String polygonLayerName) {
455        this.mc = mc;
456        this.polygonLayerName = polygonLayerName;
457        this.steps_to_skip = 0;
458        this.geospatialKosher = null;
459    }
460    public SpeciesListEvent(MapComposer mc, String polygonLayerName, int steps_to_skip, boolean[] geospatialKosher){
461        this(mc, polygonLayerName, steps_to_skip, geospatialKosher,false);
462    }
463    public SpeciesListEvent(MapComposer mc, String polygonLayerName, int steps_to_skip, boolean[] geospatialKosher, boolean chooseEndemic ) {
464        this(mc, polygonLayerName, steps_to_skip, geospatialKosher, chooseEndemic, null);
465    }
466    public SpeciesListEvent(MapComposer mc, String polygonLayerName, int steps_to_skip, boolean[] geospatialKosher, boolean chooseEndemic, String extraParams ) {
467        this.mc = mc;
468        this.polygonLayerName = polygonLayerName;
469        this.steps_to_skip = steps_to_skip;
470        this.geospatialKosher = geospatialKosher;
471        this.chooseEndemic = chooseEndemic;
472        this.extraParams = extraParams;
473    }
474
475    @Override
476    public void onEvent(Event event) throws Exception {
477        Hashtable<String, Object> params = new Hashtable<String, Object>();
478        if (polygonLayerName != null) {
479            params.put("polygonLayerName", polygonLayerName);
480        } else {
481            params.put("polygonLayerName", "none");
482        }
483        if(extraParams != null){
484            params.put("extraParams", extraParams);
485        }
486        AddToolSpeciesListComposer window = (AddToolSpeciesListComposer) mc.openModal("WEB-INF/zul/AddToolSpeciesList.zul", params, "addtoolwindow");
487        window.setGeospatialKosherCheckboxes(geospatialKosher);
488        window.setChooseEndemic(chooseEndemic);
489        
490
491        int skip = steps_to_skip;
492        while (skip > 0) {
493            window.onClick$btnOk(event);
494            skip--;
495        }
496    }
497}
498
499class MetadataEvent implements EventListener {
500
501    String layerName;
502    MapComposer mc;
503
504    public MetadataEvent(MapComposer mc, String layerName) {
505        this.mc = mc;
506        this.layerName = layerName;
507    }
508
509    @Override
510    public void onEvent(Event event) throws Exception {
511        MapLayer mapLayer = mc.getMapLayer(layerName);
512        if (mapLayer != null) {
513            if (mapLayer.getData("query") != null) {
514                //TODO: update for scatterplot layers
515                Query q = (Query) mapLayer.getData("query");
516                Events.echoEvent("openHTML", mc, q.getMetadataHtml());
517            } else if (mapLayer.getMapLayerMetadata() != null
518                    && mapLayer.getMapLayerMetadata().getMoreInfo() != null
519                    && mapLayer.getMapLayerMetadata().getMoreInfo().startsWith("http://")) {
520                String infourl = mapLayer.getMapLayerMetadata().getMoreInfo().replace("__", ".");
521                if (mapLayer.getSubType() == LayerUtilities.SCATTERPLOT) {
522                    ScatterplotData data = (ScatterplotData) mapLayer.getData("scatterplotData");
523                    infourl += "?dparam=X-Layer:" + data.getLayer1Name();
524                    infourl += "&dparam=Y-Layer:" + data.getLayer2Name();
525                }
526                // send the user to the BIE page for the species
527                Events.echoEvent("openUrl", mc, infourl);
528
529            } else if (mapLayer.getMapLayerMetadata() != null
530                    && mapLayer.getMapLayerMetadata().getMoreInfo() != null
531                    && mapLayer.getMapLayerMetadata().getMoreInfo().length() > 0) {
532                //logger.debug("performing a MapComposer.showMessage for following content " + activeLayer.getMapLayerMetadata().getMoreInfo());
533                Events.echoEvent("openHTML", mc, mapLayer.getMapLayerMetadata().getMoreInfo());
534            } else {
535                //logger.debug("no metadata is available for current layer");
536                mc.showMessage("Metadata currently unavailable");
537            }
538        }
539    }
540}
541
542class OpenFacetsEvent implements EventListener {
543
544    String layerName;
545    MapComposer mc;
546
547    public OpenFacetsEvent(MapComposer mc, String layerName) {
548        this.mc = mc;
549        this.layerName = layerName;
550    }
551
552    @Override
553    public void onEvent(Event event) throws Exception {
554        MapLayer mapLayer = mc.getMapLayer(layerName);
555        if (mapLayer != null) {
556            if (mapLayer.getColourMode().equals("grid")) {
557                mapLayer.setColourMode("-1");
558                mc.updateLayerControls();
559            }
560            Events.echoEvent("openFacets", mc, null);
561        }
562    }
563}
564
565class AreaReportEvent implements EventListener {
566
567    String polygonLayerName;
568    MapComposer mc;
569
570    public AreaReportEvent(MapComposer mc, String polygonLayerName) {
571        this.mc = mc;
572        this.polygonLayerName = polygonLayerName;
573    }
574
575    @Override
576    public void onEvent(Event event) throws Exception {
577        Hashtable<String, Object> params = new Hashtable<String, Object>();
578        if (polygonLayerName != null) {
579            params.put("polygonLayerName", polygonLayerName);
580        } else {
581            params.put("polygonLayerName", "none");
582        }
583        AddToolAreaReportComposer window = (AddToolAreaReportComposer) mc.openModal("WEB-INF/zul/AddToolAreaReport.zul", params, "addtoolwindow");
584
585//        MapLayer ml = mc.getMapLayer(polygonLayerName);
586//        Window w = (Window) mc.getPage().getFellowIfAny("popup_results");
587//        if (w != null) {
588//            w.detach();
589//        }
590//        double[] bbox = null;
591//        if (ml != null && ml.getMapLayerMetadata() != null
592//                && ml.getMapLayerMetadata().getBbox() != null
593//                && ml.getMapLayerMetadata().getBbox().size() == 4) {
594//            bbox = new double[4];
595//            bbox[0] = ml.getMapLayerMetadata().getBbox().get(0);
596//            bbox[1] = ml.getMapLayerMetadata().getBbox().get(1);
597//            bbox[2] = ml.getMapLayerMetadata().getBbox().get(2);
598//            bbox[3] = ml.getMapLayerMetadata().getBbox().get(3);
599//        }
600//        FilteringResultsWCController.open(ml.getWKT(), ml.getName(), ml.getDisplayName(), (String) ml.getData("area"), bbox);
601    }
602}
603
604class ExportAreaEvent implements EventListener {
605
606    String polygonLayerName;
607    MapComposer mc;
608
609    public ExportAreaEvent(MapComposer mc, String polygonLayerName) {
610        this.mc = mc;
611        this.polygonLayerName = polygonLayerName;
612    }
613
614    @Override
615    public void onEvent(Event event) throws Exception {
616        Hashtable<String, Object> params = new Hashtable<String, Object>();
617        if (polygonLayerName != null) {
618            params.put("polygonLayerName", polygonLayerName);
619        } else {
620            params.put("polygonLayerName", "none");
621        }
622        ExportLayerComposer window = (ExportLayerComposer) mc.openModal("WEB-INF/zul/ExportLayer.zul", params, "addtoolwindow");
623
624//        MapLayer ml = mc.getMapLayer(polygonLayerName);
625//        Window w = (Window) mc.getPage().getFellowIfAny("popup_results");
626//        if (w != null) {
627//            w.detach();
628//        }
629//        double[] bbox = null;
630//        if (ml != null && ml.getMapLayerMetadata() != null
631//                && ml.getMapLayerMetadata().getBbox() != null
632//                && ml.getMapLayerMetadata().getBbox().size() == 4) {
633//            bbox = new double[4];
634//            bbox[0] = ml.getMapLayerMetadata().getBbox().get(0);
635//            bbox[1] = ml.getMapLayerMetadata().getBbox().get(1);
636//            bbox[2] = ml.getMapLayerMetadata().getBbox().get(2);
637//            bbox[3] = ml.getMapLayerMetadata().getBbox().get(3);
638//        }
639//        FilteringResultsWCController.open(ml.getWKT(), ml.getName(), ml.getDisplayName(), (String) ml.getData("area"), bbox);
640    }
641}
642
643class GridLayerHoverEvent implements EventListener {
644
645    MapComposer mc;
646    String layerName;
647
648    public GridLayerHoverEvent(MapComposer mc, String layerName) {
649        this.mc = mc;
650        this.layerName = layerName;
651    }
652
653    @Override
654    public void onEvent(Event event) throws Exception {
655        Clients.evalJavaScript("mapFrame.toggleActiveHover();");
656    }
657}
658
659class AddToMap implements EventListener {
660
661    String type;
662    MapComposer mc;
663
664    public AddToMap(MapComposer mc, String type) {
665        this.mc = mc;
666        this.type = type;
667    }
668
669    @Override
670    public void onEvent(Event event) throws Exception {
671        if (type.equals("species")) {
672            mc.onClick$btnAddSpecies(null);
673        } else if (type.equals("area")) {
674            mc.onClick$btnAddArea(null);
675        } else if (type.equals("layer")) {
676            mc.onClick$btnAddLayer(null);
677        } else if (type.equals("facet")) {
678            mc.onClick$btnAddFacet(null);
679        }
680    }
681}