use of io.jmix.ui.executor.TaskLifeCycle in project jmix-docs by Haulmont.
the class ProgressBarScreen method onInit.
@Subscribe
protected void onInit(InitEvent event) {
BackgroundTask<Integer, Void> task = new BackgroundTask<Integer, Void>(100) {
@Override
public Void run(TaskLifeCycle<Integer> taskLifeCycle) throws Exception {
for (int i = 1; i <= ITERATIONS; i++) {
// <1>
TimeUnit.SECONDS.sleep(1);
taskLifeCycle.publish(i);
}
return null;
}
@Override
public void progress(List<Integer> changes) {
double lastValue = changes.get(changes.size() - 1);
// <2>
progressBar.setValue(lastValue / ITERATIONS);
}
};
BackgroundTaskHandler taskHandler = backgroundWorker.handle(task);
taskHandler.execute();
}
use of io.jmix.ui.executor.TaskLifeCycle in project jmix-docs by Haulmont.
the class DialogsScreen method onBackgroundDlgBtnClick.
// end::create-exception-dialog[]
@Subscribe("backgroundDlgBtn")
public void onBackgroundDlgBtnClick(Button.ClickEvent event) {
BackgroundTask<Integer, Void> task = new BackgroundTask<Integer, Void>(300, this) {
@Override
public Void run(TaskLifeCycle<Integer> taskLifeCycle) throws Exception {
for (int i = 1; i <= ITERATIONS; i++) {
TimeUnit.SECONDS.sleep(2);
taskLifeCycle.publish(i);
}
return null;
}
@Override
public void progress(List<Integer> changes) {
double lastValue = changes.get(changes.size() - 1);
// progressBar.setValue((lastValue / ITERATIONS));
}
};
BackgroundTaskHandler taskHandler = backgroundWorker.handle(task);
taskHandler.execute();
dialogs.createBackgroundWorkDialog(this, task).withCaption("Please wait").withMessage("Data loading continues").withShowProgressInPercentage(true).withCancelAllowed(true).show();
}
use of io.jmix.ui.executor.TaskLifeCycle in project jmix by jmix-framework.
the class UiReportRunnerImpl method runInBackground.
protected void runInBackground(UiReportRunContext context, Screen hostScreen) {
Report targetReport = getReportForPrinting(context.getReport());
long timeout = reportsClientProperties.getBackgroundReportProcessingTimeoutMs();
BackgroundTask<Integer, ReportOutputDocument> task = new BackgroundTask<Integer, ReportOutputDocument>(timeout, TimeUnit.MILLISECONDS, hostScreen) {
@SuppressWarnings("UnnecessaryLocalVariable")
@Override
public ReportOutputDocument run(TaskLifeCycle<Integer> taskLifeCycle) {
context.setReport(targetReport);
ReportOutputDocument result = reportRunner.run(context.getReportRunContext());
return result;
}
@Override
public boolean handleException(Exception ex) {
if (ex instanceof ReportingException) {
if (ex instanceof FailedToConnectToOpenOfficeException) {
String caption = messages.getMessage("io.jmix.reportsui.exception", "reportException.failedConnectToOffice");
return showErrorNotification(caption);
} else if (ex instanceof NoOpenOfficeFreePortsException) {
String caption = messages.getMessage("io.jmix.reportsui.exception", "reportException.noOpenOfficeFreePorts");
return showErrorNotification(caption);
}
}
return super.handleException(ex);
}
protected boolean showErrorNotification(String text) {
Screen ownerScreen = this.getOwnerScreen();
if (ownerScreen != null) {
ScreenContext screenContext = ComponentsHelper.getScreenContext(ownerScreen.getWindow());
Notifications notifications = screenContext.getNotifications();
notifications.create().withCaption(text).withType(Notifications.NotificationType.ERROR).show();
return true;
}
return false;
}
@Override
public void done(ReportOutputDocument document) {
showResult(document, context);
}
@Override
public void canceled() {
super.canceled();
// todo https://github.com/Haulmont/jmix-reports/issues/22
// reportService.cancelReportExecution(userSessionId, report.getId());
}
};
showDialog(task);
}
use of io.jmix.ui.executor.TaskLifeCycle in project jmix by jmix-framework.
the class UiReportRunnerImpl method runMultipleReports.
@Override
public void runMultipleReports(UiReportRunContext context, String multiParamAlias, Collection multiParamValue) {
prepareContext(context);
if (needToShowParamsDialog(context)) {
context.addParam(multiParamAlias, multiParamValue);
openReportParamsDialog(context, getInputParameter(context, multiParamAlias), true);
return;
}
FrameOwner originFrameOwner = context.getOriginFrameOwner();
if (originFrameOwner != null && context.getInBackground()) {
Report targetReport = getReportForPrinting(context.getReport());
long timeout = reportsClientProperties.getBackgroundReportProcessingTimeoutMs();
Screen hostScreen = UiControllerUtils.getScreen(originFrameOwner);
BackgroundTask<Integer, List<ReportOutputDocument>> task = new BackgroundTask<Integer, List<ReportOutputDocument>>(timeout, TimeUnit.MILLISECONDS, hostScreen) {
@SuppressWarnings("UnnecessaryLocalVariable")
@Override
public List<ReportOutputDocument> run(TaskLifeCycle<Integer> taskLifeCycle) {
context.setReport(targetReport);
return multiRunSync(context, multiParamAlias, multiParamValue);
}
@Override
public void done(List<ReportOutputDocument> result) {
downloadZipArchive(result);
}
};
showDialog(task);
} else {
List<ReportOutputDocument> outputDocuments = multiRunSync(context, multiParamAlias, multiParamValue);
downloadZipArchive(outputDocuments);
}
}
Aggregations