use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
winTop = this.getTop();
winLeft = this.getLeft();
setupDefaultParams();
Map<String, Object> tmp = new HashMap<String, Object>();
Map m = Executions.getCurrent().getArg();
if (m != null) {
for (Object o : m.entrySet()) {
if (((Map.Entry) o).getKey() instanceof String) {
tmp.put((String) ((Map.Entry) o).getKey(), ((Map.Entry) o).getValue());
}
}
}
setParams(tmp);
if (tmp.containsKey(StringConstants.GEOSPATIAL_KOSHER)) {
setGeospatialKosherCheckboxes((boolean[]) tmp.get(StringConstants.GEOSPATIAL_KOSHER));
}
if (tmp.containsKey(StringConstants.CHOOSEENDEMIC)) {
setChooseEndemic((Boolean) tmp.get(StringConstants.CHOOSEENDEMIC));
} else if (chkEndemicSpecies != null) {
updateEndemicCheckBox();
}
updateWindowTitle();
fixFocus();
if (lbListLayers != null) {
lbListLayers.clearSelection();
lbListLayers.updateDistances();
}
// init mpLayer1 and mpLayer2
if (mpLayer1 != null && mpLayer2 != null) {
for (MapLayer ml : getMapComposer().getGridLayers()) {
addToMpLayers(ml, false);
}
}
if (searchSpeciesACComp != null) {
mSearchSpeciesACComp.addEventListener("onValueSelected", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
toggles();
}
});
}
if (mSearchSpeciesACComp != null) {
mSearchSpeciesACComp.getAutoComplete().setBiocacheOnly(true);
mSearchSpeciesACComp.addEventListener("onValueSelected", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
mChooseSelected(null);
}
});
}
if (mSearchSpeciesACCompBk != null) {
mSearchSpeciesACCompBk.getAutoComplete().setBiocacheOnly(true);
mSearchSpeciesACCompBk.addEventListener("onValueSelected", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
mChooseSelectedBk(null);
}
});
}
// init includeLayers
if (cbLayer != null) {
cbLayer.setIncludeLayers("AllLayers");
cbLayer.refresh("");
}
if (cbLayerEnvironmentalOnly != null) {
cbLayerEnvironmentalOnly.setIncludeLayers(StringConstants.ENVIRONMENTAL_LAYERS);
cbLayerEnvironmentalOnly.refresh("");
}
if (cbLayer1 != null) {
cbLayer1.setIncludeLayers(StringConstants.ENVIRONMENTAL_LAYERS);
cbLayer1.refresh("");
}
if (cbLayer2 != null) {
cbLayer2.setIncludeLayers(StringConstants.ENVIRONMENTAL_LAYERS);
cbLayer2.refresh("");
}
if (cbLayerMix != null) {
cbLayerMix.setIncludeLayers("MixLayers");
cbLayerMix.refresh("");
}
updateDefaultGeospatialKosherValues();
//some variables won't wire because they are imported
if (getFellowIfAny("splistbox") != null) {
vboxImportSL = (Vbox) getFellow("splistbox").getFellow("vboxImportSL");
speciesListListbox = (SpeciesListListbox) this.getFellow("splistbox").getFellow("speciesListListbox");
}
if (getFellowIfAny("splistboxbk") != null) {
vboxImportSLBk = (Vbox) getFellow("splistboxbk").getFellow("vboxImportSL");
speciesListListboxBk = (SpeciesListListbox) this.getFellow("splistboxbk").getFellow("speciesListListbox");
}
//add the species lists stuff
if (rSpeciesUploadLSID != null && speciesListListbox != null) {
speciesListListbox.addEventListener(StringConstants.ONSICHECKBOXCHANGED, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
btnOk.setDisabled((Integer) event.getData() == 0);
}
});
}
if (rSpeciesUploadLSIDBk != null && speciesListListbox != null) {
speciesListListbox.addEventListener(StringConstants.ONSICHECKBOXCHANGED, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
btnOk.setDisabled((Integer) event.getData() == 0);
}
});
}
if (vboxImportSL != null) {
vboxImportSL.getFellow("btnSearchSpeciesListListbox").addEventListener("onClick", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
onClick$btnSearchSpeciesListListbox(event);
}
});
vboxImportSL.getFellow("btnClearSearchSpeciesListListbox").addEventListener("onClick", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
onClick$btnClearSearchSpeciesListListbox(event);
}
});
}
if (vboxImportSLBk != null) {
vboxImportSLBk.getFellow("btnSearchSpeciesListListbox").addEventListener("onClick", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
onClick$btnSearchSpeciesListListbox(event);
}
});
vboxImportSL.getFellow("btnClearSearchSpeciesListListbox").addEventListener("onClick", new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
onClick$btnClearSearchSpeciesListListbox(event);
}
});
}
initLifeforms();
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class AddFacetController method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
winTop = this.getTop();
winLeft = this.getLeft();
setupDefaultParams();
Map<String, Object> tmp = new HashMap<String, Object>();
Map m = Executions.getCurrent().getArg();
if (m != null) {
for (Object entry : m.entrySet()) {
if (((Map.Entry) entry).getKey() instanceof String) {
tmp.put((String) ((Map.Entry) entry).getKey(), ((Map.Entry) entry).getValue());
}
}
}
setParams(tmp);
selectedMethod = "Add facet";
updateWindowTitle();
fixFocus();
loadAreaLayers();
if (rgArea.getSelectedItem() != null) {
btnOk.setDisabled(false);
} else {
btnOk.setDisabled(true);
}
getFellow("btnSearch").addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
List<String[]> legendLinesFiltered = new ArrayList<String[]>();
String txt = 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 UploadSpeciesController method afterCompose.
@Override
public void afterCompose() {
super.afterCompose();
setTbInstructions("3. Select file (text file, one LSID or name per line)");
Map m = Executions.getCurrent().getArg();
if (m != null) {
for (Object o : m.entrySet()) {
if (((Map.Entry) o).getKey() instanceof String && "setTbInstructions".equals(((Map.Entry) o).getKey())) {
setTbInstructions((String) ((Map.Entry) o).getValue());
}
if (((Map.Entry) o).getKey() instanceof String && "addToMap".equals(((Map.Entry) o).getKey())) {
addToMap = true;
}
}
}
tbName.setConstraint(new Constraint() {
@Override
public void validate(Component comp, Object value) {
String val = (String) value;
Map htUserSpecies = (Map) getMapComposer().getSession().getAttribute(StringConstants.USERPOINTS);
if (htUserSpecies != null && !htUserSpecies.isEmpty()) {
for (Object o : htUserSpecies.values()) {
if (((UserDataDTO) o).getName().equalsIgnoreCase(val.trim())) {
throw new WrongValueException(comp, "User dataset named '" + val + "' already exists. Please enter another name for your dataset.");
}
}
}
}
});
fileUpload.addEventListener("onUpload", new EventListener() {
public void onEvent(Event event) throws Exception {
UserDataDTO ud = new UserDataDTO(tbName.getValue(), tbDesc.getValue(), "points");
addToMap = true;
defineArea = true;
doFileUpload(ud, event);
onClick$btnCancel(null);
}
});
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method addListener.
void addListener() {
if (!addedListener) {
addedListener = true;
// register for viewport changes
EventListener el = new EventListener() {
public void onEvent(Event event) throws Exception {
selectedArea = new SelectedArea(null, getMapComposer().getViewArea());
}
};
getMapComposer().getLeftmenuSearchComposer().addViewportEventListener(StringConstants.FILTERING_RESULTS, el);
}
}
use of org.zkoss.zk.ui.event.EventListener in project spatial-portal by AtlasOfLivingAustralia.
the class DistributionsController method update.
void update(List<String[]> data, String count) {
currentData = data;
distributionLabel.setValue("found " + count + " " + type + " in the Area");
distributionListbox.setItemRenderer(new ListitemRenderer() {
@Override
public void render(Listitem li, Object data, int itemIdx) {
try {
String[] cells = (String[]) data;
li.setValue(cells);
if (cells.length > 0) {
Listcell lc = new Listcell();
if (!"SPCODE".equals(cells[0])) {
Button b = new Button("map");
b.setSclass("goButton");
// But I am not sure if this is going to cause an regression issues.
if ((CommonData.getSpeciesChecklistWMSFromSpcode(cells[0]).length > 0 && getMapComposer().getMapLayerWMS(CommonData.getSpeciesChecklistWMSFromSpcode(cells[0])[1]) != null) || (CommonData.getSpeciesDistributionWMSFromSpcode(cells[0]).length > 0 && getMapComposer().getMapLayerWMS(CommonData.getSpeciesDistributionWMSFromSpcode(cells[0])[1]) != null)) {
b.setDisabled(true);
} else {
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
// get spcode
Listcell lc = (Listcell) event.getTarget().getParent().getNextSibling();
String spcode = lc.getLabel();
// row as metadata
Listitem li = (Listitem) lc.getParent();
String[] row = li.getValue();
String layerName = getMapComposer().getNextAreaLayerName(row[0] + " area");
String html = Util.getMetadataHtmlForDistributionOrChecklist(row[0], row, layerName);
// map it
String[] mapping = CommonData.getSpeciesDistributionWMSFromSpcode(spcode);
if (mapping.length == 0) {
mapping = CommonData.getSpeciesChecklistWMSFromSpcode(spcode);
}
String displayName = mapping[0] + " area";
if (row[11] != null && row[11].length() > 0) {
displayName = row[11];
}
MapLayer ml = getMapComposer().addWMSLayer(layerName, displayName, mapping[1], 0.6f, html, null, LayerUtilitiesImpl.WKT, null, null);
ml.setSPCode(row[0]);
getMapComposer().setupMapLayerAsDistributionArea(ml);
getMapComposer().updateLayerControls();
// disable this button
((Button) event.getTarget()).setDisabled(true);
// flag as mapped by area_name or spcode
for (int i = 0; i < originalData.size(); i++) {
if (originalData.get(i)[0].length() > 0 && (originalData.get(i)[0].equals(row[0]) || (originalData.get(i)[11] != null && originalData.get(i)[11].length() > 0 && !originalData.get(i)[11].startsWith(EXPERT_DISTRIBUTION_AREA_NAME) && originalData.get(i)[11].equals(row[11])))) {
originalData.get(i)[14] = "1";
}
}
for (int i = 0; i < currentData.size(); i++) {
if (currentData.get(i)[0].length() > 0 && (currentData.get(i)[0].equals(row[0]) || (currentData.get(i)[11] != null && currentData.get(i)[11].length() > 0 && !currentData.get(i)[11].startsWith(EXPERT_DISTRIBUTION_AREA_NAME) && currentData.get(i)[11].equals(row[11])))) {
currentData.get(i)[14] = "1";
}
}
for (int i = 0; i < distributionListbox.getItemCount(); i++) {
String[] data = distributionListbox.getItemAtIndex(i).getValue();
if (data != null && data[14] != null && data[14].length() > 0) {
((Button) distributionListbox.getItemAtIndex(i).getFirstChild().getFirstChild()).setDisabled(true);
}
}
}
});
}
b.setParent(lc);
}
lc.setParent(li);
for (int i = 0; i < 14; i++) {
if (i == 9) {
// metadata url
lc = new Listcell();
if (cells[i] != null && cells[i].length() > 0) {
A a = new A("link");
a.setHref(cells[i]);
a.setTarget(StringConstants.BLANK);
a.setParent(lc);
}
lc.setParent(li);
} else if (i == 10) {
// lsid
lc = new Listcell();
if (cells[i] != null && cells[i].length() > 0) {
A a = new A("more...");
a.setHref(CommonData.getBieServer() + "/species/" + cells[i]);
a.setTarget(StringConstants.BLANK);
a.setParent(lc);
}
lc.setParent(li);
} else {
lc = new Listcell(cells[i]);
lc.setParent(li);
}
}
}
} catch (Exception e) {
LOGGER.error("error updating distributions list data", e);
}
}
});
ListModelList lme = new ListModelList(data);
distributionListbox.setModel(lme);
Listhead head = distributionListbox.getListhead();
for (int i = 0; i < head.getChildren().size(); i++) {
Listheader lh = (Listheader) head.getChildren().get(i);
// -1 for first column containing buttons.
if (i == 8 || i == 9 || i == 13) {
// min depth, max depth, area_km
lh.setSortAscending(new DListComparator(true, true, i - 1));
lh.setSortDescending(new DListComparator(false, true, i - 1));
} else if (i > 0 && i != 10 && i != 11) {
// exclude 'map button',
// 'metadata link', 'BIE
// link'
lh.setSortAscending(new DListComparator(true, false, i - 1));
lh.setSortDescending(new DListComparator(false, false, i - 1));
}
}
}
Aggregations