diff --git a/src/main/java/org/infernus/idea/checkstyle/toolwindow/CheckStyleToolWindowPanel.java b/src/main/java/org/infernus/idea/checkstyle/toolwindow/CheckStyleToolWindowPanel.java index c755b687..2b5a9e4f 100644 --- a/src/main/java/org/infernus/idea/checkstyle/toolwindow/CheckStyleToolWindowPanel.java +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/CheckStyleToolWindowPanel.java @@ -297,7 +297,7 @@ private void clearProgress() { */ private void scrollToError(final TreePath treePath) { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); - if (treeNode == null || !(treeNode.getUserObject() instanceof ResultTreeNode nodeInfo)) { + if (treeNode == null || !(treeNode.getUserObject() instanceof ProblemResultTreeNode nodeInfo)) { return; } @@ -326,11 +326,11 @@ private void scrollToError(final TreePath treePath) { }, ModalityState.NON_MODAL); } - private int lineFor(final ResultTreeNode nodeInfo) { + private int lineFor(final ProblemResultTreeNode nodeInfo) { return nodeInfo.getProblem().line(); } - private int columnFor(final ResultTreeNode nodeInfo) { + private int columnFor(final ProblemResultTreeNode nodeInfo) { return nodeInfo.getProblem().column(); } diff --git a/src/main/java/org/infernus/idea/checkstyle/toolwindow/FileResultTreeNode.java b/src/main/java/org/infernus/idea/checkstyle/toolwindow/FileResultTreeNode.java new file mode 100644 index 00000000..88a00b75 --- /dev/null +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/FileResultTreeNode.java @@ -0,0 +1,47 @@ +package org.infernus.idea.checkstyle.toolwindow; + +import com.intellij.icons.AllIcons; +import org.infernus.idea.checkstyle.CheckStyleBundle; + +public class FileResultTreeNode extends ResultTreeNode { + + private final String fileName; + private final int totalProblems; + private int visibleProblems; + + /** + * Construct a file node. + * + * @param fileName the name of the file. + * @param problemCount the number of problems in the file. + */ + public FileResultTreeNode(final String fileName, final int problemCount) { + super(CheckStyleBundle.message("plugin.results.scan-file-result", fileName, problemCount)); + + if (fileName == null) { + throw new IllegalArgumentException("Filename may not be null"); + } + + this.fileName = fileName; + this.totalProblems = problemCount; + this.visibleProblems = problemCount; + + updateTextForFileNode(); + + setIcon(AllIcons.FileTypes.Java); + } + + private void updateTextForFileNode() { + if (totalProblems == visibleProblems) { + setText(CheckStyleBundle.message("plugin.results.scan-file-result", fileName, totalProblems)); + } else { + setText(CheckStyleBundle.message("plugin.results.scan-file-result.filtered", fileName, visibleProblems, totalProblems - visibleProblems)); + } + } + + void setVisibleProblems(final int visibleProblems) { + this.visibleProblems = visibleProblems; + + updateTextForFileNode(); + } +} diff --git a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ProblemResultTreeNode.java b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ProblemResultTreeNode.java new file mode 100644 index 00000000..c6a34b64 --- /dev/null +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ProblemResultTreeNode.java @@ -0,0 +1,77 @@ +package org.infernus.idea.checkstyle.toolwindow; + +import com.intellij.icons.AllIcons; +import com.intellij.psi.PsiFile; +import org.infernus.idea.checkstyle.CheckStyleBundle; +import org.infernus.idea.checkstyle.checker.Problem; +import org.infernus.idea.checkstyle.csapi.SeverityLevel; +import org.jetbrains.annotations.NotNull; + +public class ProblemResultTreeNode extends ResultTreeNode { + + private final PsiFile file; + private final Problem problem; + private final SeverityLevel severity; + + /** + * Construct a node for a given problem. + * + * @param file the file the problem exists in. + * @param problem the problem. + */ + public ProblemResultTreeNode(@NotNull final PsiFile file, + @NotNull final Problem problem) { + super(CheckStyleBundle.message("plugin.results.file-result", + file.getName(), + problem.message(), + problem.line(), + Integer.toString(problem.column()), + problem.sourceCheck())); + + this.file = file; + this.problem = problem; + + severity = problem.severityLevel(); + + updateIconsForProblem(); + } + + private void updateIconsForProblem() { + if (SeverityLevel.Ignore.equals(severity)) { + setIcon(AllIcons.General.Note); + } else if (SeverityLevel.Warning.equals(severity)) { + setIcon(AllIcons.General.Warning); + } else if (SeverityLevel.Info.equals(severity)) { + setIcon(AllIcons.General.Information); + } else { + setIcon(AllIcons.General.Error); + } + } + + /** + * Get the file associated with this node. + * + * @return the file associated with this node. + */ + public PsiFile getFile() { + return file; + } + + /** + * Get the problem associated with this node. + * + * @return the problem associated with this node. + */ + public Problem getProblem() { + return problem; + } + + /** + * Get the severity of the problem. + * + * @return the severity, or null if not applicable. + */ + public SeverityLevel getSeverity() { + return severity; + } +} 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 63a769ec..b1fc127b 100644 --- a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeModel.java +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeModel.java @@ -4,7 +4,6 @@ import java.util.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeNode; import com.intellij.psi.PsiFile; @@ -86,7 +85,7 @@ public void filter(final SeverityLevel... levels) { private void filter(final boolean sendEvents, final SeverityLevel... levels) { for (final ToggleableTreeNode fileNode : visibleRootNode.getAllChildren()) { for (final ToggleableTreeNode problemNode : fileNode.getAllChildren()) { - final ResultTreeNode result = (ResultTreeNode) problemNode.getUserObject(); + final ProblemResultTreeNode result = (ProblemResultTreeNode) problemNode.getUserObject(); final boolean resultShouldBeVisible = contains(levels, result.getSeverity()); if (problemNode.isVisible() != resultShouldBeVisible) { @@ -94,7 +93,7 @@ private void filter(final boolean sendEvents, final SeverityLevel... levels) { } } - ((ResultTreeNode) fileNode.getUserObject()).setVisibleProblems(fileNode.getChildCount()); + ((FileResultTreeNode) fileNode.getUserObject()).setVisibleProblems(fileNode.getChildCount()); final boolean fileNodeShouldBeVisible = fileNode.getChildCount() > 0; if (fileNode.isVisible() != fileNodeShouldBeVisible) { fileNode.setVisible(fileNodeShouldBeVisible); @@ -158,7 +157,7 @@ public void setModel(final Map> results, if (problems != null) { for (final Problem problem : problems) { if (problem.severityLevel() != SeverityLevel.Ignore) { - final ResultTreeNode problemObj = new ResultTreeNode(file, problem); + final ResultTreeNode problemObj = new ProblemResultTreeNode(file, problem); final ToggleableTreeNode problemNode = new ToggleableTreeNode(problemObj); fileNode.add(problemNode); @@ -171,7 +170,7 @@ public void setModel(final Map> results, itemCount += problemCount; if (problemCount > 0) { - final ResultTreeNode nodeObject = new ResultTreeNode(file.getName(), problemCount); + final ResultTreeNode nodeObject = new FileResultTreeNode(file.getName(), problemCount); fileNode.setUserObject(nodeObject); visibleRootNode.add(fileNode); 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 5d53006f..d861e2cf 100644 --- a/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeNode.java +++ b/src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultTreeNode.java @@ -1,32 +1,19 @@ package org.infernus.idea.checkstyle.toolwindow; -import javax.swing.Icon; - import com.intellij.icons.AllIcons; -import com.intellij.psi.PsiFile; -import org.infernus.idea.checkstyle.CheckStyleBundle; -import org.infernus.idea.checkstyle.checker.Problem; -import org.infernus.idea.checkstyle.csapi.SeverityLevel; -import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + import static org.infernus.idea.checkstyle.util.Strings.isBlank; /** * 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 { - private PsiFile file; - private Problem problem; - private Icon icon; private String text; - private String description; - private SeverityLevel severity; - private String fileName; - private int totalProblems; - private int visibleProblems; + private Icon icon = AllIcons.General.Information; /** * Construct an informational node. @@ -39,80 +26,6 @@ public ResultTreeNode(final String text) { } this.text = text; - icon = AllIcons.General.Information; - } - - - /** - * Construct a file node. - * - * @param fileName the name of the file. - * @param problemCount the number of problems in the file. - */ - public ResultTreeNode(final String fileName, final int problemCount) { - if (fileName == null) { - throw new IllegalArgumentException("Filename may not be null"); - } - - this.fileName = fileName; - this.totalProblems = problemCount; - this.visibleProblems = problemCount; - updateTextForFileNode(); - icon = AllIcons.FileTypes.Java; - } - - 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. - * - * @param file the file the problem exists in. - * @param problem the problem. - */ - public ResultTreeNode(@NotNull final PsiFile file, - @NotNull final Problem problem) { - this.file = file; - this.problem = problem; - - severity = problem.severityLevel(); - - updateIconsForProblem(); - } - - private void updateIconsForProblem() { - if (SeverityLevel.Ignore.equals(severity)) { - icon = AllIcons.General.Note; - } else if (SeverityLevel.Warning.equals(severity)) { - icon = AllIcons.General.Warning; - } else if (SeverityLevel.Info.equals(severity)) { - icon = AllIcons.General.Information; - } else { - icon = AllIcons.General.Error; - } - } - - /** - * Get the severity of the problem. - * - * @return the severity, or null if not applicable. - */ - public SeverityLevel getSeverity() { - return severity; - } - - /** - * Get the problem associated with this node. - * - * @return the problem associated with this node. - */ - public Problem getProblem() { - return problem; } /** @@ -147,53 +60,19 @@ public String getText() { * * @param text the file the node represents. */ - public void setText(final String text) { + void setText(final String text) { if (isBlank(text)) { throw new IllegalArgumentException("Text may not be null/empty"); } this.text = text; } - /** - * Get the file associated with this node. - * - * @return the file associated with this node. - */ - public PsiFile getFile() { - return file; - } - - /** - * Get the description of this node, if any. - * - * @return the description of this node, or null if none. - */ - public String getDescription() { - return description; - } - - /** - * Get the description of this node, if any. - * - * @param description the description of this node, or null if none. - */ - public void setDescription(final String description) { - this.description = description; - } - - public void setVisibleProblems(final int visibleProblems) { - this.visibleProblems = visibleProblems; - - updateTextForFileNode(); + protected void setIcon(final Icon icon) { + this.icon = icon; } @Override public String toString() { - if (text != null) { - return text; - } - - return CheckStyleBundle.message("plugin.results.file-result", file.getName(), - problem.message(), problem.line(), Integer.toString(problem.column()), problem.sourceCheck()); + return text; } }