use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method startQueries.
void startQueries() {
final boolean worldAreaSelected = CommonData.WORLD_WKT.equals(selectedArea.getFacets() == null ? selectedArea.getWkt() : null);
reportModelMap = setUpModelMap(worldAreaSelected);
areaReportListModel = new ChangableSimpleListModel(new ArrayList(reportModelMap.values()));
facetsValues.setModel(areaReportListModel);
//Set the renderer that is responsible for the pretties and associating actions to the buttons
facetsValues.setRowRenderer(new RowRenderer() {
@Override
public void render(Row row, Object data, int itemIdx) throws Exception {
//data should be a map of facet result information
if (data instanceof AreaReportItemDTO) {
final AreaReportItemDTO dto = (AreaReportItemDTO) data;
row.appendChild(new Label(dto.getTitle()));
row.appendChild(new Label(dto.getCount()));
//check for the buttons to display
Div listDiv = new Div();
Div mapDiv = new Div();
Div sampleDiv = new Div();
row.appendChild(listDiv);
row.appendChild(mapDiv);
row.appendChild(sampleDiv);
listDiv.setZclass("areaReportListCol");
mapDiv.setZclass("areaReportMapCol");
sampleDiv.setZclass("areaReportSampleCol");
Button b;
if (dto.getExtraInfo() != null) {
final boolean[] gk = dto.isGeospatialKosher() ? new boolean[] { true, false, false } : new boolean[] { true, true, false };
final boolean kosher = dto.isGeospatialKosher();
for (ExtraInfoEnum type : dto.getExtraInfo()) {
switch(type) {
case LIST:
b = new Button("List");
b.setZclass(StringConstants.BTN_BTN_MINI);
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (dto.getListType() == ListType.SPECIES) {
new SpeciesListEvent(areaName, gk, dto.isEndemic(), dto.getExtraParams()).onEvent(event);
} else if (dto.getListType() == ListType.DISTRIBUTION) {
listDistributions(dto);
} else if (dto.getListType() == ListType.AREA_CHECKLIST) {
listAreaChecklists(dto);
} else if (dto.getListType() == ListType.SPECIES_CHECKLIST) {
listSpeciesChecklists(dto);
} else if (dto.getListType() == ListType.JOURNAL_MAP) {
listJournalmap();
}
}
});
listDiv.appendChild(b);
break;
case SAMPLE:
b = new Button("Sample");
b.setZclass(StringConstants.BTN_BTN_MINI);
final SamplingEvent sle = new SamplingEvent(null, areaName, null, gk);
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
sle.onEvent(new ForwardEvent("", getMapComposer(), null));
}
});
sampleDiv.appendChild(b);
break;
case MAP_ALL:
//set up the map button
b = new Button("Map all");
b.setZclass(StringConstants.BTN_BTN_MINI);
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (dto.getTitle().contains("Gazetteer")) {
mapGazetteer();
} else if (StringConstants.POINTS_OF_INTEREST.equals(dto.getTitle())) {
onMapPointsOfInterest(event);
} else if (kosher) {
onMapSpeciesKosher(new Event("", null, dto.getExtraParams()));
} else {
onMapSpecies(new Event("", null, dto.getExtraParams()));
}
}
});
mapDiv.appendChild(b);
break;
default:
LOGGER.error("invalid type for AreaReportController: " + type);
}
}
}
if (dto.getUrlDetails() != null) {
Vlayout vlayout = new Vlayout();
for (Map.Entry<String, String> entry : dto.getUrlDetails().entrySet()) {
String urlTitle = entry.getKey();
org.zkoss.zul.A viewRecords = new org.zkoss.zul.A(urlTitle);
String url = entry.getValue();
if (url.startsWith("http")) {
viewRecords.setHref(url);
viewRecords.setTarget(StringConstants.BLANK);
} else {
final String helpUrl = CommonData.getSettings().get("help_url") + "/spatial-portal-help/" + url;
viewRecords.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
Events.echoEvent(StringConstants.OPEN_URL, getMapComposer(), helpUrl);
}
});
}
vlayout.appendChild(viewRecords);
}
row.appendChild(vlayout);
} else {
row.appendChild(new Label(""));
}
}
}
});
divWorldNote.setVisible(worldAreaSelected);
Callable occurrenceCount = new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
return occurrenceCount(worldAreaSelected, reportModelMap.get(StringConstants.OCCURRENCES));
}
};
Callable occurrenceCountKosher = new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
return occurrenceCountKosher(worldAreaSelected, reportModelMap.get(StringConstants.SPATIAL_OCCURRENCES));
}
};
Callable speciesCount = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return speciesCount(worldAreaSelected, reportModelMap.get(StringConstants.SPECIES));
}
};
Callable speciesCountKosher = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return speciesCountKosher(worldAreaSelected, reportModelMap.get(StringConstants.SPATIAL_SPECIES));
}
};
Callable endemismCount = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return endemismCount(worldAreaSelected, reportModelMap.get(StringConstants.ENDEMIC_SPECIES));
}
};
Callable endemismCountKosher = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return endemismCountKosher(worldAreaSelected, reportModelMap.get(StringConstants.SPATIAL_ENDEMIC_SPECIES));
}
};
Callable speciesDistributions = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return intersectWithSpeciesDistributions(reportModelMap.get(StringConstants.EXPERT_DISTRIBUTIONS));
}
};
Callable calculatedArea = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return calculateArea(reportModelMap.get(StringConstants.AREA));
}
};
Callable speciesChecklists = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return intersectWithSpeciesChecklists(reportModelMap.get(StringConstants.CHECKLIST_AREA), reportModelMap.get(StringConstants.CHECKLIST_SPECIES));
}
};
Callable gazPointsC = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return countGazPoints(reportModelMap.get(StringConstants.GAZETTEER));
}
};
Callable journalmap = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return journalmap(reportModelMap.get(StringConstants.JOURNAL_MAP));
}
};
Callable pointsOfInterestC = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return countPointsOfInterest(reportModelMap.get("poi"));
}
};
Callable[] areaFacets = new Callable[CommonData.getAreaReportFacets().length];
for (int i = 0; i < CommonData.getAreaReportFacets().length; i++) {
final String facet = CommonData.getAreaReportFacets()[i];
final String s = String.valueOf(i);
areaFacets[i] = new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
return facetCounts(reportModelMap.get(StringConstants.CONFIGURED_FACETS + s), facet);
}
};
}
try {
this.pool = Executors.newFixedThreadPool(50);
this.futures = new HashMap<String, Future<Map<String, String>>>();
this.firedEvents = new ArrayList<String>();
// add all futures
futures.put("CalculatedArea", pool.submit(calculatedArea));
futures.put("OccurrenceCount", pool.submit(occurrenceCount));
futures.put("OccurrenceCountKosher", pool.submit(occurrenceCountKosher));
for (int i = 0; i < areaFacets.length; i++) {
futures.put("AreaFacetCounts" + i, pool.submit(areaFacets[i]));
}
futures.put("SpeciesCount", pool.submit(speciesCount));
futures.put("SpeciesCountKosher", pool.submit(speciesCountKosher));
futures.put("GazPoints", pool.submit(gazPointsC));
futures.put("SpeciesChecklists", pool.submit(speciesChecklists));
futures.put("SpeciesDistributions", pool.submit(speciesDistributions));
futures.put("Journalmap", pool.submit(journalmap));
if (CommonData.getDisplayPointsOfInterest()) {
futures.put("PointsOfInterest", pool.submit(pointsOfInterestC));
}
if (includeEndemic) {
futures.put("EndemicCount", pool.submit(endemismCount));
futures.put("EndemicCountKosher", pool.submit(endemismCountKosher));
}
futuresStart = System.currentTimeMillis();
} catch (Exception e) {
LOGGER.error("error setting counts for futures", e);
}
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class ContextualMenu method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
getMapComposer().setContextualMenuRefreshListener(new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
refresh();
}
});
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class ContextualLayerListComposer method renderTree.
private void renderTree() {
tree.setItemRenderer(new TreeitemRenderer() {
@Override
public void render(Treeitem item, Object data, int itemIdx) throws Exception {
DefaultTreeNode t = (DefaultTreeNode) data;
JSONParser jp = new JSONParser();
JSONObject joLayer = (JSONObject) jp.parse(t.getData().toString());
Treerow tr;
/*
* Since only one treerow is allowed, if treerow is not null,
* append treecells to it. If treerow is null, construct a new
* treerow and attach it to item.
*/
if (item.getTreerow() == null) {
tr = new Treerow();
tr.setParent(item);
} else {
tr = item.getTreerow();
tr.getChildren().clear();
}
String displayname = joLayer.get(StringConstants.NAME).toString();
displayname = (displayname.contains(">")) ? displayname.split(">")[1] : displayname;
Treecell tcName = new Treecell();
String type = ((JSONObject) joLayer.get("layer")).get(StringConstants.TYPE).toString();
if (!"node".equals(type)) {
Html img = new Html("<i class='icon-info-sign'></i>");
img.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(event.getTarget().getParent().getParent().getAttribute("lyr").toString());
String s = jo.get(StringConstants.ID).toString();
String metadata = CommonData.getLayersServer() + "/layers/view/more/" + s;
getMapComposer().activateLink(metadata, "Metadata", false);
}
});
img.setParent(tcName);
Space sp = new Space();
sp.setParent(tcName);
}
Label lbl = new Label(displayname);
lbl.setParent(tcName);
if (!"node".equals(type)) {
tr.setAttribute("lyr", joLayer);
}
// Attach onclick events:
if (!"node".equals(type)) {
// tcAdd
tr.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
JSONParser jp = new JSONParser();
JSONObject joLayer = (JSONObject) jp.parse(tree.getSelectedItem().getTreerow().getAttribute("lyr").toString());
if (!StringConstants.CLASS.equals(((JSONObject) joLayer.get("layer")).get(StringConstants.TYPE))) {
String metadata = CommonData.getLayersServer() + "/layers/view/more/" + joLayer.get("spid");
initALC();
contextualLayerSelection.setLayer(joLayer.get(StringConstants.NAME).toString(), ((JSONObject) joLayer.get("layer")).get("displaypath").toString(), metadata, StringConstants.ENVIRONMENTAL.equalsIgnoreCase(((JSONObject) joLayer.get("layer")).get(StringConstants.TYPE).toString()) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL);
} else {
String classValue = joLayer.get(StringConstants.NAME).toString();
String layer = joLayer.get(StringConstants.LAYERNAME).toString();
String displaypath = CommonData.getGeoServer() + "/wms?service=WMS&version=1.1.0&request=GetMap&layers=ALA:Objects&format=image/png&viewparams=s:" + ((JSONObject) joLayer.get("layer")).get("displaypath");
//Filtered requests don't work on
displaypath = displaypath.replace("gwc/service/", "");
String metadata = CommonData.getLayersServer() + "/layers/view/more/" + joLayer.get(StringConstants.ID);
initALC();
contextualLayerSelection.setLayer(layer + " - " + classValue, displaypath, metadata, StringConstants.ENVIRONMENTAL.equalsIgnoreCase(((JSONObject) joLayer.get("layer")).get(StringConstants.TYPE).toString()) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL);
}
}
});
}
tcName.setParent(tr);
item.setOpen(false);
}
});
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesAutoCompleteComponent method initChildren.
/**
* Initialise the children components that will appear within the vbox.
*/
private void initChildren() {
vbox = new Vbox();
chkUseRawName = new Checkbox("Use the scientific names supplied with the records");
chkUseRawName.setChecked(false);
chkUseRawName.addEventListener("onCheck", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
onCheck$chkUseRawName(event);
}
});
autoComplete = new SpeciesAutoComplete();
autoComplete.setAutodrop(true);
autoComplete.setWidth("330px");
autoComplete.addEventListener("onChange", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
autoCompleteSelectionChanged(event);
}
});
vbox.appendChild(chkUseRawName);
vbox.appendChild(autoComplete);
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class LayerLegendScatterplotController method onClick$btnEditAppearance1.
public void onClick$btnEditAppearance1(Event event) {
if (layerWindow != null) {
boolean closing = layerWindow.getParent() != null;
layerWindow.detach();
layerWindow = null;
if (closing) {
return;
}
}
getScatterplotData();
if (data.getQuery() != null) {
//preview species list
layerWindow = (ScatterplotLayerLegendComposer) Executions.createComponents("WEB-INF/zul/legend/ScatterplotLayerLegend.zul", getRoot(), null);
EventListener el = new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
updateFromLegend();
}
};
layerWindow.init(data.getQuery(), mapLayer, data.getRed(), data.getGreen(), data.getBlue(), data.getSize(), data.getOpacity(), data.getColourMode(), el);
try {
layerWindow.doOverlapped();
layerWindow.setPosition("right");
} catch (Exception e) {
LOGGER.error("failed ot open scatteplot layer legend", e);
}
}
}
Aggregations