vcs: Inlined "GenericDetailsLoader" logic to "AbstractRefreshablePanel"
authorKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Fri, 4 Nov 2016 13:02:10 +0000 (16:02 +0300)
committerKonstantin Kolosovsky <konstantin.kolosovsky@jetbrains.com>
Wed, 16 Nov 2016 18:01:56 +0000 (21:01 +0300)
platform/vcs-api/src/com/intellij/openapi/vcs/GenericDetailsLoader.java [deleted file]
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/AbstractRefreshablePanel.java
plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java

diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/GenericDetailsLoader.java b/platform/vcs-api/src/com/intellij/openapi/vcs/GenericDetailsLoader.java
deleted file mode 100644 (file)
index 21d72cf..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2000-2011 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.openapi.vcs;
-
-import com.intellij.openapi.util.Comparing;
-import com.intellij.util.Consumer;
-import com.intellij.util.PairConsumer;
-import org.jetbrains.annotations.CalledInAwt;
-import org.jetbrains.annotations.Nullable;
-
-public class GenericDetailsLoader<Id, Data> implements Details<Id, Data> {
-  private final Consumer<Id> myLoader;
-  private final PairConsumer<Id, Data> myValueConsumer;
-  private Id myCurrentlySelected;
-  private Id mySetId;
-
-  /**
-   * @param loader - is called in AWT. Should call {@link #take} with data when ready. Also in AWT
-   * @param valueConsumer - is called in AWT. passive, just benefits from details loading
-   */
-  public GenericDetailsLoader(Consumer<Id> loader, PairConsumer<Id, Data> valueConsumer) {
-    myLoader = loader;
-    myValueConsumer = valueConsumer;
-  }
-
-  @CalledInAwt
-  public void updateSelection(@Nullable Id id, boolean force) {
-    Id previousId = myCurrentlySelected;
-    myCurrentlySelected = id;
-    mySetId = null;
-    if (force || !Comparing.equal(id, previousId)) {
-      myLoader.consume(id);
-    }
-  }
-
-  @CalledInAwt
-  @Override
-  public void take(Id id, Data data) {
-    if (!id.equals(mySetId) && id.equals(myCurrentlySelected)) {
-      mySetId = id;
-      myValueConsumer.consume(id, data);
-    }
-  }
-
-  @CalledInAwt
-  @Override
-  public Id getCurrentlySelected() {
-    return myCurrentlySelected;
-  }
-}
index a5661d6182c9a0847a63886cf7ddc04ff978c287..f497599fe1d4bbc111cbecdbad9bfe7aef6757e1 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.util.Comparing;
-import com.intellij.openapi.vcs.GenericDetailsLoader;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
 import com.intellij.util.continuation.ModalityIgnorantBackgroundableTask;
@@ -44,22 +43,23 @@ import javax.swing.*;
 public abstract class AbstractRefreshablePanel<T> implements RefreshablePanel<Change> {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.AbstractRefreshablePanel");
 
+  @NotNull private final Project myProject;
+  @NotNull private final String myLoadingTitle;
+  private Ticket myCurrentlySelected;
+  private Ticket mySetId;
   private final Ticket myTicket;
   private final DetailsPanel myDetailsPanel;
-  private final GenericDetailsLoader<Ticket, T> myDetailsLoader;
   private final BackgroundTaskQueue myQueue;
   private volatile boolean myDisposed;
 
-  protected AbstractRefreshablePanel(final Project project, final String loadingTitle, final BackgroundTaskQueue queue) {
+  protected AbstractRefreshablePanel(@NotNull Project project, @NotNull String loadingTitle, @NotNull BackgroundTaskQueue queue) {
+    myProject = project;
+    myLoadingTitle = loadingTitle;
     myQueue = queue;
     myTicket = new Ticket();
     myDetailsPanel = new DetailsPanel();
     myDetailsPanel.loading();
     myDetailsPanel.layout();
-
-    myDetailsLoader = new GenericDetailsLoader<>(
-      ticket -> myQueue.run(new Loader(project, loadingTitle, myTicket.copy())),
-      (ticket, t) -> acceptData(t));
   }
 
   @Override
@@ -78,10 +78,16 @@ public abstract class AbstractRefreshablePanel<T> implements RefreshablePanel<Ch
   @Override
   public void refresh() {
     ApplicationManager.getApplication().assertIsDispatchThread();
-    
-    if (! Comparing.equal(myDetailsLoader.getCurrentlySelected(), myTicket)) {
-      final Ticket copy = myTicket.copy();
-      myDetailsLoader.updateSelection(copy, false);
+
+    if (!Comparing.equal(myCurrentlySelected, myTicket)) {
+      Ticket copy = myTicket.copy();
+      Ticket previousId = myCurrentlySelected;
+      myCurrentlySelected = copy;
+      mySetId = null;
+      if (!Comparing.equal(copy, previousId)) {
+        myQueue.run(new Loader(myProject, myLoadingTitle, copy));
+      }
+
       myDetailsPanel.loading();
       myDetailsPanel.layout();
     } else {
@@ -144,7 +150,11 @@ public abstract class AbstractRefreshablePanel<T> implements RefreshablePanel<Ch
     @Override
     protected void doInAwtIfSuccess() {
       if (myDisposed) return;
-      myDetailsLoader.take(myTicketCopy, myT);
+
+      if (!myTicketCopy.equals(mySetId) && myTicketCopy.equals(myCurrentlySelected)) {
+        mySetId = myTicketCopy;
+        acceptData(myT);
+      }
     }
 
     @Override
index 8b1f5e45c9bd40f0e1a37d2e661a2daca27b6d62..075949b9f362d929e5b7fe7948640f8cfd337f8b 100644 (file)
@@ -79,7 +79,10 @@ public class TreeConflictRefreshablePanel extends AbstractRefreshablePanel {
   private final CompositeDisposable myChildDisposables = new CompositeDisposable();
   private final TLongArrayList myRightRevisionsList;
 
-  public TreeConflictRefreshablePanel(Project project, String loadingTitle, BackgroundTaskQueue queue, Change change) {
+  public TreeConflictRefreshablePanel(@NotNull Project project,
+                                      @NotNull String loadingTitle,
+                                      @NotNull BackgroundTaskQueue queue,
+                                      Change change) {
     super(project, loadingTitle, queue);
     myVcs = SvnVcs.getInstance(project);
     assert change instanceof ConflictedSvnChange;