vcs: Refactored "ModalityIgnorantBackgroundableTask"
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Thu, 3 Nov 2016 15:36:27 +0000 (18:36 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Wed, 16 Nov 2016 18:01:56 +0000 (21:01 +0300)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java
platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/VcsMappingConfigurationDialog.java
platform/vcs-impl/src/com/intellij/util/continuation/ModalityIgnorantBackgroundableTask.java
plugins/svn4idea/src/org/jetbrains/idea/svn/branchConfig/SelectBranchPopup.java

index 1b9e4f7059d6856f2e3c0fa2641838631faeecfb..a5661d6182c9a0847a63886cf7ddc04ff978c287 100644 (file)
@@ -56,11 +56,10 @@ public abstract class AbstractRefreshablePanel<T> implements RefreshablePanel<Ch
     myDetailsPanel = new DetailsPanel();
     myDetailsPanel.loading();
     myDetailsPanel.layout();
-    
-    myDetailsLoader = new GenericDetailsLoader<>(ticket -> {
-      final Loader loader = new Loader(project, loadingTitle, myTicket.copy());
-      loader.runSteadily(backgroundable -> myQueue.run(backgroundable));
-    }, (ticket, t) -> acceptData(t));
+
+    myDetailsLoader = new GenericDetailsLoader<>(
+      ticket -> myQueue.run(new Loader(project, loadingTitle, myTicket.copy())),
+      (ticket, t) -> acceptData(t));
   }
 
   @Override
@@ -125,7 +124,7 @@ public abstract class AbstractRefreshablePanel<T> implements RefreshablePanel<Ch
     }
 
     @Override
-    protected void doInAwtIfFail(Exception e) {
+    protected void doInAwtIfFail(@NotNull Exception e) {
       final Exception cause;
       if (e instanceof RuntimeException && e.getCause() != null) {
         cause = (Exception) e.getCause();
index efd4a03d71aacda69776c25e8bd0063bf99b0736..048250ee9d8aa3c291a4f9a21566f53c4d8c403f 100644 (file)
@@ -202,7 +202,7 @@ public class VcsMappingConfigurationDialog extends DialogWrapper {
             VcsDescriptor probableVcs = null;
 
             @Override
-            protected void doInAwtIfFail(Exception e) {
+            protected void doInAwtIfFail(@NotNull Exception e) {
             }
 
             @Override
index 4173ed82247172c800588b730e25b1cdf1710cd2..0b7e1ccdd834eb9fd6c8d3f00d82584ae7bb7c5d 100644 (file)
 package com.intellij.util.continuation;
 
 import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.progress.PerformInBackgroundOption;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.Task;
 import com.intellij.openapi.project.Project;
-import com.intellij.util.Consumer;
-import com.intellij.util.TimeoutUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 
-/**
- * Created by IntelliJ IDEA.
- * User: Irina.Chernushina
- * Date: 8/19/11
- * Time: 12:14 PM
- */
 public abstract class ModalityIgnorantBackgroundableTask extends Task.Backgroundable {
-  private final static Logger LOG = Logger.getInstance("#com.intellij.util.continuation.ModalityIgnorantBackgroundableTask");
-  private Consumer<Task.Backgroundable> myRunner;
-  private int myCnt;
-
-  public ModalityIgnorantBackgroundableTask(@Nullable Project project,
-                                            @NotNull String title,
-                                            boolean canBeCancelled,
-                                            @Nullable PerformInBackgroundOption backgroundOption) {
-    super(project, title, canBeCancelled, backgroundOption);
-  }
+  private final static Logger LOG = Logger.getInstance(ModalityIgnorantBackgroundableTask.class);
 
-  public ModalityIgnorantBackgroundableTask(@Nullable Project project,
-                                            @NotNull String title,
-                                            boolean canBeCancelled) {
+  public ModalityIgnorantBackgroundableTask(@Nullable Project project, @NotNull String title, boolean canBeCancelled) {
     super(project, title, canBeCancelled);
   }
 
-  public ModalityIgnorantBackgroundableTask(@Nullable Project project, @NotNull String title) {
-    super(project, title);
-  }
-
-  protected abstract void doInAwtIfFail(final Exception e);
+  protected abstract void doInAwtIfFail(@NotNull Exception e);
   protected abstract void doInAwtIfCancel();
   protected abstract void doInAwtIfSuccess();
   protected abstract void runImpl(@NotNull ProgressIndicator indicator);
 
-  public void runSteadily(final Consumer<Backgroundable> consumer) {
-    myRunner = consumer;
-    myCnt = 100;
-    consumer.consume(this);
-  }
-
   @Override
-  public void run(@NotNull final ProgressIndicator indicator) {
+  public void run(@NotNull ProgressIndicator indicator) {
     try {
       runImpl(indicator);
-    } catch (final ToBeRepeatedException tbre) {
-      if (myRunner != null && myCnt > 0) {
-        -- myCnt;
-        // we are on some background thread and do not want to reschedule too often
-        TimeoutUtil.sleep(100);
-        myRunner.consume(this);
-        return;
-      }
-      SwingUtilities.invokeLater(new Runnable() {
-        @Override
-        public void run() {
-          doInAwtIfFail(tbre);
-        }
-      });
-    } catch (final Exception e) {
+    }
+    catch (Exception e) {
       LOG.info(e);
-      SwingUtilities.invokeLater(new Runnable() {
-        @Override
-        public void run() {
-          doInAwtIfFail(e);
-        }
-      });
+      SwingUtilities.invokeLater(() -> doInAwtIfFail(e));
       return;
     }
 
-    SwingUtilities.invokeLater(new Runnable() {
-      @Override
-      public void run() {
-        if (indicator.isCanceled()) {
-          doInAwtIfCancel();
-        } else {
-          doInAwtIfSuccess();
-        }
+    SwingUtilities.invokeLater(() -> {
+      if (indicator.isCanceled()) {
+        doInAwtIfCancel();
+      }
+      else {
+        doInAwtIfSuccess();
       }
     });
   }
-
-  public static class ToBeRepeatedException extends RuntimeException {}
 }
index e2c5300181cbbcc483b26f4a82a788e219f14fa5..ed0b987f56baa78335786a187e3ff111449bbbf7 100644 (file)
@@ -197,9 +197,9 @@ public class SelectBranchPopup {
     @Nullable
     private void loadBranches(final String selectedBranchesHolder, final Runnable runnable) {
       final ProgressManager pm = ProgressManager.getInstance();
-      pm.run(new ModalityIgnorantBackgroundableTask(myProject, SvnBundle.message("compare.with.branch.progress.loading.branches")) {
+      pm.run(new ModalityIgnorantBackgroundableTask(myProject, SvnBundle.message("compare.with.branch.progress.loading.branches"), true) {
         @Override
-        protected void doInAwtIfFail(Exception e) {
+        protected void doInAwtIfFail(@NotNull Exception e) {
           runnable.run();
         }