Search in sources :

Example 6 with ForwardEvent

use of org.zkoss.zk.ui.event.ForwardEvent in project spatial-portal by AtlasOfLivingAustralia.

the class MapComposer method redrawLayersList.

public void redrawLayersList() {
    int idx = activeLayersList.getSelectedIndex();
    List<MapLayer> activeLayers = getPortalSession().getActiveLayers();
    activeLayersList.setModel(new ListModelList(activeLayers, true));
    activeLayersList.setSelectedIndex(idx);
    if (layerLegendNameRefresh != null) {
        try {
            layerLegendNameRefresh.onEvent(new ForwardEvent("", this, null, llc2MapLayer.getDisplayName()));
        } catch (Exception e) {
            LOGGER.error("failed to refresh legend name with current map layer", e);
        }
    }
    lblSelectedLayer.setValue(llc2MapLayer.getDisplayName());
    adjustActiveLayersList();
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) HasMapLayer(au.org.emii.portal.menu.HasMapLayer) MapLayer(au.org.emii.portal.menu.MapLayer) ParseException(org.json.simple.parser.ParseException)

Example 7 with ForwardEvent

use of org.zkoss.zk.ui.event.ForwardEvent in project spatial-portal by AtlasOfLivingAustralia.

the class UploadLayerListController method doFileUpload.

public void doFileUpload(Event event) {
    UploadEvent ue = null;
    if (event instanceof UploadEvent) {
        ue = (UploadEvent) event;
    } else if (event instanceof ForwardEvent) {
        ue = (UploadEvent) ((ForwardEvent) event).getOrigin();
    }
    if (ue == null) {
        LOGGER.debug("unable to upload file");
        return;
    } else {
        LOGGER.debug("fileUploaded()");
    }
    try {
        Media m = ue.getMedia();
        boolean loaded = false;
        try {
            loadLayerList(m.getReaderData());
            loaded = true;
            LOGGER.debug(m.getContentType() + " with getReaderData");
        } catch (Exception e) {
        //failed to read, will try another method
        }
        if (!loaded) {
            try {
                loadLayerList(new StringReader(new String(m.getByteData())));
                loaded = true;
                LOGGER.debug(m.getContentType() + " with getByteData");
            } catch (Exception e) {
            //failed to read, will try another method
            }
        }
        if (!loaded) {
            try {
                loadLayerList(new InputStreamReader(m.getStreamData()));
                loaded = true;
                LOGGER.debug(m.getContentType() + " with getStreamData");
            } catch (Exception e) {
            //failed to read, will try another method
            }
        }
        if (!loaded) {
            try {
                loadLayerList(new StringReader(m.getStringData()));
                LOGGER.debug(m.getContentType() + " with getStringData");
            } catch (Exception e) {
                //last one, report error
                getMapComposer().showMessage(CommonData.lang("error_uploading_file"));
                LOGGER.error("unable to load user layer list: ", e);
            }
        }
    } catch (Exception ex) {
        LOGGER.error("error reading uploaded file", ex);
    }
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) InputStreamReader(java.io.InputStreamReader) Media(org.zkoss.util.media.Media) StringReader(java.io.StringReader) IOException(java.io.IOException) UploadEvent(org.zkoss.zk.ui.event.UploadEvent)

Example 8 with ForwardEvent

use of org.zkoss.zk.ui.event.ForwardEvent in project spatial-portal by AtlasOfLivingAustralia.

the class UploadSpeciesController method doFileUpload.

