mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Runtime dashboard cleanup
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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<T, C extends TreeContent> extends AnAc
|
||||
Presentation presentation = e.getPresentation();
|
||||
List<T> 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<T, C extends TreeContent> 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<T> 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<T> targetNodeClass = getTargetNodeClass();
|
||||
List<T> 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<T, C extends TreeContent> extends AnAc
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
List<T> targetNodes = getTargetNodes(e);
|
||||
if (targetNodes == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<T> verifiedTargetNodes = ContainerUtil.filter(targetNodes, targetNode -> isVisible4(targetNode) && isEnabled4(targetNode));
|
||||
List<T> 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<T, C extends TreeContent> extends AnAc
|
||||
}
|
||||
|
||||
protected void doActionPerformed(@NotNull C content, AnActionEvent e, List<T> 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) {
|
||||
|
||||
@@ -323,6 +323,7 @@ public class RuntimeDashboardContent extends JPanel implements TreeContent, Disp
|
||||
}), myProject.getDisposed());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public AbstractTreeBuilder getBuilder() {
|
||||
return myBuilder;
|
||||
|
||||
+32
-35
@@ -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<Element> {
|
||||
@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<RuntimeDashboardManagerImpl.State> {
|
||||
@NotNull private final ContentManager myContentManager;
|
||||
private List<DashboardGrouper> 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<Element> 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<RuleState> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -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<T extends DashboardNode> extend
|
||||
protected final RuntimeDashboardContent getTreeContent(AnActionEvent e) {
|
||||
return e.getData(RuntimeDashboardContent.KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisibleForAnySelection(@NotNull AnActionEvent e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -86,11 +86,6 @@ class RunConfigurationNode extends AbstractRunConfigurationNode<RunnerAndConfigu
|
||||
|
||||
@Override
|
||||
public boolean isTerminated() {
|
||||
for (RunDescriptorNode node : myChildren) {
|
||||
if (!node.isTerminated()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return myChildren.stream().allMatch(RunDescriptorNode::isTerminated);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1023,6 +1023,7 @@
|
||||
<action id="RuntimeDashboard.Run" class="com.intellij.execution.dashboard.actions.RunAction"/>
|
||||
<action id="RuntimeDashboard.Debug" class="com.intellij.execution.dashboard.actions.DebugAction"/>
|
||||
<action id="RuntimeDashboard.Stop" class="com.intellij.execution.dashboard.actions.StopAction"/>
|
||||
<separator/>
|
||||
<action id="RuntimeDashboard.EditConfiguration" class="com.intellij.execution.dashboard.actions.EditConfigurationAction"/>
|
||||
<action id="RuntimeDashboard.CopyConfiguration" class="com.intellij.execution.dashboard.actions.CopyConfigurationAction"/>
|
||||
<action id="RuntimeDashboard.RemoveConfiguration" class="com.intellij.execution.dashboard.actions.RemoveConfigurationAction"/>
|
||||
|
||||
Reference in New Issue
Block a user