Search in sources :

Example 1 with BackgroundTaskHandler

use of io.jmix.ui.executor.BackgroundTaskHandler 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();
}
Also used : TaskLifeCycle(io.jmix.ui.executor.TaskLifeCycle) List(java.util.List) BackgroundTaskHandler(io.jmix.ui.executor.BackgroundTaskHandler) BackgroundTask(io.jmix.ui.executor.BackgroundTask)

Example 2 with BackgroundTaskHandler

use of io.jmix.ui.executor.BackgroundTaskHandler 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();
}
Also used : TaskLifeCycle(io.jmix.ui.executor.TaskLifeCycle) List(java.util.List) BackgroundTaskHandler(io.jmix.ui.executor.BackgroundTaskHandler) BackgroundTask(io.jmix.ui.executor.BackgroundTask) Subscribe(io.jmix.ui.screen.Subscribe)

Example 3 with BackgroundTaskHandler

use of io.jmix.ui.executor.BackgroundTaskHandler in project jmix by jmix-framework.

the class ImapMessageEdit method initBody.

protected void initBody(ImapMessage msg, AtomicInteger loadProgress) {
    BackgroundTaskHandler taskHandler = backgroundWorker.handle(new InitBodyTask(msg, loadProgress));
    taskHandler.execute();
}
Also used : BackgroundTaskHandler(io.jmix.ui.executor.BackgroundTaskHandler)

Example 4 with BackgroundTaskHandler

use of io.jmix.ui.executor.BackgroundTaskHandler in project jmix by jmix-framework.

the class ImapMessageEdit method initAttachments.

protected void initAttachments(ImapMessage msg, AtomicInteger loadProgress) {
    if (!Boolean.TRUE.equals(msg.getAttachmentsLoaded())) {
        BackgroundTaskHandler taskHandler = backgroundWorker.handle(new InitAttachmentTask(msg, loadProgress));
        taskHandler.execute();
    } else {
        hideProgressBar(loadProgress);
    }
}
Also used : BackgroundTaskHandler(io.jmix.ui.executor.BackgroundTaskHandler)

Aggregations

BackgroundTaskHandler (io.jmix.ui.executor.BackgroundTaskHandler)4 BackgroundTask (io.jmix.ui.executor.BackgroundTask)2 TaskLifeCycle (io.jmix.ui.executor.TaskLifeCycle)2 List (java.util.List)2 Subscribe (io.jmix.ui.screen.Subscribe)1