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
.vcs
.changes
;
18 import com
.intellij
.openapi
.application
.ApplicationManager
;
19 import com
.intellij
.openapi
.application
.ModalityState
;
20 import com
.intellij
.openapi
.diagnostic
.Logger
;
21 import com
.intellij
.openapi
.progress
.ProgressManager
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.openapi
.vcs
.VcsBundle
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
30 private final static Logger LOG
= Logger
.getInstance("com.intellij.openapi.vcs.changes.CallbackData");
31 private final Runnable myCallback
;
32 private final Runnable myWrapperStarter
;
34 CallbackData(@NotNull final Runnable callback
, @Nullable final Runnable wrapperStarter
) {
35 myCallback
= callback
;
36 myWrapperStarter
= wrapperStarter
;
39 public Runnable
getCallback() {
43 public Runnable
getWrapperStarter() {
44 return myWrapperStarter
;
47 public static CallbackData
create(final Runnable afterUpdate
, final String title
, final ModalityState state
,
48 final InvokeAfterUpdateMode mode
, final Project project
) {
49 if (mode
.isSilently()) {
50 return new CallbackData(new Runnable() {
52 if (mode
.isCallbackOnAwt()) {
53 SwingUtilities
.invokeLater(new Runnable() {
55 LOG
.debug("invokeAfterUpdate: silent wrapper called for project: " + project
.getName());
56 if (project
.isDisposed()) return;
58 ChangesViewManager
.getInstance(project
).refreshView();
62 ApplicationManager
.getApplication().executeOnPooledThread(afterUpdate
);
67 if (mode
.isSynchronous()) {
68 final Waiter waiter
= new Waiter(project
, afterUpdate
, state
,
69 VcsBundle
.message("change.list.manager.wait.lists.synchronization", title
), mode
.isCancellable());
70 return new CallbackData(
73 LOG
.debug("invokeAfterUpdate: NOT silent SYNCHRONOUS wrapper called for project: " + project
.getName());
78 ProgressManager
.getInstance().run(waiter
);
83 final FictiveBackgroundable fictiveBackgroundable
= new FictiveBackgroundable(project
, afterUpdate
, mode
.isCancellable(), title
, state
);
84 return new CallbackData(
87 LOG
.debug("invokeAfterUpdate: NOT silent wrapper called for project: " + project
.getName());
88 fictiveBackgroundable
.done();
92 ProgressManager
.getInstance().run(fictiveBackgroundable
);