[vcs-log] split log project manager (as a project component) and log manager (can have any number of those)

This commit is contained in:
Julia Beliaeva
2016-05-05 19:02:53 +03:00
parent fe58dd937c
commit bd533f65c7
9 changed files with 152 additions and 64 deletions
@@ -8,7 +8,7 @@
<changesViewContent tabName="Log" className="com.intellij.vcs.log.impl.VcsLogContentProvider"
predicateClassName="com.intellij.vcs.log.impl.VcsLogContentProvider$VcsLogVisibilityPredicate"/>
<projectService serviceImplementation="com.intellij.vcs.log.impl.VcsLogManager"/>
<projectService serviceImplementation="com.intellij.vcs.log.impl.VcsLogProjectManager"/>
<projectService serviceInterface="com.intellij.vcs.log.VcsLogObjectsFactory"
serviceImplementation="com.intellij.vcs.log.impl.VcsLogObjectsFactoryImpl"/>
<projectService serviceInterface="com.intellij.vcs.log.VcsLogSettings"
@@ -50,11 +50,11 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
public static final String TAB_NAME = "Log";
@NotNull private final Project myProject;
@NotNull private final VcsLogManager myLogManager;
@NotNull private final VcsLogProjectManager myLogManager;
@NotNull private final JPanel myContainer = new JBPanel(new BorderLayout());
private MessageBusConnection myConnection;
public VcsLogContentProvider(@NotNull Project project, @NotNull VcsLogManager logManager) {
public VcsLogContentProvider(@NotNull Project project, @NotNull VcsLogProjectManager logManager) {
myProject = project;
myLogManager = logManager;
myLogManager.setRecreateMainLogHandler(new Runnable() {
@@ -86,7 +86,7 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
}
public static void openAnotherLogTab(@NotNull Project project) {
VcsLogManager logManager = VcsLogManager.getInstance(project);
VcsLogProjectManager logManager = VcsLogProjectManager.getInstance(project);
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS);
String shortName = generateShortName(toolWindow);
@@ -111,7 +111,7 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
}
}
private static void addLogTab(@NotNull VcsLogManager logManager,
private static void addLogTab(@NotNull VcsLogProjectManager logManager,
@NotNull ToolWindow toolWindow,
@NotNull VcsLogUiImpl logUi,
@NotNull String shortName) {
@@ -50,7 +50,6 @@ import java.util.Collection;
import java.util.Map;
public class VcsLogManager implements Disposable {
public static final ExtensionPointName<VcsLogProvider> LOG_PROVIDER_EP = ExtensionPointName.create("com.intellij.logProvider");
private static final Logger LOG = Logger.getInstance(VcsLogManager.class);
@@ -60,23 +59,32 @@ public class VcsLogManager implements Disposable {
@Nullable private Runnable myRecreateMainLogHandler;
private volatile VcsLogUiImpl myUi;
private VcsLogDataManager myDataManager;
private VcsLogColorManagerImpl myColorManager;
private VcsLogTabsWatcher myTabsLogRefresher;
private PostponableLogRefresher myPostponableRefresher;
@NotNull private final VcsLogDataManager myDataManager;
@NotNull private final VcsLogColorManagerImpl myColorManager;
@NotNull private final VcsLogTabsWatcher myTabsLogRefresher;
@NotNull private final PostponableLogRefresher myPostponableRefresher;
public VcsLogManager(@NotNull Project project, @NotNull VcsLogTabsProperties uiProperties) {
public VcsLogManager(@NotNull Project project, @NotNull VcsLogTabsProperties uiProperties, @NotNull Collection<VcsRoot> roots) {
myProject = project;
myUiProperties = uiProperties;
}
public VcsLogDataManager getDataManager() {
return myDataManager;
Map<VirtualFile, VcsLogProvider> logProviders = findLogProviders(roots, myProject);
myDataManager = new VcsLogDataManager(myProject, logProviders, new MyFatalErrorsConsumer());
myPostponableRefresher = new PostponableLogRefresher(myDataManager);
myTabsLogRefresher = new VcsLogTabsWatcher(myProject, myPostponableRefresher, myDataManager);
refreshLogOnVcsEvents(logProviders, myPostponableRefresher, myDataManager);
myColorManager = new VcsLogColorManagerImpl(logProviders.keySet());
myDataManager.refreshCompletely();
Disposer.register(project, this);
}
@NotNull
protected Collection<VcsRoot> getVcsRoots() {
return Arrays.asList(ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots());
public VcsLogDataManager getDataManager() {
return myDataManager;
}
public void watchTab(@NotNull String contentTabName, @NotNull VcsLogUiImpl logUi) {
@@ -102,30 +110,12 @@ public class VcsLogManager implements Disposable {
@NotNull
public VcsLogUiImpl createLog(@NotNull String logId) {
initData();
VcsLogUiProperties properties = myUiProperties.createProperties(logId);
VcsLogFiltererImpl filterer =
new VcsLogFiltererImpl(myProject, myDataManager, PermanentGraph.SortType.values()[properties.getBekSortType()]);
return new VcsLogUiImpl(myDataManager, myProject, myColorManager, properties, filterer);
}
public boolean initData() {
if (myDataManager != null) return true;
Map<VirtualFile, VcsLogProvider> logProviders = findLogProviders(getVcsRoots(), myProject);
myDataManager = new VcsLogDataManager(myProject, logProviders, new MyFatalErrorsConsumer());
myPostponableRefresher = new PostponableLogRefresher(myDataManager);
myTabsLogRefresher = new VcsLogTabsWatcher(myProject, myPostponableRefresher, myDataManager);
refreshLogOnVcsEvents(logProviders, myPostponableRefresher, myDataManager);
myColorManager = new VcsLogColorManagerImpl(logProviders.keySet());
myDataManager.refreshCompletely();
return false;
}
private static void refreshLogOnVcsEvents(@NotNull Map<VirtualFile, VcsLogProvider> logProviders,
@NotNull VcsLogRefresher refresher,
@NotNull Disposable disposableParent) {
@@ -175,17 +165,17 @@ public class VcsLogManager implements Disposable {
}
public void disposeLog() {
if (myDataManager != null) Disposer.dispose(myDataManager);
myDataManager = null;
myTabsLogRefresher = null;
myPostponableRefresher = null;
myColorManager = null;
Disposer.dispose(myDataManager);
myUi = null;
}
/*
* Use VcsLogProjectManager to get main log.
* */
@Nullable
@Deprecated
public static VcsLogManager getInstance(@NotNull Project project) {
return ServiceManager.getService(project, VcsLogManager.class);
return ServiceManager.getService(project, VcsLogProjectManager.class).getLogManager();
}
@Override
@@ -0,0 +1,102 @@
/*
* Copyright 2000-2016 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.vcs.log.impl;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsRoot;
import com.intellij.vcs.log.data.VcsLogDataManager;
import com.intellij.vcs.log.data.VcsLogTabsProperties;
import com.intellij.vcs.log.ui.VcsLogUiImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Arrays;
import java.util.Collection;
public class VcsLogProjectManager {
@NotNull private final Project myProject;
@NotNull private final VcsLogTabsProperties myUiProperties;
private VcsLogManager myLogManager;
@Nullable private Runnable myRecreateMainLogHandler;
public VcsLogProjectManager(@NotNull Project project, @NotNull VcsLogTabsProperties uiProperties) {
myProject = project;
myUiProperties = uiProperties;
}
public VcsLogDataManager getDataManager() {
return myLogManager.getDataManager();
}
@NotNull
protected Collection<VcsRoot> getVcsRoots() {
return Arrays.asList(ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots());
}
public void watchTab(@NotNull String contentTabName, @NotNull VcsLogUiImpl logUi) {
myLogManager.watchTab(contentTabName, logUi);
}
@NotNull
public JComponent initMainLog(@NotNull String contentTabName) {
initData();
return myLogManager.initMainLog(contentTabName);
}
@NotNull
public VcsLogUiImpl createLog(@NotNull String logId) {
initData();
return myLogManager.createLog(logId);
}
public boolean initData() {
if (myLogManager != null) return true;
myLogManager = new VcsLogManager(myProject, myUiProperties, getVcsRoots());
myLogManager.setRecreateMainLogHandler(myRecreateMainLogHandler);
return false;
}
public void setRecreateMainLogHandler(@Nullable Runnable recreateMainLogHandler) {
myRecreateMainLogHandler = recreateMainLogHandler;
}
/**
* The instance of the {@link VcsLogUiImpl} or null if the log was not initialized yet.
*/
@Nullable
public VcsLogUiImpl getMainLogUi() {
return myLogManager.getMainLogUi();
}
public void disposeLog() {
if (myLogManager != null) Disposer.dispose(myLogManager);
myLogManager = null;
}
public static VcsLogProjectManager getInstance(@NotNull Project project) {
return ServiceManager.getService(project, VcsLogProjectManager.class);
}
public VcsLogManager getLogManager() {
return myLogManager;
}
}
@@ -29,7 +29,7 @@ import com.intellij.vcs.log.VcsLogProvider;
import com.intellij.vcs.log.data.DataPack;
import com.intellij.vcs.log.data.VcsLogDataManager;
import com.intellij.vcs.log.graph.PermanentGraph;
import com.intellij.vcs.log.impl.VcsLogManager;
import com.intellij.vcs.log.impl.VcsLogProjectManager;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@@ -46,7 +46,7 @@ public class VcsLogRepoSizeCollector extends AbstractApplicationUsagesCollector
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) throws CollectUsagesException {
VcsLogManager logManager = VcsLogManager.getInstance(project);
VcsLogProjectManager logManager = VcsLogProjectManager.getInstance(project);
VcsLogDataManager dataManager = logManager.getDataManager();
if (dataManager != null) {
DataPack dataPack = dataManager.getDataPack();
@@ -20,7 +20,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.vcs.log.impl.VcsLogContentProvider;
import com.intellij.vcs.log.impl.VcsLogManager;
import com.intellij.vcs.log.impl.VcsLogProjectManager;
import com.intellij.vcs.log.ui.VcsLogUiImpl;
public class OpenAnotherLogTabAction extends DumbAwareAction {
@@ -34,7 +34,7 @@ public class OpenAnotherLogTabAction extends DumbAwareAction {
e.getPresentation().setEnabledAndVisible(false);
return;
}
VcsLogUiImpl mainLogUi = VcsLogManager.getInstance(e.getProject()).getMainLogUi();
VcsLogUiImpl mainLogUi = VcsLogProjectManager.getInstance(e.getProject()).getMainLogUi();
if (mainLogUi == null) {
e.getPresentation().setEnabledAndVisible(false);
return;
@@ -22,7 +22,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.vcs.log.VcsLogDataKeys;
import com.intellij.vcs.log.data.VcsLogDataManager;
import com.intellij.vcs.log.impl.VcsLogManager;
import com.intellij.vcs.log.impl.VcsLogProjectManager;
public class RefreshLogAction extends RefreshAction {
public RefreshLogAction() {
@@ -32,7 +32,7 @@ public class RefreshLogAction extends RefreshAction {
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
VcsLogManager.getInstance(project).getDataManager().refreshCompletely();
VcsLogProjectManager.getInstance(project).getDataManager().refreshCompletely();
}
@Override
@@ -42,7 +42,8 @@ public class RefreshLogAction extends RefreshAction {
e.getPresentation().setEnabledAndVisible(false);
}
else {
VcsLogDataManager dataManager = VcsLogManager.getInstance(project).getDataManager();
VcsLogProjectManager projectManager = VcsLogProjectManager.getInstance(project);
VcsLogDataManager dataManager = projectManager.getDataManager();
e.getPresentation().setEnabledAndVisible(dataManager != null && e.getData(VcsLogDataKeys.VCS_LOG_UI) != null);
}
}
@@ -38,7 +38,7 @@ import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import com.intellij.vcs.log.VcsLog;
import com.intellij.vcs.log.impl.VcsLogContentProvider;
import com.intellij.vcs.log.impl.VcsLogManager;
import com.intellij.vcs.log.impl.VcsLogProjectManager;
import com.intellij.vcs.log.ui.VcsLogUiImpl;
import git4idea.GitVcs;
import git4idea.i18n.GitBundle;
@@ -106,7 +106,7 @@ public class GitShowCommitInLogAction extends DumbAwareAction {
return;
}
VcsLogManager logManager = VcsLogManager.getInstance(project);
VcsLogProjectManager logManager = VcsLogProjectManager.getInstance(project);
if (logManager == null) {
showLogNotReadyMessage(project);
return;
@@ -145,14 +145,14 @@ public class GitShowCommitInLogAction extends DumbAwareAction {
super.update(e);
Project project = e.getProject();
e.getPresentation().setEnabled(project != null &&
VcsLogManager.getInstance(project) != null &&
VcsLogProjectManager.getInstance(project) != null &&
getRevisionNumber(e) != null &&
Comparing.equal(getVcsKey(e), GitVcs.getKey()));
}
@Nullable
private static VcsLog findLog(@NotNull Project project) {
VcsLogManager manager = VcsLogManager.getInstance(project);
VcsLogProjectManager manager = VcsLogProjectManager.getInstance(project);
if (manager != null) {
VcsLogUiImpl ui = manager.getMainLogUi();
if (ui != null) {
@@ -127,18 +127,13 @@ public class GitShowExternalLogAction extends DumbAwareAction {
for (VirtualFile root : roots) {
repositoryManager.addExternalRepository(root, GitRepositoryImpl.getInstance(root, project, true));
}
VcsLogManager manager = new VcsLogManager(project, ServiceManager.getService(project, VcsLogTabsProperties.class)) {
@NotNull
@Override
protected Collection<VcsRoot> getVcsRoots() {
return ContainerUtil.map(roots, new Function<VirtualFile, VcsRoot>() {
@Override
public VcsRoot fun(VirtualFile root) {
return new VcsRoot(vcs, root);
}
});
}
};
VcsLogManager manager = new VcsLogManager(project, ServiceManager.getService(project, VcsLogTabsProperties.class),
ContainerUtil.map(roots, new Function<VirtualFile, VcsRoot>() {
@Override
public VcsRoot fun(VirtualFile root) {
return new VcsRoot(vcs, root);
}
}));
return new MyContentComponent(manager.initMainLog(tabName), roots, new Disposable() {
@Override
public void dispose() {