use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.
the class ActiveLayersInfoEventListener method onEvent.
@Override
public void onEvent(Event event) throws Exception {
MapComposer mapComposer = getMapComposer(event);
if (mapComposer != null && mapComposer.safeToPerformMapAction()) {
// get reference to the label/image the user clicked on
Component target = event.getTarget();
Listitem listItem = (Listitem) target.getParent().getParent();
MapLayer activeLayer = listItem.getValue();
if (activeLayer != null) {
if (activeLayer.getSpeciesQuery() != null) {
Query q = activeLayer.getSpeciesQuery();
Events.echoEvent(StringConstants.OPEN_HTML, mapComposer, q.getMetadataHtml());
} else if (activeLayer.getMapLayerMetadata().getMoreInfo() != null && activeLayer.getMapLayerMetadata().getMoreInfo().startsWith("http://")) {
String infourl = activeLayer.getMapLayerMetadata().getMoreInfo().replace("__", ".");
if (activeLayer.getSubType() == LayerUtilitiesImpl.SCATTERPLOT) {
ScatterplotDataDTO data = activeLayer.getScatterplotDataDTO();
infourl += "?dparam=X-Layer:" + data.getLayer1Name();
infourl += "&dparam=Y-Layer:" + data.getLayer2Name();
}
// send the user to the BIE page for the species
LOGGER.debug("opening the following url " + infourl);
Events.echoEvent(StringConstants.OPEN_URL, mapComposer, activeLayer.getMapLayerMetadata().getMoreInfo().replace("__", "."));
} else if (activeLayer.getMapLayerMetadata().getMoreInfo() != null && activeLayer.getMapLayerMetadata().getMoreInfo().length() > 0) {
LOGGER.debug("performing a MapComposer.showMessage for following content " + activeLayer.getMapLayerMetadata().getMoreInfo());
String metadata = activeLayer.getMapLayerMetadata().getMoreInfo();
Events.echoEvent(StringConstants.OPEN_HTML, mapComposer, metadata);
} else if (activeLayer.getType() == LayerUtilitiesImpl.MAP) {
String metaurl = "http://www.google.com/intl/en_au/help/terms_maps.html";
if ("outline".equalsIgnoreCase(mapComposer.getPortalSession().getBaseLayer())) {
metaurl = "openstreetmap_metadata.html";
} else if ("minimal".equalsIgnoreCase(mapComposer.getPortalSession().getBaseLayer())) {
metaurl = "http://www.naturalearthdata.com/about/terms-of-use";
}
LOGGER.debug("opening base map metadata for: " + mapComposer.getPortalSession().getBaseLayer() + ", url:" + metaurl);
Events.echoEvent(StringConstants.OPEN_URL, mapComposer, metaurl);
} else {
LOGGER.debug("no metadata is available for current layer");
mapComposer.showMessage("Metadata currently unavailable");
}
}
} else {
LOGGER.debug("MapController reports unsafe to perform action");
}
}
use of au.org.ala.spatial.util.Query in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListResults method populateList.
public void populateList() {
if (selectedArea == null) {
selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
}
try {
Query sq = QueryUtil.queryFromSelectedArea(null, selectedArea, extraParams, false, geospatialKosher);
sq = sq.newFacet(new Facet("occurrence_status_s", "absent", false), false);
if (sq.getSpeciesCount() <= 0) {
getMapComposer().showMessage("No species records in the active area.");
results = null;
popupListboxResults.setVisible(false);
resultsLabel.setVisible(false);
this.detach();
return;
}
// remove header
String speciesList = chooseEndemic ? sq.endemicSpeciesList() : sq.speciesList();
results = speciesList.substring(speciesList.indexOf('\n') + 1).split("\n");
java.util.Arrays.sort(results);
// results should already be sorted
String[] tmp = results;
if (results.length > 200) {
tmp = java.util.Arrays.copyOf(results, 200);
resultsLabel.setValue("preview of first 200 of " + results.length + " species found");
} else {
resultsLabel.setValue("preview of all " + results.length + " species found");
}
popupListboxResults.setModel(new ListModelArray(tmp, false));
popupListboxResults.setItemRenderer(new ListitemRenderer() {
public void render(Listitem li, Object data, int itemIdx) {
String s = (String) data;
CSVReader reader = new CSVReader(new StringReader(s));
String[] ss;
try {
ss = reader.readNext();
} catch (Exception e) {
ss = new String[0];
}
if (ss == null || ss.length == 0) {
return;
}
Listcell lc = new Listcell(ss[0]);
lc.setParent(li);
int col = 1;
while (col < ss.length) {
lc = new Listcell(ss[col]);
lc.setParent(li);
col++;
}
try {
reader.close();
} catch (IOException e) {
LOGGER.error("error closing after reading species list", e);
}
}
});
} catch (Exception e) {
LOGGER.error("error reading species list data", e);
}
}
Aggregations