2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.progress
;
18 import com
.intellij
.openapi
.components
.ServiceManager
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import org
.jetbrains
.annotations
.Nls
;
21 import org
.jetbrains
.annotations
.NonNls
;
22 import org
.jetbrains
.annotations
.NotNull
;
23 import org
.jetbrains
.annotations
.Nullable
;
27 public abstract class ProgressManager
{
28 private static final ProgressManager ourInstance
= ServiceManager
.getService(ProgressManager
.class);
30 public static ProgressManager
getInstance() {
34 public abstract boolean hasProgressIndicator();
35 public abstract boolean hasModalProgressIndicator();
36 public abstract boolean hasUnsafeProgressIndicator();
38 public abstract void runProcess(Runnable process
, ProgressIndicator progress
) throws ProcessCanceledException
;
40 public abstract ProgressIndicator
getProgressIndicator();
42 protected static boolean ourNeedToCheckCancel
= false;
43 public static void checkCanceled() throws ProcessCanceledException
{
44 // smart optimization! There's a thread started in ProgressManagerImpl, that set's this flag up once in 10 milliseconds
45 if (ourNeedToCheckCancel
) {
46 ourNeedToCheckCancel
= false;
47 getInstance().doCheckCanceled();
51 protected abstract void doCheckCanceled() throws ProcessCanceledException
;
54 public abstract void registerFunComponentProvider(ProgressFunComponentProvider provider
);
56 public abstract void removeFunComponentProvider(ProgressFunComponentProvider provider
);
57 public abstract JComponent
getProvidedFunComponent(Project project
, @NonNls String processId
);
59 public abstract void executeNonCancelableSection(Runnable r
);
60 public abstract NonCancelableSection
startNonCancelableSection();
62 public abstract void setCancelButtonText(String cancelButtonText
);
66 * Runs the specified operation in a background thread and shows a modal progress dialog in the
67 * main thread while the operation is executing.
69 * @param process the operation to execute.
70 * @param progressTitle the title of the progress window.
71 * @param canBeCanceled whether "Cancel" button is shown on the progress window.
72 * @param project the project in the context of which the operation is executed.
73 * @return true if the operation completed successfully, false if it was cancelled.
75 public abstract boolean runProcessWithProgressSynchronously(@NotNull Runnable process
,
76 @Nls String progressTitle
,
77 boolean canBeCanceled
,
81 * Runs the specified operation in a background thread and shows a modal progress dialog in the
82 * main thread while the operation is executing.
84 * @param process the operation to execute.
85 * @param progressTitle the title of the progress window.
86 * @param canBeCanceled whether "Cancel" button is shown on the progress window.
87 * @param project the project in the context of which the operation is executed.
88 * @param parentComponent the component which will be used to calculate the progress window ancestor
89 * @return true if the operation completed successfully, false if it was cancelled.
91 public abstract boolean runProcessWithProgressSynchronously(@NotNull Runnable process
, @Nls String progressTitle
, boolean canBeCanceled
,
92 Project project
, JComponent parentComponent
);
95 * Runs a specified <code>process</code> in a background thread and shows a progress dialog, which can be made non-modal by pressing
96 * background button. Upon successfull termination of the process a <code>successRunnable</code> will be called in Swing UI thread and
97 * <code>canceledRunnable</code> will be called if terminated on behalf of the user by pressing either cancel button, while running in
98 * a modal state or stop button if running in background.
100 * @param project the project in the context of which the operation is executed.
101 * @param progressTitle the title of the progress window.
102 * @param process the operation to execute.
103 * @param successRunnable a callback to be called in Swing UI thread upon normal termination of the process.
104 * @param canceledRunnable a callback to be called in Swing UI thread if the process have been canceled by the user.
105 * @deprecated use {@link #run(com.intellij.openapi.progress.Task)}
107 public abstract void runProcessWithProgressAsynchronously(@NotNull Project project
,
108 @NotNull @Nls String progressTitle
,
109 @NotNull Runnable process
,
110 @Nullable Runnable successRunnable
,
111 @Nullable Runnable canceledRunnable
);
113 * Runs a specified <code>process</code> in a background thread and shows a progress dialog, which can be made non-modal by pressing
114 * background button. Upon successfull termination of the process a <code>successRunnable</code> will be called in Swing UI thread and
115 * <code>canceledRunnable</code> will be called if terminated on behalf of the user by pressing either cancel button, while running in
116 * a modal state or stop button if running in background.
118 * @param project the project in the context of which the operation is executed.
119 * @param progressTitle the title of the progress window.
120 * @param process the operation to execute.
121 * @param successRunnable a callback to be called in Swing UI thread upon normal termination of the process.
122 * @param canceledRunnable a callback to be called in Swing UI thread if the process have been canceled by the user.
123 * @param option progress indicator behavior controller.
124 * @deprecated use {@link #run(com.intellij.openapi.progress.Task)}
126 public abstract void runProcessWithProgressAsynchronously(@NotNull Project project
,
127 @NotNull @Nls String progressTitle
,
128 @NotNull Runnable process
,
129 @Nullable Runnable successRunnable
,
130 @Nullable Runnable canceledRunnable
,
131 @NotNull PerformInBackgroundOption option
);
134 * Runs a specified <code>task</code> in either background/foreground thread and shows a progress dialog.
135 * @param task task to run (either {@link com.intellij.openapi.progress.Task.Modal} or {@link com.intellij.openapi.progress.Task.Backgroundable}).
137 public abstract void run(@NotNull Task task
);