Skip to content

Commit

Permalink
Background tasks #1160
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaurite committed Feb 7, 2023
1 parent e3deeb2 commit d8bd790
Show file tree
Hide file tree
Showing 30 changed files with 2,590 additions and 6 deletions.
82 changes: 81 additions & 1 deletion jmix-flowui/flowui/src/main/java/io/jmix/flowui/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import io.jmix.flowui.app.inputdialog.InputDialog;
import io.jmix.flowui.app.inputdialog.InputParameter;
import io.jmix.flowui.component.validation.ValidationErrors;
import io.jmix.flowui.backgroundtask.BackgroundTask;
import io.jmix.flowui.kit.action.Action;
import io.jmix.flowui.view.DialogWindow;
import io.jmix.flowui.view.View;

import javax.annotation.Nullable;
import java.util.Locale;
import java.util.function.Consumer;
import java.util.function.Function;

Expand Down Expand Up @@ -97,6 +97,25 @@ public interface Dialogs {
*/
InputDialogBuilder createInputDialog(View<?> origin);

/**
* Creates background task dialog builder.
* <br>
* Example of showing a background task dialog:
* <pre>
* dialogs.createBackgroundTaskDialog(backgroundTask)
* .withHeader("Task")
* .withText("My Task is Running")
* .withTotal(10)
* .withShowProgressInPercentage(true)
* .withCancelAllowed(true)
* .open();
* </pre>
*
* @param backgroundTask background task to run
* @return builder
*/
<T extends Number, V> BackgroundTaskDialogBuilder<T, V> createBackgroundTaskDialog(BackgroundTask<T, V> backgroundTask);

interface OptionDialogBuilder extends DialogBuilder<OptionDialogBuilder>,
HasText<OptionDialogBuilder>,
HasContent<OptionDialogBuilder>,
Expand Down Expand Up @@ -326,6 +345,67 @@ enum LabelsPosition {
}
}

/**
* Builder of background task dialog.
*/
interface BackgroundTaskDialogBuilder<T extends Number, V> extends
HasHeader<BackgroundTaskDialogBuilder<T, V>>,
HasText<BackgroundTaskDialogBuilder<T, V>>,
HasTheme<BackgroundTaskDialogBuilder<T, V>>,
HasStyle<BackgroundTaskDialogBuilder<T, V>>,
Draggable<BackgroundTaskDialogBuilder<T, V>>,
Resizable<BackgroundTaskDialogBuilder<T, V>> {

/**
* Determines whether the dialog can be closed.
* <p>
* The default value is {@code false}.
*
* @param cancelAllowed {@code true} if dialog is closeable
* @return builder
*/
BackgroundTaskDialogBuilder<T, V> withCancelAllowed(boolean cancelAllowed);

/**
* @return {@code true} if the dialog can be closed
*/
boolean isCancelAllowed();

/**
* Sets amount of items to be processed by background task.
* <br>
* Use {@link io.jmix.flowui.backgroundtask.TaskLifeCycle#publish(Object[])} to notify the dialog about progress
* completion.
*
* @param total amount of items to be processed by background task,
* @return builder
*/
BackgroundTaskDialogBuilder<T, V> withTotal(Number total);

/**
* @return amount of items to be processed by background task
*/
Number getTotal();

/**
* Sets whether progress should be represented as percentage (rather than as raw number).
*
* @param percentProgress {@code true} to show progress in percents
* @return builder
*/
BackgroundTaskDialogBuilder<T, V> withShowProgressInPercentage(boolean percentProgress);

/**
* @return {@code true} if progress should is shown in percents
*/
boolean isShowProgressInPercentage();

/**
* Opens the dialog.
*/
void open();
}

/**
* Base class for all Dialog Builders.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020 Haulmont.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.jmix.flowui;

import io.jmix.core.TimeSource;
import io.jmix.flowui.backgroundtask.FlowuiBackgroundTaskProperties;
import io.jmix.flowui.backgroundtask.BackgroundTaskWatchDog;
import io.jmix.flowui.backgroundtask.impl.BackgroundTaskWatchDogImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@Configuration(proxyBeanMethods = false)
public class FlowuiScheduleConfiguration {

@Bean("flowui_ThreadPoolTaskScheduler")
public TaskScheduler threadPoolTaskScheduler() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setThreadNamePrefix("flowui_backgroundScheduler-");
threadPoolTaskScheduler.setPoolSize(1);
threadPoolTaskScheduler.setDaemon(true);
return threadPoolTaskScheduler;
}

@Bean("flowui_BackgroundWorkerWatchDog")
public BackgroundTaskWatchDog watchDog(FlowuiBackgroundTaskProperties properties, TimeSource timeSource) {
return new BackgroundTaskWatchDogImpl(properties, timeSource);
}
}
Loading

0 comments on commit d8bd790

Please sign in to comment.