diff --git a/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java b/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java index 098a68b57857..d14e426509ee 100644 --- a/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java +++ b/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java @@ -23,7 +23,7 @@ import org.jetbrains.annotations.NotNull; */ public abstract class ClearableLazyValue { private static final RecursionGuard ourGuard = RecursionManager.createGuard("ClearableLazyValue"); - private T myValue; + protected T myValue; @NotNull protected abstract T compute(); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java index 8e700cdfa27b..9589ebb2c620 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java @@ -17,6 +17,7 @@ package com.intellij.vcs.log.impl; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.ClearableLazyValue; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsRoot; @@ -35,7 +36,8 @@ public class VcsLogProjectManager { @NotNull private final Project myProject; @NotNull private final VcsLogTabsProperties myUiProperties; - private VcsLogManager myLogManager; + @NotNull + private final LazyVcsLogManager myLogManager = new LazyVcsLogManager(); private volatile VcsLogUiImpl myUi; @Nullable private Runnable myRecreateMainLogHandler; @@ -44,27 +46,22 @@ public class VcsLogProjectManager { myUiProperties = uiProperties; } + @Nullable public VcsLogDataManager getDataManager() { - return myLogManager.getDataManager(); + VcsLogManager cached = myLogManager.getCached(); + if (cached == null) return null; + return cached.getDataManager(); } @NotNull - protected Collection getVcsRoots() { + private Collection getVcsRoots() { return Arrays.asList(ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots()); } @NotNull public JComponent initMainLog(@NotNull String contentTabName) { - initData(); - - myUi = myLogManager.createLogUi(VcsLogTabsProperties.MAIN_LOG_ID, contentTabName); - return new VcsLogPanel(myLogManager, myUi); - } - - public boolean initData() { - if (myLogManager != null) return true; - myLogManager = new VcsLogManager(myProject, myUiProperties, getVcsRoots(), myRecreateMainLogHandler); - return false; + myUi = myLogManager.getValue().createLogUi(VcsLogTabsProperties.MAIN_LOG_ID, contentTabName); + return new VcsLogPanel(myLogManager.getValue(), myUi); } public void setRecreateMainLogHandler(@Nullable Runnable recreateMainLogHandler) { @@ -80,18 +77,36 @@ public class VcsLogProjectManager { } + @Nullable + public VcsLogManager getLogManager() { + return myLogManager.getCached(); + } + public void disposeLog() { myUi = null; - if (myLogManager != null) Disposer.dispose(myLogManager); - - myLogManager = null; + myLogManager.drop(); } public static VcsLogProjectManager getInstance(@NotNull Project project) { return ServiceManager.getService(project, VcsLogProjectManager.class); } - public VcsLogManager getLogManager() { - return myLogManager; + private class LazyVcsLogManager extends ClearableLazyValue { + @NotNull + @Override + protected VcsLogManager compute() { + return new VcsLogManager(myProject, myUiProperties, getVcsRoots(), myRecreateMainLogHandler); + } + + @Override + public void drop() { + if (myValue != null) Disposer.dispose(myValue); + super.drop(); + } + + @Nullable + public VcsLogManager getCached() { + return myValue; + } } }