-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for grouping results by package (#3)
- Loading branch information
Showing
15 changed files
with
301 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/org/infernus/idea/checkstyle/actions/GroupByFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.infernus.idea.checkstyle.actions; | ||
|
||
import org.infernus.idea.checkstyle.toolwindow.ResultGrouping; | ||
|
||
public class GroupByFile extends GroupingAction { | ||
|
||
public GroupByFile() { | ||
super(ResultGrouping.BY_FILE); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/infernus/idea/checkstyle/actions/GroupByPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.infernus.idea.checkstyle.actions; | ||
|
||
import org.infernus.idea.checkstyle.toolwindow.ResultGrouping; | ||
|
||
public class GroupByPackage extends GroupingAction { | ||
|
||
public GroupByPackage() { | ||
super(ResultGrouping.BY_PACKAGE); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/org/infernus/idea/checkstyle/actions/GroupingAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.infernus.idea.checkstyle.actions; | ||
|
||
import com.intellij.openapi.actionSystem.ActionUpdateThread; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.project.DumbAwareToggleAction; | ||
import com.intellij.openapi.project.Project; | ||
import org.infernus.idea.checkstyle.toolwindow.ResultGrouping; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.infernus.idea.checkstyle.actions.ToolWindowAccess.*; | ||
|
||
abstract class GroupingAction extends DumbAwareToggleAction { | ||
|
||
private final ResultGrouping grouping; | ||
|
||
GroupingAction(@NotNull final ResultGrouping grouping) { | ||
this.grouping = grouping; | ||
} | ||
|
||
@Override | ||
public boolean isSelected(final @NotNull AnActionEvent event) { | ||
final Project project = getEventProject(event); | ||
if (project == null) { | ||
return false; | ||
} | ||
|
||
Boolean selected = getFromToolWindowPanel(toolWindow(project), panel -> panel.groupedBy() == grouping); | ||
return Objects.requireNonNullElse(selected, false); | ||
} | ||
|
||
@Override | ||
public void setSelected(final @NotNull AnActionEvent event, final boolean selected) { | ||
final Project project = getEventProject(event); | ||
if (project == null) { | ||
return; | ||
} | ||
|
||
actOnToolWindowPanel(toolWindow(project), panel -> { | ||
panel.groupBy(grouping); | ||
}); | ||
} | ||
|
||
@Override | ||
public @NotNull ActionUpdateThread getActionUpdateThread() { | ||
return ActionUpdateThread.EDT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/org/infernus/idea/checkstyle/toolwindow/PackageTreeInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.infernus.idea.checkstyle.toolwindow; | ||
|
||
import com.intellij.icons.AllIcons; | ||
import org.infernus.idea.checkstyle.CheckStyleBundle; | ||
|
||
public class PackageTreeInfo extends ResultTreeNode { | ||
|
||
private final String packageName; | ||
private final int totalProblems; | ||
private int visibleProblems; | ||
|
||
/** | ||
* Construct a package node. | ||
* | ||
* @param packageName the name of the package. | ||
* @param problemCount the number of problems in the file. | ||
*/ | ||
public PackageTreeInfo(final String packageName, final int problemCount) { | ||
super(CheckStyleBundle.message("plugin.results.scan-file-result", packageName, problemCount)); | ||
|
||
if (packageName == null) { | ||
throw new IllegalArgumentException("Package name may not be null"); | ||
} | ||
|
||
this.packageName = packageName; | ||
this.totalProblems = problemCount; | ||
this.visibleProblems = problemCount; | ||
|
||
updateDisplayText(); | ||
|
||
setIcon(AllIcons.Nodes.Package); | ||
} | ||
|
||
private void updateDisplayText() { | ||
if (totalProblems == visibleProblems) { | ||
setText(CheckStyleBundle.message("plugin.results.scan-package-result", packageName, totalProblems)); | ||
} else { | ||
setText(CheckStyleBundle.message("plugin.results.scan-package-result.filtered", packageName, visibleProblems, totalProblems - visibleProblems)); | ||
} | ||
} | ||
|
||
void setVisibleProblems(final int visibleProblems) { | ||
this.visibleProblems = visibleProblems; | ||
|
||
updateDisplayText(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/org/infernus/idea/checkstyle/toolwindow/ResultGrouping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.infernus.idea.checkstyle.toolwindow; | ||
|
||
public enum ResultGrouping { | ||
|
||
BY_FILE, | ||
BY_PACKAGE | ||
|
||
} |
Oops, something went wrong.