Search in sources :

Example 1 with BackgroundTask

use of com.haulmont.cuba.gui.executors.BackgroundTask 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 BackgroundTask

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

the class MbeanInspectWindow method runAsynchronously.

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

        @Override
        public Object run(TaskLifeCycle<Long> taskLifeCycle) throws Exception {
            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

BackgroundTask (com.haulmont.cuba.gui.executors.BackgroundTask)2 TaskLifeCycle (com.haulmont.cuba.gui.executors.TaskLifeCycle)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 BackgroundWorkWindow (com.haulmont.cuba.gui.backgroundwork.BackgroundWorkWindow)1