[vcs-log] simplify VcsProjectLog code

* VcsLogContentProvider does not scheduleInitialization when log is visible, VcsProjectLog does that;
 * VcsLogContentProvider ensures that log is created on initContent;
 * remove inheritance of ClearableLazyValue, this allows to nicely call logCreated/logDisposed when really needed;
 * createLog inits log if it is visible.
This commit is contained in:
Julia Beliaeva
2016-05-05 19:03:36 +03:00
parent 98f7c0abea
commit 31ffa78dc7
2 changed files with 22 additions and 33 deletions
@@ -18,7 +18,6 @@ package com.intellij.vcs.log.impl;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentEP;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentProvider;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
@@ -79,15 +78,11 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
@CalledInAwt
private void addLogUi() {
myContainer.add(myProjectLog.initMainLog(TAB_NAME), BorderLayout.CENTER);
VcsLogManager manager = myProjectLog.getLogManager();
assert manager != null;
if (manager.isLogVisible()) myProjectLog.scheduleInitialization();
}
@Override
public JComponent initContent() {
myProjectLog.scheduleInitialization();
myProjectLog.createLog();
return myContainer;
}
@@ -19,10 +19,10 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.ClearableLazyValue;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.RecursionGuard;
import com.intellij.openapi.util.RecursionManager;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsListener;
import com.intellij.openapi.vcs.VcsRoot;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
@@ -101,27 +101,22 @@ public class VcsProjectLog {
@CalledInAwt
private void disposeLog() {
if (myLogManager.getCached() != null) myMessageBus.syncPublisher(VCS_PROJECT_LOG_CHANGED).logDisposed();
myUi = null;
myLogManager.drop();
}
@CalledInAwt
private void createLog() {
public void createLog() {
VcsLogManager logManager = myLogManager.getValue();
myMessageBus.syncPublisher(VCS_PROJECT_LOG_CHANGED).logCreated();
if (PostponableLogRefresher.keepUpToDate()) {
if (logManager.isLogVisible()) {
logManager.scheduleInitialization();
}
else if (PostponableLogRefresher.keepUpToDate()) {
new HeavyAwareExecutor(myProject).execute(logManager::scheduleInitialization);
}
}
public void scheduleInitialization() {
VcsLogManager cached = myLogManager.getCached();
if (cached != null) cached.scheduleInitialization();
}
private boolean hasDvcsRoots() {
return !VcsLogManager.findLogProviders(getVcsRoots(), myProject).isEmpty();
}
@@ -130,33 +125,32 @@ public class VcsProjectLog {
return ServiceManager.getService(project, VcsProjectLog.class);
}
@SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext")
private class LazyVcsLogManager extends ClearableLazyValue<VcsLogManager> {
private class LazyVcsLogManager {
@Nullable private VcsLogManager myValue;
@NotNull
@CalledInAwt
@Override
public synchronized VcsLogManager getValue() {
return super.getValue();
if (myValue == null) {
myValue = compute();
myMessageBus.syncPublisher(VCS_PROJECT_LOG_CHANGED).logCreated();
}
return myValue;
}
@NotNull
@CalledInAwt
@Override
protected synchronized VcsLogManager compute() {
return new VcsLogManager(myProject, myUiProperties, getVcsRoots(), false, new Runnable() {
@Override
public void run() {
recreateLog();
}
});
return new VcsLogManager(myProject, myUiProperties, getVcsRoots(), false, VcsProjectLog.this::recreateLog);
}
@CalledInAwt
@Override
public synchronized void drop() {
if (myValue != null) Disposer.dispose(myValue);
super.drop();
if (myValue != null) {
myMessageBus.syncPublisher(VCS_PROJECT_LOG_CHANGED).logDisposed();
Disposer.dispose(myValue);
}
myValue = null;
}
@Nullable
@@ -173,7 +167,7 @@ public class VcsProjectLog {
MessageBusConnection connection = project.getMessageBus().connect(project);
connection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, projectLog::recreateLog);
if (projectLog.hasDvcsRoots()) {
ApplicationManager.getApplication().invokeLater(projectLog::createLog);
ApplicationManager.getApplication().invokeLater(() -> projectLog.createLog());
}
}
}