Search in sources :

Example 1 with ForwardEvent

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

the class SandboxEmbeddedController method gotDrUid.

public void gotDrUid(Event event) {
    dataResourceUid = ((String) event.getData());
    sandboxReady.setVisible(true);
    sandboxFrame.setVisible(false);
    List<Facet> facetList = new ArrayList<Facet>();
    facetList.add(new Facet("data_resource_uid", dataResourceUid, true));
    query = new BiocacheQuery(null, null, null, facetList, true, null, CommonData.getSettings().getProperty("sandbox.biocache.url"), CommonData.getSettings().getProperty("sandbox.biocache.ws.url"), true);
    if (addtoMap) {
        getMapComposer().mapSpecies(query, query.getSolrName(), StringConstants.SPECIES, query.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
    }
    //call reset window on caller to perform refresh'
    if (callback != null) {
        try {
            callback.onEvent(new ForwardEvent("", null, null, new String[] { dataResourceUid, "normal" }));
        } catch (Exception e) {
            LOGGER.error("failed to cancel species points upload", e);
        }
    }
    onClick$btnOk(null);
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Facet(au.org.ala.legend.Facet)

Example 2 with ForwardEvent

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

the class SandboxPasteController method gotDrUid.

public void gotDrUid(Event event) {
    dataResourceUid = ((String) event.getData());
    sandboxReady.setVisible(true);
    sandboxFrame.setVisible(false);
    List<Facet> facetList = new ArrayList<Facet>();
    facetList.add(new Facet("data_resource_uid", dataResourceUid, true));
    query = new BiocacheQuery(null, null, null, facetList, true, null, CommonData.getSettings().getProperty("sandbox.biocache.url"), CommonData.getSettings().getProperty("sandbox.biocache.ws.url"), true);
    if (addtoMap) {
        getMapComposer().mapSpecies(query, query.getSolrName(), StringConstants.SPECIES, query.getOccurrenceCount(), LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
    }
    //call reset window on caller to perform refresh'
    if (callback != null) {
        try {
            callback.onEvent(new ForwardEvent("", null, null, new String[] { dataResourceUid, "normal" }));
        } catch (Exception e) {
            LOGGER.error("failed to cancel species points upload", e);
        }
    }
    onClick$btnOk(null);
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) ArrayList(java.util.ArrayList) BiocacheQuery(au.org.ala.spatial.util.BiocacheQuery) Facet(au.org.ala.legend.Facet)

Example 3 with ForwardEvent

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

the class SandboxPasteController 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();
        String filename = m.getName();
        String contentType = m.getContentType();
        String format = m.getFormat();
        boolean loaded = false;
        if (!loaded) {
            try {
                loaded = upload(m.getByteData(), filename, contentType);
                LOGGER.debug(m.getContentType() + " with getByteData");
            } catch (Exception e) {
            //failed to read, will try another method
            }
        }
        if (!loaded) {
            try {
                loaded = upload(IOUtils.toByteArray(m.getStreamData()), filename, contentType);
                LOGGER.debug(m.getContentType() + " with getStreamData");
            } catch (Exception e) {
            //failed to read, will try another method
            }
        }
        try {
            Reader r = m.getReaderData();
            InputStream is = new ReaderInputStream(r, "UTF-8");
            loaded = upload(IOUtils.toByteArray(is), filename, contentType);
            LOGGER.debug(m.getContentType() + " with getReaderData");
        } catch (Exception e) {
        //failed to read, will try another method
        }
        if (!loaded) {
            try {
                loaded = upload(m.getStringData().getBytes(), filename, contentType);
                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);
            }
        }
        //process if successful upload
        if (loaded) {
            ((Iframe) getFellow("sandboxFrame")).setSrc("sandboxPreview.html?uploadId=" + uploadId + "&uploadFn=" + uploadFn);
            //display frame and trigger javascript setup function
            getMapComposer().getOpenLayersJavascript().execute("$('#sandboxContainer')[0].style.display = \"inline\";setTimeout(\"setUrls()\",500)");
            getFellow("fileUpload").setVisible(false);
            getFellow("fileUpload").detach();
            getFellow("divSandbox").setVisible(false);
            setTop("10px");
        }
    } catch (Exception ex) {
        LOGGER.error("error reading uploaded file", ex);
    }
}
Also used : Iframe(org.zkoss.zul.Iframe) ReaderInputStream(org.apache.xmlbeans.impl.common.ReaderInputStream) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) ReaderInputStream(org.apache.xmlbeans.impl.common.ReaderInputStream) InputStream(java.io.InputStream) Media(org.zkoss.util.media.Media) Reader(java.io.Reader) UploadEvent(org.zkoss.zk.ui.event.UploadEvent)

Example 4 with ForwardEvent

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

the class UploadLayerListController method loadLayerList.

private void loadLayerList(Reader r) throws IOException {
    CSVReader reader = new CSVReader(r);
    //one line, read it
    StringBuilder sb = new StringBuilder();
    for (String s : reader.readNext()) {
        if (sb.length() > 0) {
            sb.append(",");
        }
        sb.append(s);
    }
    reader.close();
    if (callback != null) {
        try {
            callback.onEvent(new ForwardEvent("", this, null, sb.toString()));
        } catch (Exception e) {
            LOGGER.error("failed when calling ToolComposer callback", e);
        }
    }
}
Also used : ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) CSVReader(au.com.bytecode.opencsv.CSVReader) IOException(java.io.IOException)

Example 5 with ForwardEvent

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

the class UploadToSpeciesListController method onClick$btnOk.

public void onClick$btnOk(Event event) {
    if (tbName.getValue().length() > 0) {
        String name = tbName.getValue();
        String description = tbDesc.getValue();
        dataResourceUid = SpeciesListUtil.createNewList(name, species, description, null, Util.getUserEmail(), chkPrivate.isChecked());
        LOGGER.debug("The data resource uid: " + dataResourceUid);
        if (callback != null) {
            try {
                callback.onEvent(new ForwardEvent("", null, null, dataResourceUid));
            } catch (Exception e) {
                LOGGER.error("failed to trigger callback from species list upload", e);
            }
        }
        this.detach();
    } else {
        tbInstructions.setValue("WARNING: Must supply a list name");
    }
}
Also used : 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