Search in sources :

Example 1 with RequestContext

use of org.primefaces.context.RequestContext in project dataverse by IQSS.

the class DatasetPage method modifyGuestbookMultipleResponse.

public void modifyGuestbookMultipleResponse() {
    if (this.selectedFiles.isEmpty()) {
        RequestContext requestContext = RequestContext.getCurrentInstance();
        requestContext.execute("PF('selectFilesForDownload').show()");
        return;
    }
    this.guestbookResponse = this.guestbookResponseService.modifySelectedFileIds(guestbookResponse, getSelectedDownloadableFilesIdsString());
    this.guestbookResponse.setDownloadtype("Download");
    this.guestbookResponse.setFileFormat("Download");
    RequestContext requestContext = RequestContext.getCurrentInstance();
    requestContext.execute("PF('downloadPopup').show();handleResizeDialog('downloadPopup');");
}
Also used : RequestContext(org.primefaces.context.RequestContext)

Example 2 with RequestContext

use of org.primefaces.context.RequestContext in project dataverse by IQSS.

the class DatasetPage method restrictSelectedFiles.

public String restrictSelectedFiles(boolean restricted) throws CommandException {
    RequestContext requestContext = RequestContext.getCurrentInstance();
    if (selectedFiles.isEmpty()) {
        if (restricted) {
            requestContext.execute("PF('selectFilesForRestrict').show()");
        } else {
            requestContext.execute("PF('selectFilesForUnRestrict').show()");
        }
        return "";
    } else {
        boolean validSelection = false;
        for (FileMetadata fmd : selectedFiles) {
            if ((fmd.isRestricted() && !restricted) || (!fmd.isRestricted() && restricted)) {
                validSelection = true;
            }
        }
        if (!validSelection) {
            if (restricted) {
                requestContext.execute("PF('selectFilesForRestrict').show()");
            }
            if (!restricted) {
                requestContext.execute("PF('selectFilesForUnRestrict').show()");
            }
            return "";
        }
    }
    if (editMode != EditMode.CREATE) {
        if (bulkUpdateCheckVersion()) {
            refreshSelectedFiles();
        }
        restrictFiles(restricted);
    }
    save();
    return returnToDraftVersion();
}
Also used : RequestContext(org.primefaces.context.RequestContext)

Example 3 with RequestContext

use of org.primefaces.context.RequestContext in project dataverse by IQSS.

the class DatasetPage method requestAccessMultipleFiles.

public String requestAccessMultipleFiles() {
    if (selectedFiles.isEmpty()) {
        RequestContext requestContext = RequestContext.getCurrentInstance();
        requestContext.execute("PF('selectFilesForRequestAccess').show()");
        return "";
    } else {
        fileDownloadHelper.clearRequestAccessFiles();
        for (FileMetadata fmd : selectedFiles) {
            fileDownloadHelper.addMultipleFilesForRequestAccess(fmd.getDataFile());
        }
        if (isRequestAccessPopupRequired()) {
            RequestContext requestContext = RequestContext.getCurrentInstance();
            requestContext.execute("PF('requestAccessPopup').show()");
            return "";
        } else {
            // No popup required
            fileDownloadHelper.requestAccessIndirect();
            return "";
        }
    }
}
Also used : RequestContext(org.primefaces.context.RequestContext)

Example 4 with RequestContext

use of org.primefaces.context.RequestContext in project dataverse by IQSS.

the class EditDatafilesPage method handleFileUpload.

/**
 * Handle native file replace
 * @param event
 * @throws java.io.IOException
 */
public void handleFileUpload(FileUploadEvent event) throws IOException {
    if (!uploadInProgress) {
        uploadInProgress = true;
    }
    if (event == null) {
        throw new NullPointerException("event cannot be null");
    }
    UploadedFile uFile = event.getFile();
    if (uFile == null) {
        throw new NullPointerException("uFile cannot be null");
    }
    /**
     * For File Replace, take a different code path
     */
    if (isFileReplaceOperation()) {
        handleReplaceFileUpload(event, uFile.getInputstream(), uFile.getFileName(), uFile.getContentType(), event, null);
        if (fileReplacePageHelper.hasContentTypeWarning()) {
            RequestContext context = RequestContext.getCurrentInstance();
            RequestContext.getCurrentInstance().update("datasetForm:fileTypeDifferentPopup");
            context.execute("PF('fileTypeDifferentPopup').show();");
        }
        return;
    }
    List<DataFile> dFileList = null;
    try {
        // Note: A single uploaded file may produce multiple datafiles -
        // for example, multiple files can be extracted from an uncompressed
        // zip file.
        dFileList = FileUtil.createDataFiles(workingVersion, uFile.getInputstream(), uFile.getFileName(), uFile.getContentType(), systemConfig);
    } catch (IOException ioex) {
        logger.warning("Failed to process and/or save the file " + uFile.getFileName() + "; " + ioex.getMessage());
        return;
    }
    /*catch (FileExceedsMaxSizeException ex) {
            logger.warning("Failed to process and/or save the file " + uFile.getFileName() + "; " + ex.getMessage());
            return;
        }*/
    // -----------------------------------------------------------
    // These raw datafiles are then post-processed, in order to drop any files
    // already in the dataset/already uploaded, and to correct duplicate file names, etc.
    // -----------------------------------------------------------
    String warningMessage = processUploadedFileList(dFileList);
    if (warningMessage != null) {
        uploadWarningMessage = warningMessage;
        FacesContext.getCurrentInstance().addMessage(event.getComponent().getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, "upload warning", warningMessage));
        // save the component id of the p:upload widget, so that we could
        // send an info message there, from elsewhere in the code:
        uploadComponentId = event.getComponent().getClientId();
    }
}
Also used : UploadedFile(org.primefaces.model.UploadedFile) RequestContext(org.primefaces.context.RequestContext) IOException(java.io.IOException) FacesMessage(javax.faces.application.FacesMessage)

Example 5 with RequestContext

use of org.primefaces.context.RequestContext in project dataverse by IQSS.

the class FileDownloadHelper method writeGuestbookAndOpenSubset.

public void writeGuestbookAndOpenSubset(GuestbookResponse guestbookResponse) {
    RequestContext requestContext = RequestContext.getCurrentInstance();
    boolean valid = validateGuestbookResponse(guestbookResponse);
    if (!valid) {
    } else {
        requestContext.execute("PF('downloadPopup').hide()");
        requestContext.execute("PF('downloadDataSubsetPopup').show()");
        guestbookResponse.setDownloadtype("Subset");
        fileDownloadService.writeGuestbookResponseRecord(guestbookResponse);
    }
}
Also used : RequestContext(org.primefaces.context.RequestContext)

Aggregations

RequestContext (org.primefaces.context.RequestContext)11 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 FacesMessage (javax.faces.application.FacesMessage)1 UploadedFile (org.primefaces.model.UploadedFile)1