use of org.zkoss.zk.ui.event.CheckEvent 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);
}
}
use of org.zkoss.zk.ui.event.CheckEvent in project spatial-portal by AtlasOfLivingAustralia.
the class LayerLegendGeneralComposer method setupForClassificationLayers.
private void setupForClassificationLayers() {
if (mapLayer.isPolygonLayer())
return;
String activeLayerName = StringConstants.NONE;
JSONObject field = null;
JSONObject layer = null;
if (mapLayer != null && mapLayer.getUri() != null) {
if (mapLayer.getBaseUri() != null) {
activeLayerName = mapLayer.getBaseUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
} else {
activeLayerName = mapLayer.getUri().replaceAll("^.*&style=", "").replaceAll("&.*", "").replaceAll("_style", "");
}
field = CommonData.getLayer(activeLayerName);
if (field == null)
return;
layer = (JSONObject) field.get("layer");
}
LOGGER.debug("ACTIVE LAYER: " + activeLayerName);
if (mapLayer != null && mapLayer.getSubType() == LayerUtilitiesImpl.ALOC) {
divClassificationPicker.setVisible(true);
//reset content
Integer groupCount = mapLayer.getClassificationGroupCount();
if (groupCount == null) {
mapLayer.setClassificationGroupCount(getClassificationGroupCount(mapLayer.getName().replace("aloc_", "")));
groupCount = 0;
}
for (int i = cbClassificationGroup.getItemCount() - 1; i >= 0; i--) {
cbClassificationGroup.removeItemAt(i);
}
Comboitem ci = new Comboitem(StringConstants.NONE);
ci.setParent(cbClassificationGroup);
for (int i = 1; i <= groupCount; i++) {
new Comboitem("Group " + i).setParent(cbClassificationGroup);
}
//is there a current selection?
Integer groupSelection = mapLayer.getClassificationSelection();
if (groupSelection == null) {
groupSelection = 0;
mapLayer.setClassificationSelection(groupSelection);
}
cbClassificationGroup.setSelectedIndex(groupSelection);
getFellow("btnCreateArea").setVisible(false);
cbClassificationGroup.setVisible(true);
lbClassificationGroup.setVisible(false);
hboxClassificationGroup.setVisible(false);
} else if (layer != null && layer.containsKey("type") && layer.get("type").toString().equalsIgnoreCase("contextual")) {
divClassificationPicker.setVisible(true);
if (mapLayer.getClassificationGroupCount() == null || mapLayer.getClassificationGroupCount() == 0) {
//build
String fieldId = field.get(StringConstants.ID).toString();
JSONParser jp = new JSONParser();
JSONObject objJson = null;
try {
objJson = (JSONObject) jp.parse(Util.readUrl(CommonData.getLayersServer() + "/field/" + fieldId));
} catch (ParseException e) {
LOGGER.error("failed to parse for: " + fieldId);
}
JSONArray objects = (JSONArray) objJson.get("objects");
//sort
List<JSONObject> list = objects.subList(0, objects.size());
Collections.sort(list, new Comparator<JSONObject>() {
@Override
public int compare(JSONObject o1, JSONObject o2) {
String s1 = (o1 == null || !o1.containsKey("name")) ? "" : o1.get("name").toString();
String s2 = (o2 == null || !o2.containsKey("name")) ? "" : o2.get("name").toString();
return s1.compareTo(s2);
}
});
JSONArray obj = new JSONArray();
obj.addAll(list);
mapLayer.setClassificationGroupCount(obj.size());
mapLayer.setClassificationObjects(obj);
}
//reset content
Integer groupCount = mapLayer.getClassificationGroupCount();
JSONArray groupObjects = mapLayer.getClassificationObjects();
lbClassificationGroup.setItemRenderer(new ListitemRenderer<JSONObject>() {
@Override
public void render(Listitem item, JSONObject data, int index) throws Exception {
Checkbox cb = new Checkbox();
final int idx = index;
cb.addEventListener("onCheck", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
if (mapLayer != null) {
lbClassificationGroup.setMultiple(true);
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() + " checked");
getFellow("clearSelection").setVisible(selectedList.size() > 0);
getFellow("createInGroup").setVisible(selectedList.size() > 0);
if (getFellowIfAny("createOutGroup") != null)
getFellow("createOutGroup").setVisible(selectedList.size() > 0);
highlightSelect(idx);
}
}
});
determineCheckboxState(cb, data.get("name").toString());
Listcell lc;
lc = new Listcell();
cb.setParent(lc);
lc.setParent(item);
lc = new Listcell(data.get("name").toString());
lc.setParent(item);
lc = new Listcell();
Image img = new Image();
img.setTooltip("Create as an area layer");
img.setClass("icon-plus-sign");
img.setParent(lc);
lc.setParent(item);
final JSONObject j = data;
img.addEventListener("onClick", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
createAreaEcho(j.get("pid").toString());
}
});
lc = new Listcell();
img = new Image();
img.setTooltip("Zoom to area");
img.setClass("icon-zoom-in");
img.setParent(lc);
lc.setParent(item);
img.addEventListener("onClick", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
List<Double> b = Util.getBoundingBox(j.get("bbox").toString());
BoundingBox bbox = new BoundingBox();
bbox.setMinLongitude(b.get(0).floatValue());
bbox.setMinLatitude(b.get(1).floatValue());
bbox.setMaxLongitude(b.get(2).floatValue());
bbox.setMaxLatitude(b.get(3).floatValue());
getMapComposer().getOpenLayersJavascript().execute(getMapComposer().getOpenLayersJavascript().zoomToBoundingBox(bbox, false));
}
});
}
});
lbClassificationGroup.addEventListener("onSelect", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
if (mapLayer != null) {
highlightSelect(lbClassificationGroup.getSelectedIndex());
}
}
});
List<JSONObject> model = new ArrayList<JSONObject>();
for (int i = 0; i < groupCount; i++) {
model.add((JSONObject) groupObjects.get(i));
}
lbClassificationGroup.setModel(new SimpleListModel(model));
//is there a current selection?
Integer groupSelection = mapLayer.getClassificationSelection();
if (groupSelection == null) {
groupSelection = 0;
mapLayer.setClassificationSelection(groupSelection);
}
getFellow("btnCreateArea").setVisible(true);
getFellow("btnCreateArea").setVisible(false);
cbClassificationGroup.setVisible(false);
lbClassificationGroup.setVisible(true);
hboxClassificationGroup.setVisible(true);
} else {
getFellow("btnCreateArea").setVisible(false);
divClassificationPicker.setVisible(false);
}
}
use of org.zkoss.zk.ui.event.CheckEvent in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesAutoCompleteComponent method onCheck$chkUseRawName.
/**
* The use "supplied" name check box has been either selected or deselected,
* take the appropriate action on the combo box
*
* @param event
*/
public void onCheck$chkUseRawName(Event event) {
boolean checked = ((CheckEvent) event).isChecked();
BiocacheQuery q = checked ? new BiocacheQuery(null, null, null, null, false, new boolean[] { true, true, false }) : null;
autoComplete.setBiocacheQuery(q);
}
Aggregations