/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

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