From 7df9bb4aec9980a7529061e68f8f51d93b7f259d Mon Sep 17 00:00:00 2001 From: Jamie Shiell Date: Thu, 8 Aug 2024 17:07:22 +0100 Subject: [PATCH] Update tree node text to show filtered child counts (#644) --- .../toolwindow/ResultTreeModel.java | 1 + .../checkstyle/toolwindow/ResultTreeNode.java | 24 ++++++++++++++++++- .../checkstyle/CheckStyleBundle.properties | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeModel.java b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeModel.java index 2cdbf91f..1d8d595a 100644 --- a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeModel.java +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeModel.java @@ -98,6 +98,7 @@ private void filter(final boolean sendEvents, final SeverityLevel... levels) { } } + ((ResultTreeNode) fileNode.getUserObject()).setVisibleProblems(fileNode.getChildCount()); final boolean fileNodeShouldBeVisible = fileNode.getChildCount() > 0; if (fileNode.isVisible() != fileNodeShouldBeVisible) { fileNode.setVisible(fileNodeShouldBeVisible); diff --git a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeNode.java b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeNode.java index b62f212f..e7bfa935 100644 --- a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeNode.java +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeNode.java @@ -13,6 +13,8 @@ /** * The user object for meta-data on tree nodes in the tool window. + * + * TODO this is covering for both files & problems at present, which is messy */ public class ResultTreeNode { @@ -22,6 +24,9 @@ public class ResultTreeNode { private String text; private String description; private SeverityLevel severity; + private String fileName; + private int totalProblems; + private int visibleProblems; /** * Construct an informational node. @@ -49,10 +54,21 @@ public ResultTreeNode(final String fileName, final int problemCount) { throw new IllegalArgumentException("Filename may not be null"); } - this.text = CheckStyleBundle.message("plugin.results.scan-file-result", fileName, problemCount); + this.fileName = fileName; + this.totalProblems = problemCount; + this.visibleProblems = problemCount; + updateTextForFileNode(); icon = Icons.icon("/fileTypes/java.png"); } + private void updateTextForFileNode() { + if (totalProblems == visibleProblems) { + this.text = CheckStyleBundle.message("plugin.results.scan-file-result", fileName, totalProblems); + } else { + this.text = CheckStyleBundle.message("plugin.results.scan-file-result.filtered", fileName, visibleProblems, totalProblems - visibleProblems); + } + } + /** * Construct a node for a given problem. * @@ -165,6 +181,12 @@ public void setDescription(final String description) { this.description = description; } + public void setVisibleProblems(final int visibleProblems) { + this.visibleProblems = visibleProblems; + + updateTextForFileNode(); + } + @Override public String toString() { if (text != null) { diff --git a/src/main/resources/org/infernus/idea/checkstyle/CheckStyleBundle.properties b/src/main/resources/org/infernus/idea/checkstyle/CheckStyleBundle.properties index 650faa21..75cbc899 100644 --- a/src/main/resources/org/infernus/idea/checkstyle/CheckStyleBundle.properties +++ b/src/main/resources/org/infernus/idea/checkstyle/CheckStyleBundle.properties @@ -20,6 +20,7 @@ plugin.results.error.instantiation-failed=The module {0} could not be loaded - \ plugin.results.scan-no-results=Checkstyle found no problems in the file(s) plugin.results.scan-results=Checkstyle found {0} item(s) in {1} file(s) plugin.results.scan-file-result={0} : {1} item(s) +plugin.results.scan-file-result.filtered={0} : {1} item(s), {2} more hidden plugin.results.file-result={1} ({2}:{3}) [{4}] plugin.results.unknown-source=unknown plugin.status.in-progress.current=Scanning current file...