use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method onSelect$selectedLayersCombobox.
public void onSelect$selectedLayersCombobox(Event event) {
Comboitem ci = selectedLayersCombobox.getSelectedItem();
if (ci != null && lbListLayers != null) {
String layersList = null;
if (ci.getValue() != null && ci.getValue() instanceof LayerSelection) {
layersList = ((LayerSelection) ci.getValue()).getLayers();
} else {
if (ci.getValue() == null) {
if (ci.getLabel().toLowerCase().contains("paste")) {
PasteLayerListController window = (PasteLayerListController) Executions.createComponents("WEB-INF/zul/input/PasteLayerList.zul", this, null);
window.setCallback(new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
selectLayerFromList((String) event.getData());
updateLayerSelectionCount();
}
});
try {
window.setParent(this);
window.doModal();
} catch (Exception e) {
LOGGER.error("error opening PasteLayerList.zul", e);
}
} else if (ci.getLabel().toLowerCase().contains("import")) {
UploadLayerListController window = (UploadLayerListController) Executions.createComponents("WEB-INF/zul/input/UploadLayerList.zul", this, null);
window.setCallback(new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
selectLayerFromList((String) event.getData());
updateLayerSelectionCount();
}
});
try {
window.setParent(this);
window.doModal();
} catch (Exception e) {
LOGGER.error("error opening UploadLayerList.zul", e);
}
}
selectedLayersCombobox.setSelectedIndex(-1);
}
}
selectLayerFromList(layersList);
}
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class PhylogeneticDiversityComposer method fillPDTreeList.
private void fillPDTreeList() {
JSONArray ja = null;
String url = CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) + "/phylo/getExpertTrees";
JSONParser jp = new JSONParser();
try {
ja = (JSONArray) jp.parse(Util.readUrl(url));
} catch (ParseException e) {
LOGGER.error("failed to parse getExpertTrees");
}
if (ja == null || ja.size() == 0) {
Events.echoEvent("onClose", this, null);
getMapComposer().showMessage("Phylogenetic diversity tool is currently unavailable.");
return;
}
trees = new Object[ja.size()];
header = new ArrayList<String>();
//restrict header to what is in the zul
for (Component c : getFellow(StringConstants.TREES_HEADER).getChildren()) {
header.add(c.getId().substring(3));
}
int row = 0;
for (int i = 0; i < ja.size(); i++) {
JSONObject j = (JSONObject) ja.get(i);
Map<String, String> pdrow = new HashMap<String, String>();
for (Object o : j.keySet()) {
String key = (String) o;
if (j.containsKey(key) && j.get(key) != null) {
pdrow.put(key, j.get(key).toString());
} else {
pdrow.put(key, null);
}
}
trees[row] = pdrow;
row++;
}
treesList.setModel(new ListModelArray(trees, false));
treesList.setItemRenderer(new ListitemRenderer() {
public void render(Listitem li, Object data, int itemIdx) {
Map<String, String> map = (Map<String, String>) data;
for (int i = 0; i < header.size(); i++) {
String value = map.get(header.get(i));
if (value == null) {
value = "";
}
if ("treeViewUrl".equalsIgnoreCase(header.get(i))) {
Html img = new Html("<i class='icon-info-sign'></i>");
img.setAttribute("link", value.isEmpty() ? CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) : value);
Listcell lc = new Listcell();
lc.setParent(li);
img.setParent(lc);
img.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
//re-toggle the checked flag
Listitem li = (Listitem) event.getTarget().getParent().getParent();
li.getListbox().toggleItemSelection(li);
String metadata = (String) event.getTarget().getAttribute("link");
getMapComposer().activateLink(metadata, "Metadata", false);
}
});
} else {
Listcell lc = new Listcell(value);
lc.setParent(li);
}
}
}
});
treesList.setMultiple(true);
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class GDMComposer method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
this.selectedMethod = StringConstants.GDM;
this.totalSteps = 5;
this.loadAreaLayers();
this.loadSpeciesLayers();
this.loadGridLayers(true, false, true);
this.updateWindowTitle();
try {
sitesslider.addEventListener("onScrolling", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (event instanceof ScrollEvent) {
ScrollEvent se = (ScrollEvent) event;
double a = se.getPos();
double b = a / maxScroll;
long p = Math.round(b * 100);
sitesslider.setSlidingtext(Math.round(a) + " - " + p + "%");
}
}
});
} catch (Exception e) {
LOGGER.debug("Error in slider");
LOGGER.debug(e.getMessage());
}
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class ClassificationLegend method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
query = (Query) (Executions.getCurrent().getArg().get(StringConstants.QUERY));
LOGGER.debug("Query q:" + query.getQ());
mapLayer = (MapLayer) (Executions.getCurrent().getArg().get(StringConstants.LAYER));
readonly = (Executions.getCurrent().getArg().get(StringConstants.READONLY)) != null;
colourmode = (String) (Executions.getCurrent().getArg().get(StringConstants.COLOURMODE));
pid = (String) (Executions.getCurrent().getArg().get(StringConstants.PID));
checkmarks = (Executions.getCurrent().getArg().get("checkmarks")) != null;
disableselection = (Executions.getCurrent().getArg().get("disableselection")) != null;
if (disableselection) {
dCreateButtons.setVisible(false);
lhFirstColumn.setWidth("0px");
lhSecondColumn.setWidth("190px");
lhThirdColumn.setWidth("15px");
lhThirdColumn.setLabel("");
lhFourthColumn.setWidth("50px");
legend.setWidth("280px");
}
buildLegend();
getFellow("btnSearch").addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
List<String[]> legendLinesFiltered = new ArrayList<String[]>();
String txt = ((Textbox) getFellow("txtSearch")).getValue().toLowerCase();
if (txt.length() > 0) {
for (int i = 0; i < legendLines.size(); i++) {
if (legendLines.get(i)[0].toLowerCase().contains(txt)) {
legendLinesFiltered.add(legendLines.get(i));
}
}
((Button) getFellow("btnClear")).setDisabled(false);
legend.setModel(new SimpleListModel(legendLinesFiltered));
legend.setActivePage(0);
}
}
});
getFellow("btnClear").addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
((Textbox) getFellow("txtSearch")).setValue("");
((Button) getFellow("btnClear")).setDisabled(true);
legend.setModel(new SimpleListModel(legendLines));
legend.setActivePage(0);
}
});
//setup sorting
Comparator labelComparatorAsc = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
String[] s1 = (String[]) o1;
String[] s2 = (String[]) o2;
return s1[0].compareTo(s2[0]);
}
};
Comparator labelComparatorDesc = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
String[] s1 = (String[]) o1;
String[] s2 = (String[]) o2;
return s2[0].compareTo(s1[0]);
}
};
Comparator countComparatorAsc = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Long l1 = null;
Long l2 = null;
try {
l1 = Long.parseLong(((String[]) o1)[4]);
l2 = Long.parseLong(((String[]) o2)[4]);
return l1.compareTo(l2);
} catch (Exception e) {
if (l2 == null && l1 == null) {
return 0;
} else if (l2 == null) {
return 1;
} else {
return -1;
}
}
}
};
Comparator countComparatorDesc = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Long l1 = null;
Long l2 = null;
try {
l1 = Long.parseLong(((String[]) o1)[4]);
l2 = Long.parseLong(((String[]) o2)[4]);
return l2.compareTo(l1);
} catch (Exception e) {
if (l2 == null && l1 == null) {
return 0;
} else if (l2 == null) {
return -1;
} else {
return 1;
}
}
}
};
lhSecondColumn.setSortAscending(labelComparatorAsc);
lhSecondColumn.setSortDescending(labelComparatorDesc);
lhFourthColumn.setSortAscending(countComparatorAsc);
lhFourthColumn.setSortDescending(countComparatorDesc);
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class ClassificationLegend method buildLegend.
void buildLegend() {
try {
StringBuilder slist = new StringBuilder();
if (query != null) {
if (StringConstants.GRID.equals(colourmode)) {
slist.append("name,red,green,blue,count");
for (int i = 0; i < 600; i += 100) {
slist.append(">");
slist.append("\n").append(i).append(",").append(LegendObject.getRGB(Legend.getLinearColour(i, 0, 500, 0xFFFFFF00, 0xFFFF0000))).append(",");
}
} else {
slist.append(query.getLegend(colourmode).getTable());
}
} else {
return;
}
try {
legendLines = new CSVReader(new StringReader(slist.toString())).readAll();
//reset selection when legendLines is rebuilt
uncheckAll();
} catch (IOException e) {
LOGGER.error("failed to read legend list as csv", e);
}
legendLines.remove(0);
String h = mapLayer.getHighlight();
facet = Facet.parseFacet(h);
divContinous.setVisible(false);
//test for range (user upload)
if (legendLines.size() > 1) {
String first = legendLines.get(0)[0];
if (first == null || first.length() == 0 || first.startsWith(StringConstants.UNKNOWN)) {
first = legendLines.get(1)[0];
}
if (!checkmarks && query.getLegend(colourmode) != null && query.getLegend(colourmode).getNumericLegend() != null) {
setupForNumericalList(h);
//test for manual range (solr query)
} else if (StringConstants.OCCURRENCE_YEAR.equals(colourmode)) {
setupForBiocacheNumber(h, colourmode, true);
} else if (StringConstants.OCCURRENCE_YEAR_DECADE.equals(colourmode) || StringConstants.DECADE.equals(colourmode)) {
setupForBiocacheDecade();
} else if (StringConstants.COORDINATE_UNCERTAINTY.equals(colourmode) || StringConstants.UNCERTAINTY.equals(colourmode)) {
setupForBiocacheNumber(h, colourmode, false);
} else if (StringConstants.MONTH.equals(colourmode)) {
setupForBiocacheMonth();
}
}
/* apply something to line onclick in lb */
legend.setItemRenderer(new ListitemRenderer() {
@Override
public void render(Listitem li, Object data, int itemIdx) {
String[] ss = (String[]) data;
if (ss == null) {
return;
}
Checkbox cb = null;
if (checkmarks) {
cb = new Checkbox();
cb.addEventListener("onCheck", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
String v = ((Listcell) event.getTarget().getParent().getParent().getChildren().get(1)).getLabel();
if (((CheckEvent) event).isChecked()) {
selectedList.add(v);
} else {
selectedList.remove(v);
}
lblSelectedCount.setValue(selectedList.size() + " selected");
if (selectedList.size() > 0) {
createInGroup.setVisible(true);
if (createOutGroup != null)
createOutGroup.setVisible(true);
clearSelection.setVisible(true);
} else {
createInGroup.setVisible(false);
if (createOutGroup != null)
createOutGroup.setVisible(false);
clearSelection.setVisible(false);
}
checkboxClick(event);
}
});
determineCheckboxState(cb, ss[0]);
}
Listcell lc;
lc = new Listcell();
if (cb != null) {
cb.setParent(lc);
//Do not display checkboxes for facets that are not simple
cb.setVisible(!disableselection && !ss[0].endsWith(" more"));
}
lc.setParent(li);
if (readonly) {
lc = new Listcell(actualToDisplayLabel(ss[0]));
} else {
lc = new Listcell("group " + ss[0]);
}
lc.setParent(li);
int red = 0, green = 0, blue = 0;
try {
red = Integer.parseInt(ss[1]);
green = Integer.parseInt(ss[2]);
blue = Integer.parseInt(ss[3]);
} catch (Exception e) {
LOGGER.error("error parsing colours : " + ss[0], e);
}
lc = new Listcell(" ");
lc.setStyle("background-color: rgb(" + red + "," + green + "," + blue + "); color: rgb(" + red + "," + green + "," + blue + ")");
lc.setParent(li);
//count
try {
//don't display if it is not a number
Long.parseLong(ss[4]);
lhFourthColumn.setVisible(true);
lc = new Listcell(ss[4]);
lc.setParent(li);
} catch (NumberFormatException e) {
lhFourthColumn.setVisible(false);
lhThirdColumn.setWidth("100%");
dCreateButtons.setVisible(!readonly);
}
}
});
legend.setModel(new SimpleListModel(legendLines));
createInGroup.setVisible(!disableselection && mapLayer.getHighlight() != null && mapLayer.getHighlight().length() > 0);
if (createOutGroup != null)
createOutGroup.setVisible(!disableselection && mapLayer.getHighlight() != null && mapLayer.getHighlight().length() > 0);
clearSelection.setVisible(!disableselection && mapLayer.getHighlight() != null && mapLayer.getHighlight().length() > 0);
if (divContinous.isVisible()) {
int[] state = getState();
if (state[0] > 1) {
setEnableContinousControls(false);
} else {
updateD();
}
getFellow("txtSearch").setVisible(false);
} else {
getFellow("txtSearch").setVisible(true);
}
} catch (Exception e) {
LOGGER.error("error building classification legend, pid: " + pid, e);
}
}
Aggregations