Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 855f3ea

Browse files
committed
fix: make sure ApplicationsRootNode is properly disposed (#868)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent ad600f4 commit 855f3ea

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

src/main/java/org/jboss/tools/intellij/openshift/WindowToolFactory.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,28 @@
3838

3939
public class WindowToolFactory implements ToolWindowFactory {
4040

41-
private static final Logger LOGGER = LoggerFactory.getLogger(WindowToolFactory.class);
41+
private static final Logger LOGGER = LoggerFactory.getLogger(WindowToolFactory.class);
4242

43-
@Override
44-
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
45-
ContentFactory contentFactory = IDEAContentFactory.getInstance();
46-
JBPanel<JBPanel> panel = new JBPanel<>();
47-
panel.setLayout(new BorderLayout());
48-
Content content = contentFactory.createContent(panel, "", false);
49-
ApplicationsTreeStructure structure = new ApplicationsTreeStructure(project);
50-
StructureTreeModel<ApplicationsTreeStructure> model = new StructureTreeModel<>(structure, content);
51-
content.setDisposer(structure);
52-
new MutableModelSynchronizer<>(model, structure, structure);
53-
Tree tree = new Tree(new AsyncTreeModel(model, content));
54-
tree.putClientProperty(Constants.STRUCTURE_PROPERTY, structure);
55-
tree.setCellRenderer(new NodeRenderer());
56-
tree.setRootVisible(false);
57-
PopupHandler.installPopupMenu(tree, "org.jboss.tools.intellij.tree", ActionPlaces.MAIN_MENU);
58-
panel.add(new JBScrollPane(tree), BorderLayout.CENTER);
59-
toolWindow.getContentManager().addContent(content);
60-
ArrayList<AnAction> actions = new ArrayList<>();
61-
actions.add(ActionManager.getInstance().getAction("org.jboss.tools.intellij.openshift.actions.toolwindow.FeedBackAction"));
62-
toolWindow.setTitleActions(actions);
63-
TreeHelper.addLinkSupport(tree);
64-
}
43+
@Override
44+
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
45+
ContentFactory contentFactory = IDEAContentFactory.getInstance();
46+
JBPanel<JBPanel> panel = new JBPanel<>();
47+
panel.setLayout(new BorderLayout());
48+
Content content = contentFactory.createContent(panel, "", false);
49+
ApplicationsTreeStructure structure = new ApplicationsTreeStructure(project, content);
50+
StructureTreeModel<ApplicationsTreeStructure> model = new StructureTreeModel<>(structure, content);
51+
content.setDisposer(structure);
52+
new MutableModelSynchronizer<>(model, structure, structure);
53+
Tree tree = new Tree(new AsyncTreeModel(model, content));
54+
tree.putClientProperty(Constants.STRUCTURE_PROPERTY, structure);
55+
tree.setCellRenderer(new NodeRenderer());
56+
tree.setRootVisible(false);
57+
PopupHandler.installPopupMenu(tree, "org.jboss.tools.intellij.tree", ActionPlaces.MAIN_MENU);
58+
panel.add(new JBScrollPane(tree), BorderLayout.CENTER);
59+
toolWindow.getContentManager().addContent(content);
60+
ArrayList<AnAction> actions = new ArrayList<>();
61+
actions.add(ActionManager.getInstance().getAction("org.jboss.tools.intellij.openshift.actions.toolwindow.FeedBackAction"));
62+
toolWindow.setTitleActions(actions);
63+
TreeHelper.addLinkSupport(tree);
64+
}
6565
}

src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsRootNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.intellij.openapi.module.ModuleManager;
1717
import com.intellij.openapi.project.ModuleListener;
1818
import com.intellij.openapi.project.Project;
19+
import com.intellij.openapi.util.Disposer;
1920
import com.intellij.openapi.vfs.LocalFileSystem;
2021
import com.intellij.openapi.vfs.VirtualFile;
2122
import com.intellij.util.messages.MessageBusConnection;
@@ -57,13 +58,14 @@ public class ApplicationsRootNode
5758
private Config config;
5859
private final OdoProcessHelper processHelper;
5960

60-
public ApplicationsRootNode(Project project, ApplicationsTreeStructure structure) {
61+
public ApplicationsRootNode(Project project, ApplicationsTreeStructure structure, Disposable parent) {
6162
this.project = project;
6263
this.structure = structure;
6364
initConfigWatcher();
6465
this.config = loadConfig();
6566
registerProjectListener(project);
6667
this.processHelper = new OdoProcessHelper();
68+
Disposer.register(parent, this);
6769
}
6870

6971
private static boolean shouldLogMessage(String message) {

src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.intellij.ide.util.treeView.NodeDescriptor;
1616
import com.intellij.openapi.Disposable;
1717
import com.intellij.openapi.project.Project;
18+
import com.intellij.openapi.util.Disposer;
1819
import com.intellij.ui.tree.LeafState;
1920
import com.redhat.devtools.intellij.common.tree.LabelAndIconDescriptor;
2021
import com.redhat.devtools.intellij.common.tree.MutableModel;
@@ -52,10 +53,11 @@ public class ApplicationsTreeStructure extends AbstractTreeStructure implements
5253
private final MutableModel<Object> mutableModelSupport = new MutableModelSupport<>();
5354
private final DevfileRegistriesNode registries;
5455

55-
public ApplicationsTreeStructure(Project project) {
56+
public ApplicationsTreeStructure(Project project, Disposable parentDisposable) {
5657
this.project = project;
57-
this.root = new ApplicationsRootNode(project, this);
58+
this.root = new ApplicationsRootNode(project, this, parentDisposable);
5859
this.registries = new DevfileRegistriesNode(root);
60+
Disposer.register(parentDisposable, this);
5961
}
6062

6163
@Override

src/test/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationTreeModelConfigUpdateTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
package org.jboss.tools.intellij.openshift.tree.application;
1212

1313
import com.intellij.openapi.project.Project;
14+
import com.intellij.openapi.util.Disposer;
1415
import com.intellij.openapi.util.text.StringUtil;
1516
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
1617
import io.fabric8.kubernetes.api.model.AuthInfo;
1718
import io.fabric8.kubernetes.api.model.Config;
1819
import io.fabric8.kubernetes.api.model.Context;
1920
import io.fabric8.kubernetes.api.model.NamedAuthInfo;
2021
import io.fabric8.kubernetes.api.model.NamedContext;
21-
2222
import java.util.Arrays;
2323

2424
import static org.mockito.Mockito.doReturn;
@@ -116,7 +116,7 @@ public void testShouldRefreshIfContextUserLogout() {
116116
}
117117

118118
protected ApplicationsRootNode createApplicationsRootNode(Project project, Config config) {
119-
return spy(new ApplicationsRootNode(project, null) {
119+
return spy(new ApplicationsRootNode(project, null, Disposer.newDisposable()) {
120120
@Override
121121
protected void initConfigWatcher() {
122122
}

0 commit comments

Comments
 (0)