From 14cb8624cbb2ef298093374c089b859b3719ecb5 Mon Sep 17 00:00:00 2001 From: Konstantin Aleev Date: Fri, 17 Nov 2017 19:22:38 +0300 Subject: [PATCH] IDEA-182256 RunDashboard: fix NPE when types is added to dashboard - Fix toolbar layout when RC runs and tool window content is not initialized --- .../dashboard/RunDashboardContent.java | 70 ++++++++++++------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/RunDashboardContent.java b/platform/lang-impl/src/com/intellij/execution/dashboard/RunDashboardContent.java index 69708551cf83..9b44e58a8bd4 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/RunDashboardContent.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/RunDashboardContent.java @@ -140,21 +140,7 @@ public class RunDashboardContent extends JPanel implements TreeContent, Disposab myContentManagerListener = new ContentManagerAdapter() { @Override public void contentAdded(ContentManagerEvent event) { - Content content = event.getContent(); - RunContentDescriptor descriptor = RunContentManagerImpl.getRunContentDescriptorByContent(content); - if (descriptor == null) { - return; - } - RunnerLayoutUi layoutUi = descriptor.getRunnerLayoutUi(); - if (!(layoutUi instanceof RunnerLayoutUiImpl)) { - return; - } - RunnerLayoutUiImpl layoutUiImpl = (RunnerLayoutUiImpl)layoutUi; - layoutUiImpl.setLeftToolbarVisible(false); - layoutUiImpl.setContentToolbarBefore(false); - List leftToolbarActions = layoutUiImpl.getActions(); - myContentActions.put(content, leftToolbarActions); - updateContentToolbar(content); + onContentAdded(event.getContent()); } @Override @@ -172,17 +158,9 @@ public class RunDashboardContent extends JPanel implements TreeContent, Disposab if (ContentManagerEvent.ContentOperation.add != event.getOperation()) { return; } - contentAdded(event); - myBuilder.queueUpdate().doWhenDone(() -> myBuilder.accept(RunDashboardNode.class, new TreeVisitor() { - @Override - public boolean visit(@NotNull RunDashboardNode node) { - if (node.getContent() == event.getContent()) { - myBuilder.select(node); - } - return false; - } - })); - showContentPanel(); + Content content = event.getContent(); + onContentAdded(content); + onContentSelectionChanged(content); } }; myContentManager.addContentManagerListener(myContentManagerListener); @@ -261,6 +239,16 @@ public class RunDashboardContent extends JPanel implements TreeContent, Disposab new TreeSpeedSearch(myTree, TreeSpeedSearch.NODE_DESCRIPTOR_TOSTRING, true); setTreeVisible(dashboardManager.isShowConfigurations()); + + // RunDashboardContent may be initialized when some contents have been already added to content manager. + // Process already added content. + for (Content content : myContentManager.getContents()) { + onContentAdded(content); + } + Content selectedContent = myContentManager.getSelectedContent(); + if (selectedContent != null) { + onContentSelectionChanged(selectedContent); + } } private void setTreeVisible(boolean visible) { @@ -331,6 +319,36 @@ public class RunDashboardContent extends JPanel implements TreeContent, Disposab showMessagePanel(ExecutionBundle.message("run.dashboard.empty.selection.message")); } + private void onContentAdded(Content content) { + RunContentDescriptor descriptor = RunContentManagerImpl.getRunContentDescriptorByContent(content); + if (descriptor == null) { + return; + } + RunnerLayoutUi layoutUi = descriptor.getRunnerLayoutUi(); + if (!(layoutUi instanceof RunnerLayoutUiImpl)) { + return; + } + RunnerLayoutUiImpl layoutUiImpl = (RunnerLayoutUiImpl)layoutUi; + layoutUiImpl.setLeftToolbarVisible(false); + layoutUiImpl.setContentToolbarBefore(false); + List leftToolbarActions = layoutUiImpl.getActions(); + myContentActions.put(content, leftToolbarActions); + updateContentToolbar(content); + } + + private void onContentSelectionChanged(Content content) { + myBuilder.queueUpdate().doWhenDone(() -> myBuilder.accept(RunDashboardNode.class, new TreeVisitor() { + @Override + public boolean visit(@NotNull RunDashboardNode node) { + if (node.getContent() == content) { + myBuilder.select(node); + } + return false; + } + })); + showContentPanel(); + } + private void showMessagePanel(String text) { Content selectedContent = myContentManager.getSelectedContent(); if (selectedContent != null) {