From ef6f3df8cebe535991dfaf2a188070e056fc9b7a Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 15 Mar 2005 19:24:18 +0300 Subject: [PATCH] group by severity in InspectionResultsView --- .../ex/InspectionManagerEx.java | 26 +++++++- .../ui/InspectionResultsView.java | 61 ++++++++++++++----- .../ui/InspectionSeverityGroupNode.java | 32 ++++++++++ 3 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 source/com/intellij/codeInspection/ui/InspectionSeverityGroupNode.java diff --git a/source/com/intellij/codeInspection/ex/InspectionManagerEx.java b/source/com/intellij/codeInspection/ex/InspectionManagerEx.java index 6523234393f0..edfb71d1a74a 100644 --- a/source/com/intellij/codeInspection/ex/InspectionManagerEx.java +++ b/source/com/intellij/codeInspection/ex/InspectionManagerEx.java @@ -7,6 +7,7 @@ package com.intellij.codeInspection.ex; import com.intellij.analysis.AnalysisScope; +import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.LocalQuickFix; @@ -16,6 +17,8 @@ import com.intellij.codeInspection.reference.*; import com.intellij.codeInspection.ui.InspectCodePanel; import com.intellij.codeInspection.ui.InspectionResultsView; import com.intellij.ide.impl.ContentManagerWatcher; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ProjectComponent; @@ -775,8 +778,9 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern public class UIOptions implements JDOMExternalizable { public boolean AUTOSCROLL_TO_SOURCE = false; public float SPLITTER_PROPORTION = 0.5f; + public boolean GROUP_BY_SEVERITY = false; public final AutoScrollToSourceHandler myAutoScrollToSourceHandler; - + public final GroupBySeverityAction myGroupBySeverityAction; public UIOptions() { myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() { protected boolean isAutoScrollMode() { @@ -787,6 +791,7 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern AUTOSCROLL_TO_SOURCE = state; } }; + myGroupBySeverityAction = new GroupBySeverityAction(); } public void readExternal(Element element) throws InvalidDataException { @@ -798,6 +803,25 @@ public class InspectionManagerEx extends InspectionManager implements JDOMExtern } } + private class GroupBySeverityAction extends ToggleAction { + public GroupBySeverityAction() { + super("Group by Severity", "Group Inspections By Severity", HighlightDisplayLevel.WARNING.getIcon()); + } + + public boolean isSelected(AnActionEvent e) { + return myUIOptions.GROUP_BY_SEVERITY; + } + + public void setSelected(AnActionEvent e, boolean state) { + myUIOptions.GROUP_BY_SEVERITY = state; + myView.update(); + } + } + + public AnAction createGroupBySeverityAction(){ + return myUIOptions.myGroupBySeverityAction; + } + public String getComponentName() { return "InspectionManager"; } diff --git a/source/com/intellij/codeInspection/ui/InspectionResultsView.java b/source/com/intellij/codeInspection/ui/InspectionResultsView.java index b8a204b41f04..f96aad873e94 100644 --- a/source/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/source/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -2,6 +2,7 @@ package com.intellij.codeInspection.ui; import com.intellij.analysis.AnalysisScope; import com.intellij.codeEditor.printing.ExportToHTMLSettings; +import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInsight.daemon.HighlightDisplayKey; import com.intellij.codeInsight.daemon.impl.SwitchOffToolAction; import com.intellij.codeInsight.highlighting.HighlightManager; @@ -50,9 +51,8 @@ import com.intellij.ui.ListPopup; import com.intellij.ui.PopupHandler; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SmartExpander; -import com.intellij.util.containers.HashMap; -import com.intellij.util.containers.HashSet; import com.intellij.util.OpenSourceUtil; +import com.intellij.util.containers.HashSet; import javax.swing.*; import javax.swing.event.TreeSelectionEvent; @@ -80,12 +80,12 @@ public class InspectionResultsView extends JPanel implements OccurenceNavigator, private InspectionTree myTree; private Browser myBrowser; private Splitter mySplitter; - private Map myGroups = null; + private Map> myGroups = null; private OccurenceNavigator myOccurenceNavigator; private InspectionProfile myInspectionProfile; private AnalysisScope myScope; public static final String HELP_ID = "codeInspection"; - + public final Map mySeverityGroupNodes = new java.util.HashMap(); public InspectionResultsView(final Project project, InspectionProfile inspectionProfile, AnalysisScope scope) { setLayout(new BorderLayout()); @@ -197,6 +197,7 @@ public class InspectionResultsView extends JPanel implements OccurenceNavigator, group.add(new CloseAction()); group.add(new RerunAction(this)); group.add(manager.createToggleAutoscrollAction()); + group.add(manager.createGroupBySeverityAction()); group.add(new PreviousOccurenceToolbarAction(getOccurenceNavigator())); group.add(new NextOccurenceToolbarAction(getOccurenceNavigator())); group.add(new ExportHTMLAction()); @@ -414,11 +415,11 @@ public class InspectionResultsView extends JPanel implements OccurenceNavigator, setCursor(currentCursor); } - public void addTool(InspectionTool tool) { + public void addTool(InspectionTool tool, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { tool.updateContent(); if (tool.hasReportedProblems()) { final InspectionNode toolNode = new InspectionNode(tool); - initToolNode(tool, toolNode, getToolParentNode(tool.getGroupDisplayName().length() > 0 ? tool.getGroupDisplayName() : "General")); + initToolNode(tool, toolNode, getToolParentNode(tool.getGroupDisplayName().length() > 0 ? tool.getGroupDisplayName() : "General", errorLevel, groupedBySeverity)); if (tool instanceof DeadCodeInspection) { final DummyEntryPointsTool entryPoints = new DummyEntryPointsTool((DeadCodeInspection)tool); entryPoints.updateContent(); @@ -447,15 +448,23 @@ public class InspectionResultsView extends JPanel implements OccurenceNavigator, } } + private void clearTree(){ + myTree.removeAllNodes(); + mySeverityGroupNodes.clear(); + } + public boolean update() { InspectionTool[] tools = myInspectionProfile.getInspectionTools(myProject); - myTree.removeAllNodes(); + clearTree(); boolean resultsFound = false; - myGroups = new HashMap(); + final InspectionManagerEx manager = ((InspectionManagerEx)InspectionManagerEx.getInstance(myProject)); + final boolean isGroupedBySeverity = manager.getUIOptions().GROUP_BY_SEVERITY; + myGroups = new java.util.HashMap>(); for (int i = 0; i < tools.length; i++) { InspectionTool tool = tools[i]; - if (myInspectionProfile.isToolEnabled(HighlightDisplayKey.find(tool.getShortName()))) { - addTool(tool); + final HighlightDisplayKey key = HighlightDisplayKey.find(tool.getShortName()); + if (myInspectionProfile.isToolEnabled(key)) { + addTool(tool, myInspectionProfile.getErrorLevel(key), isGroupedBySeverity); resultsFound |= tool.hasReportedProblems(); } } @@ -464,17 +473,39 @@ public class InspectionResultsView extends JPanel implements OccurenceNavigator, return resultsFound; } - private InspectionTreeNode getToolParentNode(String groupName) { - if (groupName == null || groupName.length() == 0) return myTree.getRoot(); - InspectionGroupNode group = myGroups.get(groupName); + private InspectionTreeNode getToolParentNode(String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { + if ((groupName == null || groupName.length() == 0)){ + return getRelativeRootNode(groupedBySeverity, errorLevel); + } + Map map = myGroups.get(errorLevel); + if (map == null){ + map = new java.util.HashMap(); + myGroups.put(errorLevel, map); + } + InspectionGroupNode group = map.get(groupName); if (group == null) { group = new InspectionGroupNode(groupName); - myGroups.put(groupName, group); - myTree.getRoot().add(group); + map.put(groupName, group); + getRelativeRootNode(groupedBySeverity, errorLevel).add(group); } return group; } + private InspectionTreeNode getRelativeRootNode(boolean isGroupedBySeverity, HighlightDisplayLevel level){ + if (isGroupedBySeverity){ + if (mySeverityGroupNodes.containsKey(level)){ + return mySeverityGroupNodes.get(level); + } else { + final InspectionSeverityGroupNode severityGroupNode = new InspectionSeverityGroupNode(level); + mySeverityGroupNodes.put(level, severityGroupNode); + myTree.getRoot().add(severityGroupNode); + return severityGroupNode; + } + } else { + return myTree.getRoot(); + } + } + public void exportHTML(HTMLExportFrameMaker frameMaker) { final InspectionTreeNode root = myTree.getRoot(); final Enumeration children = root.children(); diff --git a/source/com/intellij/codeInspection/ui/InspectionSeverityGroupNode.java b/source/com/intellij/codeInspection/ui/InspectionSeverityGroupNode.java new file mode 100644 index 000000000000..acd281dc4a0c --- /dev/null +++ b/source/com/intellij/codeInspection/ui/InspectionSeverityGroupNode.java @@ -0,0 +1,32 @@ +package com.intellij.codeInspection.ui; + +import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.openapi.util.text.StringUtil; + +import javax.swing.*; + + +/** + * User: anna + * Date: Mar 15, 2005 + */ +public class InspectionSeverityGroupNode extends InspectionTreeNode{ + + private HighlightDisplayLevel myLevel; + public InspectionSeverityGroupNode(final HighlightDisplayLevel level) { + super(level); + myLevel = level; + } + + public Icon getIcon(boolean expanded) { + return myLevel.getIcon(); + } + + public boolean appearsBold() { + return true; + } + + public String toString() { + return StringUtil.capitalize(myLevel.toString().toLowerCase()); + } +}