Skip to content

Commit

Permalink
Update tree node text to show filtered child counts (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Aug 8, 2024
1 parent 18019dd commit 7df9bb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down

0 comments on commit 7df9bb4

Please sign in to comment.