public void doFileUpload(UserDataDTO ud, Event event) {
    UploadEvent ue = null;
    if (event instanceof UploadEvent) {
        ue = (UploadEvent) event;
    } else if (event instanceof ForwardEvent) {
        ue = (UploadEvent) ((ForwardEvent) event).getOrigin();
    }
    if (ue == null) {
        LOGGER.debug("unable to upload file");
        return;
    } else {
        LOGGER.debug("fileUploaded()");
    }
    try {
        Media m = ue.getMedia();
        UserDataDTO u = ud;
        if (u == null) {
            u = new UserDataDTO(m.getName());
        }
        if (u.getName().trim().isEmpty()) {
            u.setName(m.getName());
        }
        u.setFilename(m.getName());
        if (u.getName() == null || u.getName().length() == 0) {
            u.setName(m.getName());
        }
        if (u.getDescription() == null || u.getDescription().length() == 0) {
            u.setDescription(m.getName());
        }
        u.setUploadedTimeInMs(System.currentTimeMillis());
        LOGGER.debug("Got file '" + u.getName() + "' with type '" + m.getContentType() + "'");
        //forget content types, do 'try'
        boolean loaded = false;
        try {
            loadUserPoints(u, m.getReaderData(), addToMap, tbName.getText(), tbDesc.getText(), getMapComposer(), eventListener);
            loaded = true;
            LOGGER.debug("read type " + m.getContentType() + " with getReaderData");
        } catch (Exception e) {
        //failed to read uploaded data, will try another method
        }
        if (!loaded) {
            try {
                loadUserPoints(u, new StringReader(new String(m.getByteData())), addToMap, tbName.getText(), tbDesc.getText(), getMapComposer(), eventListener);
                loaded = true;
                LOGGER.debug("read type " + m.getContentType() + " with getByteData");
            } catch (Exception e) {
            //failed to read uploaded data, will try another method
            }
        }
        if (!loaded) {
            try {
                loadUserPoints(u, new InputStreamReader(m.getStreamData()), addToMap, tbName.getText(), tbDesc.getText(), getMapComposer(), eventListener);
                loaded = true;
                LOGGER.debug("read type " + m.getContentType() + " with getStreamData");
            } catch (Exception e) {
            //failed to read uploaded data, will try another method
            }
        }
        if (!loaded) {
            try {
                loadUserPoints(u, new StringReader(m.getStringData()), addToMap, tbName.getText(), tbDesc.getText(), getMapComposer(), eventListener);
                LOGGER.debug("read type " + m.getContentType() + " with getStringData");
            } catch (Exception e) {
                //last one, report error
                getMapComposer().showMessage("Unable to load your file. Please try again.");
                LOGGER.error("unable to load user points: ", e);
            }
        }
        //call reset window on caller to perform refresh'
        if (callback != null) {
            try {
                callback.onEvent(new ForwardEvent("", null, null, new String[] { uploadLSID, uploadType }));
            } catch (Exception e) {
                LOGGER.error("failed to cancel species points upload", e);
            }
        }
    } catch (Exception ex) {
        LOGGER.error("unable to load user points", ex);
    }
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) InputStreamReader(java.io.InputStreamReader) Media(org.zkoss.util.media.Media) StringReader(java.io.StringReader) UserDataDTO(au.org.ala.spatial.dto.UserDataDTO) WrongValueException(org.zkoss.zk.ui.WrongValueException) UploadEvent(org.zkoss.zk.ui.event.UploadEvent)

Example 9 with ForwardEvent

use of org.zkoss.zk.ui.event.ForwardEvent 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 10 with ForwardEvent

use of org.zkoss.zk.ui.event.ForwardEvent in project spatial-portal by AtlasOfLivingAustralia.

the class ActiveLayerRenderer method render.

