vcs: Inlined "GenericDetailsLoader" logic to "AbstractRefreshablePanel"

This commit is contained in:
Konstantin Kolosovsky
2016-11-16 21:01:56 +03:00
parent 230af93ea1
commit 281d909b32
3 changed files with 26 additions and 76 deletions
@@ -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;
}
}
@@ -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
@@ -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;