VCS: fix group by structure for Changes | Local
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / CallbackData.java
blobef53214d11ea60158d4afbcd8d271061512594de
1 /*
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;
27 import javax.swing.*;
29 class CallbackData {
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() {
40 return myCallback;
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() {
51 public void run() {
52 if (mode.isCallbackOnAwt()) {
53 SwingUtilities.invokeLater(new Runnable() {
54 public void run() {
55 LOG.debug("invokeAfterUpdate: silent wrapper called for project: " + project.getName());
56 if (project.isDisposed()) return;
57 afterUpdate.run();
58 ChangesViewManager.getInstance(project).refreshView();
60 });
61 } else {
62 ApplicationManager.getApplication().executeOnPooledThread(afterUpdate);
65 }, null);
66 } else {
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(
71 new Runnable() {
72 public void run() {
73 LOG.debug("invokeAfterUpdate: NOT silent SYNCHRONOUS wrapper called for project: " + project.getName());
74 waiter.done();
76 }, new Runnable() {
77 public void run() {
78 ProgressManager.getInstance().run(waiter);
82 } else {
83 final FictiveBackgroundable fictiveBackgroundable = new FictiveBackgroundable(project, afterUpdate, mode.isCancellable(), title, state);
84 return new CallbackData(
85 new Runnable() {
86 public void run() {
87 LOG.debug("invokeAfterUpdate: NOT silent wrapper called for project: " + project.getName());
88 fictiveBackgroundable.done();
90 }, new Runnable() {
91 public void run() {
92 ProgressManager.getInstance().run(fictiveBackgroundable);
94 });