From 2f191ca55499a80807f9e1d7a582827667229eca Mon Sep 17 00:00:00 2001 From: Konstantin Aleev Date: Wed, 25 Jan 2017 17:26:35 +0300 Subject: [PATCH] Runtime dashboard cleanup --- .../execution/dashboard/DashboardNode.java | 3 +- .../dashboard/DashboardTreeAction.java | 45 +++++-------- .../dashboard/RuntimeDashboardContent.java | 1 + .../RuntimeDashboardManagerImpl.java | 67 +++++++++---------- .../actions/RuntimeDashboardTreeAction.java | 6 ++ .../dashboard/tree/RunConfigurationNode.java | 7 +- .../src/idea/LangActions.xml | 1 + 7 files changed, 59 insertions(+), 71 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/dashboard/DashboardNode.java b/platform/lang-api/src/com/intellij/execution/dashboard/DashboardNode.java index bfdc96ff48ba..dbbead18f1d7 100644 --- a/platform/lang-api/src/com/intellij/execution/dashboard/DashboardNode.java +++ b/platform/lang-api/src/com/intellij/execution/dashboard/DashboardNode.java @@ -31,7 +31,8 @@ public interface DashboardNode { @Nullable default Content getContent() { - return getDescriptor() == null ? null : getDescriptor().getAttachedContent(); + RunContentDescriptor descriptor = getDescriptor(); + return descriptor == null ? null : descriptor.getAttachedContent(); } Project getProject(); diff --git a/platform/lang-api/src/com/intellij/execution/dashboard/DashboardTreeAction.java b/platform/lang-api/src/com/intellij/execution/dashboard/DashboardTreeAction.java index a958ba8dfbf5..feb9451a0cbf 100644 --- a/platform/lang-api/src/com/intellij/execution/dashboard/DashboardTreeAction.java +++ b/platform/lang-api/src/com/intellij/execution/dashboard/DashboardTreeAction.java @@ -25,8 +25,10 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * @author konstantin.aleev @@ -41,21 +43,8 @@ public abstract class DashboardTreeAction extends AnAc Presentation presentation = e.getPresentation(); List targetNodes = getTargetNodes(e); - boolean visible; - boolean enabled; - - if (targetNodes == null) { - visible = false; - enabled = false; - } - else { - visible = true; - enabled = true; - for (T targetNode : targetNodes) { - visible &= isVisible4(targetNode); - enabled &= visible && isEnabled4(targetNode); - } - } + boolean visible = isVisibleForAnySelection(e) || (!targetNodes.isEmpty() && targetNodes.stream().allMatch(this::isVisible4)); + boolean enabled = visible && (!targetNodes.isEmpty() && targetNodes.stream().allMatch(this::isEnabled4)); presentation.setVisible(visible); presentation.setEnabled(enabled); @@ -65,27 +54,27 @@ public abstract class DashboardTreeAction extends AnAc /** * Invokes {@link #collectNodes(AbstractTreeBuilder) collectNodes()} to collect nodes. * If each collected node could be casted to tree action node class, - * returns a list of collected nodes casted to tree action node class, otherwise returns {@code null}. + * returns a list of collected nodes casted to tree action node class, otherwise returns empty list. * * @param e Action event. * @return List of target nodes for this action. */ - @Nullable + @NotNull protected List getTargetNodes(AnActionEvent e) { C content = getTreeContent(e); if (content == null) { - return null; + return Collections.emptyList(); } Set selectedElements = collectNodes(content.getBuilder()); int selectionCount = selectedElements.size(); if (selectionCount == 0 || selectionCount > 1 && !isMultiSelectionAllowed()) { - return null; + return Collections.emptyList(); } Class targetNodeClass = getTargetNodeClass(); List result = new ArrayList<>(); for (Object selectedElement : selectedElements) { if (!targetNodeClass.isInstance(selectedElement)) { - return null; + return Collections.emptyList(); } result.add(targetNodeClass.cast(selectedElement)); } @@ -108,15 +97,15 @@ public abstract class DashboardTreeAction extends AnAc @Override public void actionPerformed(@NotNull AnActionEvent e) { - List targetNodes = getTargetNodes(e); - if (targetNodes == null) { - return; - } - - List verifiedTargetNodes = ContainerUtil.filter(targetNodes, targetNode -> isVisible4(targetNode) && isEnabled4(targetNode)); + List verifiedTargetNodes = getTargetNodes(e).stream().filter(node -> isVisible4(node) && isEnabled4(node)) + .collect(Collectors.toList()); doActionPerformed(getTreeContent(e), e, verifiedTargetNodes); } + protected boolean isVisibleForAnySelection(@NotNull AnActionEvent e) { + return false; + } + protected boolean isMultiSelectionAllowed() { return false; } @@ -133,9 +122,7 @@ public abstract class DashboardTreeAction extends AnAc } protected void doActionPerformed(@NotNull C content, AnActionEvent e, List nodes) { - for (T node : nodes) { - doActionPerformed(content, e, node); - } + nodes.forEach(node -> doActionPerformed(content, e , node)); } protected void doActionPerformed(@NotNull C content, AnActionEvent e, T node) { diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardContent.java b/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardContent.java index c53b71192804..919f30098409 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardContent.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardContent.java @@ -323,6 +323,7 @@ public class RuntimeDashboardContent extends JPanel implements TreeContent, Disp }), myProject.getDisposed()); } + @Override @NotNull public AbstractTreeBuilder getBuilder() { return myBuilder; diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardManagerImpl.java index ba1a122e6dc5..34d520838feb 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/RuntimeDashboardManagerImpl.java @@ -16,8 +16,8 @@ package com.intellij.execution.dashboard; import com.intellij.execution.dashboard.tree.ConfigurationTypeDashboardGroupingRule; -import com.intellij.execution.dashboard.tree.FolderDashboardGroupingRule; import com.intellij.execution.dashboard.tree.DashboardGrouper; +import com.intellij.execution.dashboard.tree.FolderDashboardGroupingRule; import com.intellij.execution.dashboard.tree.StatusDashboardGroupingRule; import com.intellij.icons.AllIcons; import com.intellij.openapi.application.ApplicationManager; @@ -36,14 +36,13 @@ import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.ContentUI; -import org.jdom.Element; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * @author konstantin.aleev @@ -52,12 +51,7 @@ import java.util.List; name = "RuntimeDashboard", storages = @Storage(StoragePathMacros.WORKSPACE_FILE) ) -public class RuntimeDashboardManagerImpl implements RuntimeDashboardManager, PersistentStateComponent { - @NonNls private static final String GROUPERS_TAG = "groupers"; - @NonNls private static final String GROUPER_TAG = "grouper"; - @NonNls private static final String NAME_ATTR = "name"; - @NonNls private static final String ENABLED_ATTR = "enabled"; - +public class RuntimeDashboardManagerImpl implements RuntimeDashboardManager, PersistentStateComponent { @NotNull private final ContentManager myContentManager; private List myGroupers = new ArrayList<>(); @@ -105,37 +99,40 @@ public class RuntimeDashboardManagerImpl implements RuntimeDashboardManager, Per @Nullable @Override - public Element getState() { - final Element element = new Element("state"); - final Element groupers = new Element(GROUPERS_TAG); - element.addContent(groupers); - myGroupers.forEach(grouper -> groupers.addContent(writeGrouperState(grouper))); - return element; - } - - private static Element writeGrouperState(DashboardGrouper grouper) { - Element element = new Element(GROUPER_TAG); - element.setAttribute(NAME_ATTR, grouper.getRule().getName()); - element.setAttribute(ENABLED_ATTR, Boolean.toString(grouper.isEnabled())); - return element; + public State getState() { + State state = new State(); + state.ruleStates = myGroupers.stream().map(grouper -> new RuleState(grouper.getRule().getName(), grouper.isEnabled())) + .collect(Collectors.toList()); + return state; } @Override - public void loadState(Element element) { - Element groupersElement = element.getChild(GROUPERS_TAG); - if (groupersElement != null) { - List groupers = groupersElement.getChildren(GROUPER_TAG); - groupers.forEach(this::readGrouperState); - } + public void loadState(State state) { + state.ruleStates.forEach(ruleState -> { + for (DashboardGrouper grouper : myGroupers) { + if (grouper.getRule().getName().equals(ruleState.name)) { + grouper.setEnabled(ruleState.enabled); + return; + } + } + }); } - private void readGrouperState(Element grouperElement) { - String id = grouperElement.getAttributeValue(NAME_ATTR); - for (DashboardGrouper grouper : myGroupers) { - if (grouper.getRule().getName().equals(id)) { - grouper.setEnabled(Boolean.valueOf(grouperElement.getAttributeValue(ENABLED_ATTR, "true"))); - return; - } + static class State { + public List ruleStates = new ArrayList<>(); + } + + private static class RuleState { + public String name; + public boolean enabled = true; + + @SuppressWarnings("UnusedDeclaration") + public RuleState() { + } + + public RuleState(String name, boolean enabled) { + this.name = name; + this.enabled = enabled; } } } diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RuntimeDashboardTreeAction.java b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RuntimeDashboardTreeAction.java index 4faf1d9a08b9..5409df0e032c 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RuntimeDashboardTreeAction.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RuntimeDashboardTreeAction.java @@ -17,6 +17,7 @@ package com.intellij.execution.dashboard.actions; import com.intellij.execution.dashboard.*; import com.intellij.openapi.actionSystem.AnActionEvent; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -32,4 +33,9 @@ public abstract class RuntimeDashboardTreeAction extend protected final RuntimeDashboardContent getTreeContent(AnActionEvent e) { return e.getData(RuntimeDashboardContent.KEY); } + + @Override + protected boolean isVisibleForAnySelection(@NotNull AnActionEvent e) { + return false; + } } diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java b/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java index d9f0edfd87ad..7a3b062d718d 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java @@ -86,11 +86,6 @@ class RunConfigurationNode extends AbstractRunConfigurationNode +