@Override
public void render(Listitem item, Object data, int itemIdx) throws Exception {
    final MapLayer layer = (MapLayer) data;
    Listcell listcell = new Listcell();
    Checkbox checkbox;
    /*
         * In the past it was assumed that we just set true here - this is not
         * the case because this method is called to re-render the list after
         * the user has been fiddling with the checkboxes in some cases (dnd
         * events)
         */
    checkbox = new Checkbox();
    checkbox.setChecked(layer.isDisplayed());
    checkbox.setParent(listcell);
    checkbox.setTooltiptext("Hide");
    if (layer.getType() == LayerUtilitiesImpl.MAP) {
        checkbox.setChecked(true);
    }
    checkbox.addEventListener("onCheck", visibilityToggleEventListener);
    if (!layer.isRemoveable()) {
        checkbox.setStyle("float:left; visibility:hidden; ");
        checkbox.setDisabled(true);
    }
    Label label = new Label(layer.getDisplayName());
    //do after legend
    listcell.setParent(item);
    // dnd list reordering support
    item.addEventListener("onDrop", new ActiveLayerDNDEventListener());
    item.setDraggable(StringConstants.TRUE);
    item.setDroppable(StringConstants.TRUE);
    // bind to the ActiveLayer instance (we readback later)
    item.setValue(layer);
    // simple description for tooltip
    label.setTooltiptext(layer.getDescription());
    if (layer.isRemoveable()) {
        checkbox.setStyle(StringConstants.FLOAT_LEFT);
    }
    /*
         * show the legend graphic when the user hovers over the palette icon
         */
    if (layer.isRemoveable()) {
        Html remove = new Html(languagePack.getLang("layer_remove_icon_html"));
        remove.addEventListener(StringConstants.ONCLICK, new ActiveLayersRemoveEventListener());
        remove.setParent(listcell);
        remove.setStyle(StringConstants.FLOAT_RIGHT);
        remove.setTooltiptext("remove layer");
    }
    Html info = new Html(languagePack.getLang("layer_info_icon_html"));
    info.setParent(listcell);
    info.setStyle(StringConstants.FLOAT_RIGHT);
    info.setTooltiptext("metadata");
    info.addEventListener(StringConstants.ONCLICK, new ActiveLayersInfoEventListener());
    if (layer.getType() != LayerUtilitiesImpl.MAP) {
        Html zoomextent = new Html(languagePack.getLang("layer_zoomextent_icon_html"));
        zoomextent.setParent(listcell);
        zoomextent.setStyle("float:right");
        zoomextent.setTooltiptext("zoom to extent");
        zoomextent.addEventListener(StringConstants.ONCLICK, new ActiveLayersZoomExtentEventListener());
    }
    //Set the legend graphic based on the layer type
    Image legend;
    if (layer.isGridLayer() || layer.getSubType() == LayerUtilitiesImpl.GDM || layer.getSubType() == LayerUtilitiesImpl.MAXENT || layer.getSubType() == LayerUtilitiesImpl.ALOC || layer.getSubType() == LayerUtilitiesImpl.SRICHNESS || layer.getSubType() == LayerUtilitiesImpl.ODENSITY) {
        legend = new Image(languagePack.getLang("icon_grid"));
    } else if (layer.isSpeciesLayer()) {
        legend = new Image(languagePack.getLang("icon_species"));
    } else if (layer.isPolygonLayer()) {
        legend = new Image(languagePack.getLang("icon_polygon"));
    } else if (layer.isContextualLayer()) {
        legend = new Image(languagePack.getLang("icon_contextual"));
    } else {
        //just a plain layer
        legend = new Image(languagePack.getLang("layer_legend_icon"));
    }
    legend.setStyle(StringConstants.FLOAT_LEFT);
    legend.setParent(listcell);
    legend.setTooltiptext("View/edit the legend");
    legend.addEventListener(StringConstants.ONCLICK, new ActiveLayersLegendEventListener());
    label.setParent(listcell);
    // adding buttons to basemap in layer list
    if (layer.getType() == LayerUtilitiesImpl.MAP) {
        //add select all or unselect all button or delete all buttons
        //NOTE: Objects created here are referenced by relative location in the listcell.
        //      Changes made here must also be made in MapComposer.adjustActiveLayersList
        Div div = new Div();
        div.setClass("btn-group");
        div.setParent(listcell);
        div.setStyle("float:right;margin-right:30px");
        Button b = new Button("Delete all");
        b.setClass(StringConstants.BTN_MINI);
        b.setParent(div);
        b.setVisible(false);
        b.addEventListener(StringConstants.ONCLICK, new ActiveLayersRemoveAll());
        b = new Button("Show all");
        b.setClass(StringConstants.BTN_MINI);
        b.setParent(div);
        b.setVisible(false);
        b.addEventListener(StringConstants.ONCLICK, new VisibilityAllToggleEventListener(true));
        b = new Button("Hide all");
        b.setClass(StringConstants.BTN_MINI);
        b.setParent(div);
        b.setVisible(false);
        b.addEventListener(StringConstants.ONCLICK, new VisibilityAllToggleEventListener(false));
        new ActiveLayersAdjustEventListener().equals(new ForwardEvent("", legend, null));
    }
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent)

Aggregations

ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)10 Media (org.zkoss.util.media.Media)3 UploadEvent (org.zkoss.zk.ui.event.UploadEvent)3 Facet (au.org.ala.legend.Facet)2 BiocacheQuery (au.org.ala.spatial.util.BiocacheQuery)2 MapLayer (au.org.emii.portal.menu.MapLayer)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 CSVReader (au.com.bytecode.opencsv.CSVReader)1 SamplingEvent (au.org.ala.spatial.composer.quicklinks.SamplingEvent)1 SpeciesListEvent (au.org.ala.spatial.composer.quicklinks.SpeciesListEvent)1 AreaReportItemDTO (au.org.ala.spatial.dto.AreaReportItemDTO)1 ExtraInfoEnum (au.org.ala.spatial.dto.AreaReportItemDTO.ExtraInfoEnum)1 UserDataDTO (au.org.ala.spatial.dto.UserDataDTO)1 HasMapLayer (au.org.emii.portal.menu.HasMapLayer)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 Callable (java.util.concurrent.Callable)1