Package com.vladsch.plugin.util
Class OneTimeRunnable
- java.lang.Object
-
- com.vladsch.plugin.util.AwtRunnable
-
- com.vladsch.plugin.util.OneTimeRunnable
-
- All Implemented Interfaces:
Cancellable,CancellableRunnable,java.lang.Runnable
public class OneTimeRunnable extends AwtRunnable implements CancellableRunnable
Used to create a task that can be run at most once and the run can be cancelled before it has run, in which case further attempts to run it will do nothing.Can also specify that it should run on the AWT thread, otherwise it will run on the application thread
Useful for triggering actions after a delay that may need to be run before the delay triggers
-
-
Field Summary
Fields Modifier and Type Field Description static OneTimeRunnableNULL
-
Constructor Summary
Constructors Constructor Description OneTimeRunnable(boolean awtThread, java.lang.Runnable command)OneTimeRunnable(@NotNull java.lang.Runnable command)OneTimeRunnable(@NotNull java.lang.String id, boolean awtThread, @Nullable com.intellij.openapi.application.ModalityState modalityState, java.lang.Runnable command)OneTimeRunnable(@NotNull java.lang.String id, boolean awtThread, java.lang.Runnable command)OneTimeRunnable(@NotNull java.lang.String id, @NotNull java.lang.Runnable command)OneTimeRunnable(@NotNull java.lang.String id, com.intellij.openapi.application.ModalityState modalityState, java.lang.Runnable command)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel()Cancels the scheduled task run if it has not run yetbooleancanRun()Tests whether it has run or been cancelled@NotNull java.lang.StringgetId()voidrun()static OneTimeRunnableschedule(@NotNull CancelableJobScheduler scheduler, int delay, @NotNull CancellableRunnable command)static OneTimeRunnableschedule(@NotNull CancelableJobScheduler scheduler, int delay, @NotNull OneTimeRunnable command)static OneTimeRunnableschedule(@NotNull CancelableJobScheduler scheduler, int delay, @NotNull java.lang.Runnable command)static OneTimeRunnableschedule(@NotNull CancelableJobScheduler scheduler, @NotNull java.lang.String id, int delay, @NotNull java.lang.Runnable command)Creates a one-shot runnable that will run after a delay, can be run early, or cancelledstatic OneTimeRunnableschedule(CancelableJobScheduler scheduler, @NotNull java.lang.String id, int delay, @Nullable com.intellij.openapi.application.ModalityState modalityState, @NotNull java.lang.Runnable command)Creates a one-shot runnable that will run after a delay, can be run early, or cancelled-
Methods inherited from class com.vladsch.plugin.util.AwtRunnable
getCommand, isAwtThread
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vladsch.plugin.util.CancellableRunnable
isNotNull, isNull
-
-
-
-
Field Detail
-
NULL
public static final OneTimeRunnable NULL
-
-
Constructor Detail
-
OneTimeRunnable
public OneTimeRunnable(@NotNull @NotNull java.lang.String id, com.intellij.openapi.application.ModalityState modalityState, java.lang.Runnable command)
-
OneTimeRunnable
public OneTimeRunnable(@NotNull @NotNull java.lang.Runnable command)
-
OneTimeRunnable
public OneTimeRunnable(@NotNull @NotNull java.lang.String id, @NotNull @NotNull java.lang.Runnable command)
-
OneTimeRunnable
public OneTimeRunnable(@NotNull @NotNull java.lang.String id, boolean awtThread, java.lang.Runnable command)
-
OneTimeRunnable
public OneTimeRunnable(boolean awtThread, java.lang.Runnable command)
-
OneTimeRunnable
public OneTimeRunnable(@NotNull @NotNull java.lang.String id, boolean awtThread, @Nullable @Nullable com.intellij.openapi.application.ModalityState modalityState, java.lang.Runnable command)
-
-
Method Detail
-
cancel
public boolean cancel()
Cancels the scheduled task run if it has not run yet- Specified by:
cancelin interfaceCancellable- Returns:
- true if cancelled, false if it has already run
-
canRun
public boolean canRun()
Tests whether it has run or been cancelled- Specified by:
canRunin interfaceCancellable- Returns:
- false if cancelled or has run, true still can run later
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classAwtRunnable
-
getId
@NotNull public @NotNull java.lang.String getId()
- Specified by:
getIdin interfaceCancellableRunnable
-
schedule
public static OneTimeRunnable schedule(@NotNull @NotNull CancelableJobScheduler scheduler, @NotNull @NotNull java.lang.String id, int delay, @NotNull @NotNull java.lang.Runnable command)
Creates a one-shot runnable that will run after a delay, can be run early, or cancelledthe given command will only be executed once, either by the delayed trigger or by the run method. if you want to execute the task early just invoke #run, it will do nothing if the task has already run.
- Parameters:
scheduler- job scheduler to useid- id of the jobdelay- the time from now to delay executioncommand- the task to execute- Returns:
- a
OneTimeRunnablewhich will run after the given delay or ifrun()is invoked beforecancel()is invoked - Throws:
java.lang.NullPointerException- if command is null
-
schedule
public static OneTimeRunnable schedule(@NotNull @NotNull CancelableJobScheduler scheduler, int delay, @NotNull @NotNull java.lang.Runnable command)
-
schedule
public static OneTimeRunnable schedule(@NotNull @NotNull CancelableJobScheduler scheduler, int delay, @NotNull @NotNull CancellableRunnable command)
-
schedule
public static OneTimeRunnable schedule(@NotNull @NotNull CancelableJobScheduler scheduler, int delay, @NotNull @NotNull OneTimeRunnable command)
-
schedule
public static OneTimeRunnable schedule(CancelableJobScheduler scheduler, @NotNull @NotNull java.lang.String id, int delay, @Nullable @Nullable com.intellij.openapi.application.ModalityState modalityState, @NotNull @NotNull java.lang.Runnable command)
Creates a one-shot runnable that will run after a delay, can be run early, or cancelledthe given command will only be executed once, either by the delayed trigger or by the run method. if you want to execute the task early just invoke #run, it will do nothing if the task has already run.
- Parameters:
scheduler- job scheduler to useid- id of the jobdelay- the time from now to delay executionmodalityState- the modality state to run the job incommand- the task to execute- Returns:
- a
CancellableRunnablewhich will run after the given delay on the AwtThread ifrun()is invoked beforeCancellable.cancel() - Throws:
java.lang.NullPointerException- if command is null
-
-