Search in sources :

Example 56 with Event

use of org.zkoss.zk.ui.event.Event 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);
    }
}
Also used : AreaReportItemDTO(au.org.ala.spatial.dto.AreaReportItemDTO) Callable(java.util.concurrent.Callable) org.zkoss.zul(org.zkoss.zul) ExtraInfoEnum(au.org.ala.spatial.dto.AreaReportItemDTO.ExtraInfoEnum) EventListener(org.zkoss.zk.ui.event.EventListener) SamplingEvent(au.org.ala.spatial.composer.quicklinks.SamplingEvent) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) Event(org.zkoss.zk.ui.event.Event) ListDataEvent(javax.swing.event.ListDataEvent) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) SpeciesListEvent(au.org.ala.spatial.composer.quicklinks.SpeciesListEvent) SamplingEvent(au.org.ala.spatial.composer.quicklinks.SamplingEvent) SpeciesListEvent(au.org.ala.spatial.composer.quicklinks.SpeciesListEvent) Future(java.util.concurrent.Future) JSONObject(org.json.simple.JSONObject)

Example 57 with Event

use of org.zkoss.zk.ui.event.Event 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);
}
Also used : Checkbox(org.zkoss.zul.Checkbox) CheckEvent(org.zkoss.zk.ui.event.CheckEvent) Event(org.zkoss.zk.ui.event.Event) EventListener(org.zkoss.zk.ui.event.EventListener) Vbox(org.zkoss.zul.Vbox)

Example 58 with Event

use of org.zkoss.zk.ui.event.Event 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);
        }
    }
}
Also used : Event(org.zkoss.zk.ui.event.Event) EventListener(org.zkoss.zk.ui.event.EventListener)

Example 59 with Event

use of org.zkoss.zk.ui.event.Event in project collect by openforis.

the class TabsGroupContainer method addNewChildTab.

private void addNewChildTab() {
    newChildTab = new Tab();
    newChildTab.setLabel("+");
    newChildTab.addEventListener("onClick", new EventListener<Event>() {

        @Override
        public void onEvent(Event event) throws Exception {
            postAddTabCommand();
        }
    });
    Tabs tabs = tabbox.getTabs();
    tabs.appendChild(newChildTab);
}
Also used : UITab(org.openforis.collect.metamodel.ui.UITab) Tab(org.zkoss.zul.Tab) Event(org.zkoss.zk.ui.event.Event) Tabs(org.zkoss.zul.Tabs)

Example 60 with Event

use of org.zkoss.zk.ui.event.Event in project collect by openforis.

the class SurveyErrorsPopUpVM method initEventListeners.

protected static void initEventListeners(Window popUp, final ConfirmHandler confirmHandler) {
    IdSpace idSpace = popUp.getSpaceOwner();
    Component okButton = Path.getComponent(idSpace, OK_BUTTON_ID);
    okButton.addEventListener(ON_CLICK_EVENT, new EventListener<Event>() {

        public void onEvent(Event arg0) throws Exception {
            confirmHandler.onOk();
        }
    });
    Component cancelButton = Path.getComponent(idSpace, CANCEL_BUTTON_ID);
    cancelButton.addEventListener(ON_CLICK_EVENT, new EventListener<Event>() {

        public void onEvent(Event arg0) throws Exception {
            if (confirmHandler instanceof CompleteConfirmHandler) {
                ((CompleteConfirmHandler) confirmHandler).onCancel();
            }
        }
    });
}
Also used : CompleteConfirmHandler(org.openforis.collect.designer.util.MessageUtil.CompleteConfirmHandler) Event(org.zkoss.zk.ui.event.Event) IdSpace(org.zkoss.zk.ui.IdSpace) Component(org.zkoss.zk.ui.Component)

Aggregations

Event (org.zkoss.zk.ui.event.Event)60 EventListener (org.zkoss.zk.ui.event.EventListener)42 JSONObject (org.json.simple.JSONObject)11 ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)9 ValueChangeEvent (org.adempiere.exceptions.ValueChangeEvent)7 Component (org.zkoss.zk.ui.Component)7 CheckEvent (org.zkoss.zk.ui.event.CheckEvent)7 LegendObject (au.org.ala.legend.LegendObject)6 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 JSONParser (org.json.simple.parser.JSONParser)6 Center (org.zkoss.zul.Center)6 MapLayer (au.org.emii.portal.menu.MapLayer)5 JSONArray (org.json.simple.JSONArray)5 Borderlayout (org.zkoss.zul.Borderlayout)5 Tabpanel (org.adempiere.webui.component.Tabpanel)4 WTableModelEvent (org.adempiere.webui.event.WTableModelEvent)4 ParseException (org.json.simple.parser.ParseException)4 Div (org.zkoss.zul.Div)4 North (org.zkoss.zul.North)4