Git log: don't ask current user on AWT when Git log manager component initialization
authorirengrig <Irina.Chernushina@jetbrains.com>
Thu, 15 Apr 2010 12:15:27 +0000 (16:15 +0400)
committerirengrig <Irina.Chernushina@jetbrains.com>
Thu, 15 Apr 2010 12:15:27 +0000 (16:15 +0400)
platform/util/src/com/intellij/util/CatchingConsumer.java [new file with mode: 0644]
platform/vcs-api/src/com/intellij/util/CalculateContinuation.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/history/browser/GitProjectLogManager.java

diff --git a/platform/util/src/com/intellij/util/CatchingConsumer.java b/platform/util/src/com/intellij/util/CatchingConsumer.java
new file mode 100644 (file)
index 0000000..dc40bcb
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.util;
+
+public interface CatchingConsumer<T, E extends Throwable> extends Consumer<T> {
+  void consume(E e);
+}
diff --git a/platform/vcs-api/src/com/intellij/util/CalculateContinuation.java b/platform/vcs-api/src/com/intellij/util/CalculateContinuation.java
new file mode 100644 (file)
index 0000000..44cb16a
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.util;
+
+import com.intellij.openapi.application.Application;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Ref;
+import com.intellij.openapi.util.ThrowableComputable;
+
+public class CalculateContinuation<T> {
+  public void calculateAndContinue(final ThrowableComputable<T, Exception> computable, final CatchingConsumer<T, Exception> consumer) {
+    final Application application = ApplicationManager.getApplication();
+
+    application.assertIsDispatchThread();
+
+    final Ref<T> t = new Ref<T>();
+    application.executeOnPooledThread(new Runnable() {
+      public void run() {
+        try {
+          t.set(computable.compute());
+        }
+        catch (final Exception e) {
+          application.invokeLater(new Runnable() {
+            public void run() {
+              consumer.consume(e);
+            }
+          });
+        }
+
+        application.invokeLater(new Runnable() {
+          public void run() {
+            consumer.consume(t.get());
+          }
+        });
+      }
+    });
+  }
+}
index 0784477456940d93a4ae017760f49deebd53f012..0bffd91075875e9b6b52c999d2fa792aefad0398 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.DumbAwareRunnable;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.startup.StartupManager;
+import com.intellij.openapi.util.ThrowableComputable;
 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.VcsListener;
@@ -28,6 +29,8 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.content.Content;
 import com.intellij.ui.content.ContentFactory;
+import com.intellij.util.CalculateContinuation;
+import com.intellij.util.CatchingConsumer;
 import com.intellij.util.containers.HashMap;
 import git4idea.GitBranchesSearcher;
 import git4idea.GitVcs;
@@ -90,7 +93,7 @@ public class GitProjectLogManager implements ProjectComponent {
 
     final VirtualFile baseDir = myProject.getBaseDir();
     final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
-    for (VirtualFile root : roots) {
+    for (final VirtualFile root : roots) {
       if (! currentState.containsKey(root)) {
         final GitLogTree tree = new GitLogTree(myProject, root);
         tree.setParentDisposable(myProject);
@@ -99,6 +102,19 @@ public class GitProjectLogManager implements ProjectComponent {
         content.setCloseable(false);
         cvcm.addContent(content);
         newKeys.put(root, content);
+        
+        new CalculateContinuation<String>().calculateAndContinue(new ThrowableComputable<String, Exception>() {
+          public String compute() throws Exception {
+            return getCaption(baseDir, root);
+          }
+        }, new CatchingConsumer<String, Exception>() {
+          public void consume(Exception e) {
+            //should not
+          }
+          public void consume(final String caption) {
+            content.setDisplayName(caption);
+          }
+        });
       }
     }
 
@@ -111,7 +127,7 @@ public class GitProjectLogManager implements ProjectComponent {
   }
 
   private String getCaption(@Nullable VirtualFile baseDir, final VirtualFile root) {
-    String result = root.getPresentableUrl();
+    String result = root.getPresentableUrl();                                                                                      
     if (baseDir != null) {
       if (baseDir.equals(root)) {
         result = "<Project root>";