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;
}
}
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);
}
Aggregations