mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DashboardGroupingRule: add extension point
This commit is contained in:
@@ -17,10 +17,12 @@ package com.intellij.execution.dashboard;
|
||||
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeAction;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -29,6 +31,24 @@ import java.util.List;
|
||||
* @author konstantin.aleev
|
||||
*/
|
||||
public interface DashboardGroupingRule extends TreeAction {
|
||||
ExtensionPointName<DashboardGroupingRule> EP_NAME = ExtensionPointName.create("com.intellij.runtimeDashboardGroupingRule");
|
||||
|
||||
Comparator<DashboardGroupingRule> PRIORITY_COMPARATOR = (o1, o2) -> {
|
||||
final int res = o2.getPriority() - o1.getPriority();
|
||||
return res != 0 ? res : (o1.getName().compareTo(o2.getName()));
|
||||
};
|
||||
|
||||
/**
|
||||
* Grouping rules are ordered and applied to dashboard nodes according to their priority.
|
||||
* @return Rule's priority.
|
||||
*/
|
||||
int getPriority();
|
||||
|
||||
/**
|
||||
* @return {@code true} if grouping rule should always be applied to dashboard nodes.
|
||||
*/
|
||||
boolean isAlwaysEnable();
|
||||
|
||||
/**
|
||||
* @return A list of groups which should be shown in the tree even if they do not contain any nodes.
|
||||
*/
|
||||
@@ -43,4 +63,10 @@ public interface DashboardGroupingRule extends TreeAction {
|
||||
*/
|
||||
@Nullable
|
||||
DashboardGroup getGroup(AbstractTreeNode<?> node);
|
||||
|
||||
interface Priorities {
|
||||
int BY_FOLDER = 200;
|
||||
int BY_STATUS = 800;
|
||||
int BY_TYPE = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -295,7 +295,7 @@ public class RuntimeDashboardContent extends JPanel implements TreeContent, Disp
|
||||
rightGroup.add(collapseAllAction);
|
||||
|
||||
rightGroup.add(new Separator());
|
||||
myGroupers.forEach(grouper -> rightGroup.add(new GroupAction(grouper)));
|
||||
myGroupers.stream().filter(grouper -> !grouper.getRule().isAlwaysEnable()).forEach(grouper -> rightGroup.add(new GroupAction(grouper)));
|
||||
|
||||
ActionToolbar rightActionToolBar = ActionManager.getInstance().createActionToolbar(PLACE_TOOLBAR, rightGroup, false);
|
||||
toolBarPanel.add(rightActionToolBar.getComponent());
|
||||
|
||||
+9
-8
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package com.intellij.execution.dashboard;
|
||||
|
||||
import com.intellij.execution.dashboard.tree.ConfigurationTypeDashboardGroupingRule;
|
||||
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;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
@@ -41,6 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -65,9 +63,10 @@ public class RuntimeDashboardManagerImpl implements RuntimeDashboardManager, Per
|
||||
project, true);
|
||||
toolWindow.setIcon(getToolWindowIcon());
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
myGroupers.add(new DashboardGrouper(new ConfigurationTypeDashboardGroupingRule()));
|
||||
myGroupers.add(new DashboardGrouper(new StatusDashboardGroupingRule()));
|
||||
myGroupers.add(new DashboardGrouper(new FolderDashboardGroupingRule()));
|
||||
myGroupers = Arrays.stream(DashboardGroupingRule.EP_NAME.getExtensions())
|
||||
.sorted(DashboardGroupingRule.PRIORITY_COMPARATOR)
|
||||
.map(DashboardGrouper::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
RuntimeDashboardContent dashboardContent = new RuntimeDashboardContent(project, myContentManager, myGroupers);
|
||||
Content content = contentFactory.createContent(dashboardContent, null, false);
|
||||
@@ -101,7 +100,9 @@ public class RuntimeDashboardManagerImpl implements RuntimeDashboardManager, Per
|
||||
@Override
|
||||
public State getState() {
|
||||
State state = new State();
|
||||
state.ruleStates = myGroupers.stream().map(grouper -> new RuleState(grouper.getRule().getName(), grouper.isEnabled()))
|
||||
state.ruleStates = myGroupers.stream()
|
||||
.filter(grouper -> !grouper.getRule().isAlwaysEnable())
|
||||
.map(grouper -> new RuleState(grouper.getRule().getName(), grouper.isEnabled()))
|
||||
.collect(Collectors.toList());
|
||||
return state;
|
||||
}
|
||||
@@ -110,7 +111,7 @@ public class RuntimeDashboardManagerImpl implements RuntimeDashboardManager, Per
|
||||
public void loadState(State state) {
|
||||
state.ruleStates.forEach(ruleState -> {
|
||||
for (DashboardGrouper grouper : myGroupers) {
|
||||
if (grouper.getRule().getName().equals(ruleState.name)) {
|
||||
if (grouper.getRule().getName().equals(ruleState.name) && !grouper.getRule().isAlwaysEnable()) {
|
||||
grouper.setEnabled(ruleState.enabled);
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,6 +36,6 @@ public abstract class RuntimeDashboardTreeAction<T extends DashboardNode> extend
|
||||
|
||||
@Override
|
||||
protected boolean isVisibleForAnySelection(@NotNull AnActionEvent e) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-6
@@ -46,12 +46,7 @@ public abstract class RuntimeDashboardTreeLeafAction<T extends DashboardNode> ex
|
||||
if (!(o instanceof AbstractTreeNode)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
AbstractTreeNode node = (AbstractTreeNode)o;
|
||||
if (node instanceof GroupingNode && node.getChildren().isEmpty()) {
|
||||
// Action could not be performed if current selection contains empty grouping nodes
|
||||
return Collections.emptySet();
|
||||
}
|
||||
nodes.add(node);
|
||||
nodes.add((AbstractTreeNode)o);
|
||||
}
|
||||
return getLeaves(nodes);
|
||||
}
|
||||
|
||||
+10
@@ -49,6 +49,16 @@ public class ConfigurationTypeDashboardGroupingRule implements DashboardGrouping
|
||||
AllIcons.Actions.GroupByFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return Priorities.BY_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DashboardGroup getGroup(AbstractTreeNode<?> node) {
|
||||
|
||||
+10
@@ -48,6 +48,16 @@ public class FolderDashboardGroupingRule implements DashboardGroupingRule {
|
||||
AllIcons.Actions.GroupByPackage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return Priorities.BY_FOLDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysEnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DashboardGroup getGroup(AbstractTreeNode<?> node) {
|
||||
|
||||
+11
-3
@@ -16,9 +16,7 @@
|
||||
package com.intellij.execution.dashboard.tree;
|
||||
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.dashboard.DashboardGroup;
|
||||
import com.intellij.execution.dashboard.DashboardGroupingRule;
|
||||
import com.intellij.execution.dashboard.DashboardRunConfigurationNode;
|
||||
import com.intellij.execution.dashboard.*;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.smartTree.ActionPresentation;
|
||||
@@ -52,6 +50,16 @@ public class StatusDashboardGroupingRule implements DashboardGroupingRule {
|
||||
AllIcons.Actions.GroupByPrefix); // TODO [konstantin.aleev] provide new icon
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return Priorities.BY_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<DashboardGroup> getPermanentGroups() {
|
||||
|
||||
@@ -461,6 +461,8 @@
|
||||
|
||||
<extensionPoint name="runtimeDashboardContributor"
|
||||
interface="com.intellij.execution.dashboard.RuntimeDashboardContributor"/>
|
||||
<extensionPoint name="runtimeDashboardGroupingRule"
|
||||
interface="com.intellij.execution.dashboard.DashboardGroupingRule"/>
|
||||
|
||||
<extensionPoint name="hectorComponentProvider" interface="com.intellij.openapi.editor.HectorComponentPanelsProvider"
|
||||
area="IDEA_PROJECT"/>
|
||||
|
||||
@@ -951,7 +951,12 @@
|
||||
|
||||
<projectService serviceInterface="com.intellij.execution.ExecutionManager" serviceImplementation="com.intellij.execution.impl.ExecutionManagerImpl"/>
|
||||
<projectService serviceInterface="com.intellij.execution.ExecutionTargetManager" serviceImplementation="com.intellij.execution.ExecutionTargetManagerImpl"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.execution.dashboard.RuntimeDashboardManager" serviceImplementation="com.intellij.execution.dashboard.RuntimeDashboardManagerImpl"/>
|
||||
<runtimeDashboardGroupingRule implementation="com.intellij.execution.dashboard.tree.ConfigurationTypeDashboardGroupingRule"/>
|
||||
<runtimeDashboardGroupingRule implementation="com.intellij.execution.dashboard.tree.StatusDashboardGroupingRule"/>
|
||||
<runtimeDashboardGroupingRule implementation="com.intellij.execution.dashboard.tree.FolderDashboardGroupingRule"/>
|
||||
|
||||
<previewPanelProvider implementation="com.intellij.openapi.fileEditor.impl.FilePreviewPanelProvider"/>
|
||||
<previewPanelProvider implementation="com.intellij.codeInsight.documentation.DocumentationPreviewPanelProvider"/>
|
||||
<previewPanelProvider implementation="com.intellij.find.UsagesPreviewPanelProvider"/>
|
||||
|
||||
Reference in New Issue
Block a user