explicitly pass parent disposable to ensure that it is disposed

GitOrigin-RevId: a43cefefaa6afd7a16f89877fb2c3eb81ee72c40
This commit is contained in:
Vladimir Krivosheev
2025-09-17 08:11:51 +00:00
committed by intellij-monorepo-bot
parent 55c247d088
commit 95e54245ef
7 changed files with 40 additions and 73 deletions
@@ -1352,40 +1352,6 @@ c:com.intellij.openapi.externalSystem.view.ExternalProjectsViewAdapter
- showInheritedTasks():Z
- updateUpTo(com.intellij.openapi.externalSystem.view.ExternalSystemNode):V
- useTasksNode():Z
f:com.intellij.openapi.externalSystem.view.ExternalProjectsViewImpl
- com.intellij.openapi.ui.SimpleToolWindowPanel
- com.intellij.openapi.Disposable
- com.intellij.openapi.externalSystem.view.ExternalProjectsView
- sf:LOG:com.intellij.openapi.diagnostic.Logger
- <init>(com.intellij.openapi.project.Project,com.intellij.openapi.wm.ex.ToolWindowEx,com.intellij.openapi.externalSystem.model.ProjectSystemId):V
- addListener(com.intellij.openapi.externalSystem.view.ExternalProjectsView$Listener):V
- createNodes(com.intellij.openapi.externalSystem.view.ExternalProjectsView,com.intellij.openapi.externalSystem.view.ExternalSystemNode,com.intellij.openapi.externalSystem.model.DataNode):java.util.List
- dispose():V
- getDisplayName(com.intellij.openapi.externalSystem.model.DataNode):java.lang.String
- getErrorLevelRecursively(com.intellij.openapi.externalSystem.model.DataNode):com.intellij.openapi.externalSystem.view.ExternalProjectsStructure$ErrorLevel
- getGroupModules():Z
- getGroupTasks():Z
- getNotificationGroup():com.intellij.notification.NotificationGroup
- getProject():com.intellij.openapi.project.Project
- getShowIgnored():Z
- getState():com.intellij.openapi.externalSystem.view.ExternalProjectsViewState
- getStructure():com.intellij.openapi.externalSystem.view.ExternalProjectsStructure
- getSystemId():com.intellij.openapi.externalSystem.model.ProjectSystemId
- getTaskActivator():com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator
- getUiAware():com.intellij.openapi.externalSystem.ExternalSystemUiAware
- handleDoubleClickOrEnter(com.intellij.openapi.externalSystem.view.ExternalSystemNode,java.lang.String,java.awt.event.InputEvent):V
- init():V
- s:isNoBackgroundMode():Z
- loadState(com.intellij.openapi.externalSystem.view.ExternalProjectsViewState):V
- scheduleStructureUpdate():V
- setGroupModules(Z):V
- setGroupTasks(Z):V
- setShowIgnored(Z):V
- setShowInheritedTasks(Z):V
- showInheritedTasks():Z
- uiDataSnapshot(com.intellij.openapi.actionSystem.DataSink):V
- updateUpTo(com.intellij.openapi.externalSystem.view.ExternalSystemNode):V
- useTasksNode():Z
a:com.intellij.openapi.externalSystem.view.ExternalSystemNode
- com.intellij.ui.treeStructure.SimpleNode
- java.lang.Comparable
@@ -13,7 +13,7 @@ import java.util.Map;
* @author Vladislav.Soroka
*/
@ApiStatus.Internal
public class ExternalProjectsState {
public final class ExternalProjectsState {
private final Map<String, State> myExternalSystemsState = FactoryMap.create(key -> new State());
@Property(surroundWithTag = false)
@@ -30,7 +30,7 @@ public class ExternalProjectsState {
public boolean storeExternally = false;
@Tag("state")
public static class State {
public static final class State {
private ExternalProjectsViewState projectsViewState = new ExternalProjectsViewState();
private final Map<String, TaskActivationState> myExternalSystemsTaskActivation = FactoryMap.createMap(key-> new TaskActivationState(), LinkedHashMap::new);
@@ -39,7 +39,7 @@ public abstract class AbstractExternalSystemToolWindowFactory implements ToolWin
contentManager.addContent(new ContentImpl(createInitializingLabel(), "", false));
ExternalProjectsManager.getInstance(project).runWhenInitialized(() -> {
ExternalProjectsViewImpl projectView = new ExternalProjectsViewImpl(project, (ToolWindowEx)toolWindow, externalSystemId);
ExternalProjectsViewImpl projectView = new ExternalProjectsViewImpl(toolWindow.getDisposable(), project, (ToolWindowEx)toolWindow, externalSystemId);
ExternalProjectsManagerImpl.getInstance(project).registerView(projectView);
ContentImpl taskContent = new ContentImpl(projectView, "", true);
contentManager.removeAllContents(true);
@@ -37,7 +37,6 @@ import java.util.function.Predicate;
*/
@ApiStatus.Internal
public class SelectExternalSystemNodeDialog extends DialogWrapper {
private final @NotNull SimpleTree myTree;
private final @Nullable Predicate<? super SimpleNode> mySelector;
protected @Nullable Boolean groupTasks;
@@ -46,7 +45,7 @@ public class SelectExternalSystemNodeDialog extends DialogWrapper {
public SelectExternalSystemNodeDialog(@NotNull ProjectSystemId systemId,
@NotNull Project project,
@NotNull @NlsContexts.DialogTitle String title,
Class<? extends ExternalSystemNode> nodeClass,
Class<? extends ExternalSystemNode<?>> nodeClass,
@Nullable Predicate<? super SimpleNode> selector) {
//noinspection unchecked
this(systemId, project, title, new Class[]{nodeClass}, selector);
@@ -55,7 +54,7 @@ public class SelectExternalSystemNodeDialog extends DialogWrapper {
public SelectExternalSystemNodeDialog(@NotNull ProjectSystemId systemId,
@NotNull Project project,
@NotNull @NlsContexts.DialogTitle String title,
final Class<? extends ExternalSystemNode>[] nodeClasses,
final Class<? extends ExternalSystemNode<?>>[] nodeClasses,
@Nullable Predicate<? super SimpleNode> selector) {
super(project, false);
mySelector = selector;
@@ -68,14 +67,13 @@ public class SelectExternalSystemNodeDialog extends DialogWrapper {
if (projectsView == null) {
ToolWindow toolWindow = ExternalToolWindowManager.getToolWindow(project, systemId);
if (toolWindow instanceof ToolWindowEx) {
projectsView = new ExternalProjectsViewImpl(project, (ToolWindowEx)toolWindow, systemId);
Disposer.register(getDisposable(), (ExternalProjectsViewImpl)projectsView);
projectsView = new ExternalProjectsViewImpl(getDisposable(), project, (ToolWindowEx)toolWindow, systemId);
}
}
if(projectsView != null) {
final ExternalProjectsStructure treeStructure = new ExternalProjectsStructure(project, myTree) {
@Override
protected Class<? extends ExternalSystemNode>[] getVisibleNodesClasses() {
protected Class<? extends ExternalSystemNode<?>>[] getVisibleNodesClasses() {
return nodeClasses;
}
@@ -141,7 +139,7 @@ public class SelectExternalSystemNodeDialog extends DialogWrapper {
return myTree;
}
protected void handleDoubleClickOrEnter(@NotNull ExternalSystemNode node, @Nullable String actionId, InputEvent inputEvent) {
protected void handleDoubleClickOrEnter(@NotNull ExternalSystemNode<?> node, @Nullable String actionId, InputEvent inputEvent) {
}
protected SimpleNode getSelectedNode() {
@@ -19,13 +19,9 @@ import org.jetbrains.annotations.Nullable;
import java.awt.event.InputEvent;
/**
* @author Vladislav.Soroka
*/
@ApiStatus.Internal
public class SelectExternalTaskDialog extends SelectExternalSystemNodeDialog {
private static final Class<? extends ExternalSystemNode>[] NODE_CLASSES = ContainerUtil.ar(
public final class SelectExternalTaskDialog extends SelectExternalSystemNodeDialog {
private static final Class<? extends ExternalSystemNode<?>>[] NODE_CLASSES = ContainerUtil.ar(
ProjectNode.class,
ModuleNode.class,
TaskNode.class
@@ -59,15 +59,17 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.tree.TreeSelectionModel;
import java.awt.*;
import java.awt.event.InputEvent;
import java.util.List;
import java.util.*;
import java.util.List;
/**
* @author Vladislav.Soroka
*/
public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implements ExternalProjectsView, Disposable {
@ApiStatus.Internal
public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implements ExternalProjectsView {
public static final Logger LOG = Logger.getInstance(ExternalProjectsViewImpl.class);
@NotNull private final Disposable parentDisposable;
private final @NotNull Project myProject;
private final @NotNull ExternalProjectsManagerImpl myProjectsManager;
private final @NotNull ToolWindowEx myToolWindow;
@@ -82,8 +84,14 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
private ExternalProjectsViewState myState = new ExternalProjectsViewState();
public ExternalProjectsViewImpl(@NotNull Project project, @NotNull ToolWindowEx toolWindow, @NotNull ProjectSystemId externalSystemId) {
public ExternalProjectsViewImpl(@NotNull Disposable parentDisposable,
@NotNull Project project,
@NotNull ToolWindowEx toolWindow,
@NotNull ProjectSystemId externalSystemId) {
super(true, true);
this.parentDisposable = parentDisposable;
myProject = project;
myToolWindow = toolWindow;
myExternalSystemId = externalSystemId;
@@ -98,7 +106,15 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
Condition<ExternalSystemViewContributor> contributorPredicate = c -> {
return ProjectSystemId.IDE.equals(c.getSystemId()) || myExternalSystemId.equals(c.getSystemId());
};
myViewContributors = new ArrayList<>(ContainerUtil.filter(ExternalSystemViewContributor.EP_NAME.getExtensions(), contributorPredicate));
myViewContributors = new ArrayList<>(ContainerUtil.filter(ExternalSystemViewContributor.EP_NAME.getExtensionList(), contributorPredicate));
Disposer.register(parentDisposable, () -> {
this.listeners.clear();
this.myViewContributors.clear();
this.myStructure = null;
this.myTree = null;
});
ExternalSystemViewContributor.EP_NAME.addExtensionPointListener(new ExtensionPointListener<>() {
@Override
public void extensionAdded(@NotNull ExternalSystemViewContributor extension, @NotNull PluginDescriptor pluginDescriptor) {
@@ -113,7 +129,7 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
myViewContributors.remove(extension);
}
}
}, this);
}, parentDisposable);
setName(myExternalSystemId.getReadableName() + " tool window");
Touchbar.setActions(this, "ExternalSystem.RefreshAllProjects");
@@ -177,10 +193,9 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
}
public void init() {
Disposer.register(myProject, this);
initTree();
MessageBusConnection busConnection = myProject.getMessageBus().connect(this);
MessageBusConnection busConnection = myProject.getMessageBus().connect(parentDisposable);
busConnection.subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener() {
boolean wasVisible;
@@ -204,9 +219,9 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
}
});
getShortcutsManager().addListener(() -> scheduleTaskAndRunConfigUpdate(), this);
getShortcutsManager().addListener(() -> scheduleTaskAndRunConfigUpdate(), parentDisposable);
getTaskActivator().addListener(() -> scheduleTaskAndRunConfigUpdate(), this);
getTaskActivator().addListener(() -> scheduleTaskAndRunConfigUpdate(), parentDisposable);
busConnection.subscribe(RunManagerListener.TOPIC, new RunManagerListener() {
private void changed() {
@@ -232,7 +247,7 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
}
});
myToolWindow.setAdditionalGearActions(createAdditionalGearActionsGroup());
myToolWindow.setAdditionalGearActions(createAdditionalGearActionsGroup(parentDisposable));
scheduleStructureUpdate();
}
@@ -260,7 +275,7 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
listeners.add(listener);
}
private ActionGroup createAdditionalGearActionsGroup() {
private ActionGroup createAdditionalGearActionsGroup(@NotNull Disposable parentDisposable) {
ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup group = new DefaultActionGroup();
String[] ids = new String[]{"ExternalSystem.GroupModules", "ExternalSystem.GroupTasks", "ExternalSystem.ShowInheritedTasks", "ExternalSystem.ShowIgnored"};
@@ -269,7 +284,7 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
if (gearAction instanceof ExternalSystemViewGearAction) {
((ExternalSystemViewGearAction)gearAction).setView(this);
group.add(gearAction);
Disposer.register(this, () -> ((ExternalSystemViewGearAction)gearAction).setView(null));
Disposer.register(parentDisposable, () -> ((ExternalSystemViewGearAction)gearAction).setView(null));
}
}
return group;
@@ -278,7 +293,7 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
@ApiStatus.Internal
public void initStructure() {
myStructure = new ExternalProjectsStructure(myProject, myTree);
Disposer.register(this, myStructure);
Disposer.register(parentDisposable, myStructure);
myStructure.init(this);
}
@@ -553,7 +568,7 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
String projectPath = null;
for (ExternalSystemNode node : selectedNodes) {
for (ExternalSystemNode<?> node : selectedNodes) {
final Object data = node.getData();
if (data instanceof TaskData taskData) {
if (projectPath == null) {
@@ -576,12 +591,4 @@ public final class ExternalProjectsViewImpl extends SimpleToolWindowPanel implem
return ExternalSystemTaskLocation.create(myProject, myExternalSystemId, projectPath, taskExecutionInfo);
}
@Override
public void dispose() {
this.listeners.clear();
this.myViewContributors.clear();
this.myStructure = null;
this.myTree = null;
}
}
@@ -52,7 +52,7 @@ open class GradleToolWindowTest : GradleImportingTestCase() {
super.setUp()
isPreview = false
toolWindow = ToolWindowHeadlessManagerImpl.MockToolWindow(myProject)
view = ExternalProjectsViewImpl(myProject, toolWindow!!, externalSystemId)
view = ExternalProjectsViewImpl(myProject, myProject, toolWindow!!, externalSystemId)
runInEdtAndWait {
ExternalProjectsManagerImpl.getInstance(myProject).registerView(view)
view.initStructure()