Files
openide/platform/progress/shared/src/TaskCancellation.kt
Kate Botsman 35f17aa034 RDCT-1444 Add TaskInfoEntity
This entity is going to represent running progress in Rhizome DB.
The data is mostly copied from `PlatformTaskSupport.ProgressStartedEvent` structure.

Few differences here:
- No `CoroutineContext` in the entity

It's not possible to put the actual coroutine context to `SharedEntity` because it's not serializable.
The context is used mostly for cancellation of a job. The possibility to cancel a job will be provided through a different API.

- New `TaskStatus` field

The status represents the actual status of a task, whether it's running, paused or canceled.

Also:

- Added utils which should make working with `TasksInfoEntity` easier

The utils are queries, which allow avoiding writing the same `asQuery().getOne` in every place where tasks info needs to be retrieved.

- Marked classes used in `TaskInfoEntity` as `@Serializable`

All data used in `SharedEntities` have to be serializable, otherwise it won't be possible to put entity to shared DB

- Add `kotlinx/serialization/KSerializer` to `ideaProjectStructure/exposed-third-party`

With Rhizome `KSerializer` is going to be exposed in more places. Therefore, it makes sense to add this class to default `exposed-third-party-api`, so the tests won't fail because of the added `@Serializable` annotation.

GitOrigin-RevId: 1a1b979b7660d41879a40a4d28b6487b3205e743
2024-09-09 14:33:01 +00:00

47 lines
1.5 KiB
Kotlin

// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.platform.ide.progress
import com.intellij.openapi.util.NlsContexts
import kotlinx.serialization.Serializable
import org.jetbrains.annotations.Contract
@Serializable
sealed interface TaskCancellation {
@Serializable
sealed interface NonCancellable : TaskCancellation
@Serializable
sealed interface Cancellable : TaskCancellation {
@Contract(value = "_ -> new", pure = true)
fun withButtonText(buttonText: @NlsContexts.Button String): Cancellable
@Contract(value = "_ -> new", pure = true)
fun withTooltipText(tooltipText: @NlsContexts.Tooltip String): Cancellable
}
companion object {
/**
* @return a cancellation instance, which means that the cancel button should not be displayed in the UI
*/
@Contract(pure = true)
@JvmStatic
fun nonCancellable(): NonCancellable {
return NonCancellableTaskCancellation
}
/**
* The returned instance can optionally be customized with button text and/or tooltip text.
* If [the button text][Cancellable.withButtonText] is not specified,
* then [the default text][com.intellij.CommonBundle.getCancelButtonText] is used.
*
* @return a cancellation instance, which means that the cancel button should be displayed in the UI
*/
@Contract(pure = true)
@JvmStatic
fun cancellable(): Cancellable {
return CancellableTaskCancellation.DEFAULT
}
}
}