Search in sources :

Example 1 with TaskLifeCycle

use of com.haulmont.cuba.gui.executors.TaskLifeCycle in project cuba by cuba-platform.

the class DesktopFileUploadField method saveFile.

protected void saveFile(FileDescriptor fileDescriptor) {
    switch(mode) {
        case MANUAL:
            setValue(fileDescriptor);
            break;
        case IMMEDIATE:
            BackgroundTask<Long, FileDescriptor> uploadProgress = new BackgroundTask<Long, FileDescriptor>(2400, getFrame()) {

                @Override
                public Map<String, Object> getParams() {
                    return ParamsMap.of("fileId", fileId, "fileName", getFileName());
                }

                @Override
                public FileDescriptor run(final TaskLifeCycle<Long> taskLifeCycle) throws Exception {
                    return fileUploading.putFileIntoStorage(taskLifeCycle);
                }

                @Override
                public void done(FileDescriptor result) {
                    FileDescriptor descriptor = commitFileDescriptor(result);
                    setValue(descriptor);
                }
            };
            long fileSize = fileUploading.getFile(fileId).length();
            BackgroundWorkProgressWindow.show(uploadProgress, messages.getMainMessage("FileUploadField.uploadingFile"), null, fileSize, true, true);
            break;
    }
}
Also used : TaskLifeCycle(com.haulmont.cuba.gui.executors.TaskLifeCycle) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor) BackgroundTask(com.haulmont.cuba.gui.executors.BackgroundTask)

Example 2 with TaskLifeCycle

use of com.haulmont.cuba.gui.executors.TaskLifeCycle in project cuba by cuba-platform.

the class FileUploading method putFileIntoStorage.

@Override
public FileDescriptor putFileIntoStorage(final TaskLifeCycle<Long> taskLifeCycle) throws FileStorageException, InterruptedException {
    checkNotNullArgument(taskLifeCycle);
    UUID fileId = (UUID) taskLifeCycle.getParams().get("fileId");
    String fileName = (String) taskLifeCycle.getParams().get("fileName");
    checkNotNull(fileId);
    checkNotNull(fileName);
    UploadToStorageProgressListener progressListener = (fileId1, uploadedBytes, totalBytes) -> taskLifeCycle.publish(uploadedBytes);
    FileDescriptor fileDescriptor = getFileDescriptor(fileId, fileName);
    uploadFileIntoStorage(fileId, fileDescriptor, progressListener);
    deleteFile(fileId);
    return fileDescriptor;
}
Also used : TaskLifeCycle(com.haulmont.cuba.gui.executors.TaskLifeCycle) java.util(java.util) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SimpleDateFormat(java.text.SimpleDateFormat) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor) Supplier(java.util.function.Supplier) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) IOUtils(org.apache.commons.io.IOUtils) Component(org.springframework.stereotype.Component) java.io(java.io) LazySupplier(com.haulmont.bali.util.StreamUtils.LazySupplier) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) FilenameUtils(org.apache.commons.io.FilenameUtils) Nullable(javax.annotation.Nullable) DateFormat(java.text.DateFormat) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 3 with TaskLifeCycle

use of com.haulmont.cuba.gui.executors.TaskLifeCycle in project cuba by cuba-platform.

the class MbeanInspectWindow method runAsynchronously.

protected void runAsynchronously(ManagedBeanOperation operation, Object[] paramValues, Long timeout) {
    BackgroundTask<Long, Object> task = new BackgroundTask<Long, Object>(timeout, TimeUnit.MILLISECONDS, this) {

        @Override
        public Object run(TaskLifeCycle<Long> taskLifeCycle) {
            return jmxControlAPI.invokeOperation(operation, paramValues);
        }

        @Override
        public void done(Object result) {
            Window w = openWindow("jmxConsoleOperationResult", OpenType.DIALOG, ParamsMap.of("result", result, "beanName", operation.getMbean().getClassName(), "methodName", operation.getName()));
            w.addCloseListener(actionId -> reloadAttributes());
        }

        @Override
        public boolean handleException(Exception ex) {
            log.error("Error occurs while performing JMX operation {}", operation.getName(), ex);
            Window w = openWindow("jmxConsoleOperationResult", OpenType.DIALOG, ParamsMap.of("exception", ex, "beanName", operation.getMbean().getClassName(), "methodName", operation.getName()));
            w.addCloseListener(actionId -> reloadAttributes());
            return true;
        }
    };
    BackgroundWorkWindow.show(task, true);
}
Also used : BackgroundWorkWindow(com.haulmont.cuba.gui.backgroundwork.BackgroundWorkWindow) TaskLifeCycle(com.haulmont.cuba.gui.executors.TaskLifeCycle) BackgroundTask(com.haulmont.cuba.gui.executors.BackgroundTask)

Aggregations

TaskLifeCycle (com.haulmont.cuba.gui.executors.TaskLifeCycle)3 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 BackgroundTask (com.haulmont.cuba.gui.executors.BackgroundTask)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 LazySupplier (com.haulmont.bali.util.StreamUtils.LazySupplier)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 BackgroundWorkWindow (com.haulmont.cuba.gui.backgroundwork.BackgroundWorkWindow)1 java.io (java.io)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Supplier (java.util.function.Supplier)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 FilenameUtils (org.apache.commons.io.FilenameUtils)1 IOUtils (org.apache.commons.io.IOUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1