The Unified and Autonomous Development Platform
Remember checkstyle report expand status
Robin Shen477fa79c7b5e
diff --git a/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleFilesPage.java b/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleFilesPage.javaindex 3a1fd5d0aa..08a6218f17 100644--- a/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleFilesPage.java+++ b/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleFilesPage.java@@ -2,8 +2,9 @@ package org.server.plugin.report.checkstyle;import java.io.Serializable;import java.util.ArrayList;+import java.util.Collection;+import java.util.HashSet;import java.util.List;-import java.util.concurrent.atomic.AtomicBoolean;import java.util.stream.Collectors;import javax.annotation.Nullable;@@ -67,6 +68,8 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {private List<String> filePaths;+ private Collection<String> expandedFiles = new HashSet<>();+public CheckstyleFilesPage(PageParameters params) {super(params);@@ -79,7 +82,7 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {filePaths = getReportData().getViolationFiles().stream().map(it->it.getPath())- .collect(Collectors.toList());+ .collect(Collectors.toList());form = new Form<Void>("form");@@ -170,13 +173,15 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {protected void populateItem(ListItem<ViolationFile> item) {ViolationFile file = item.getModelObject();String filePath = file.getPath();- AtomicBoolean showViolations = new AtomicBoolean(item.getIndex() == 0);AjaxLink<Void> toggleLink = new AjaxLink<Void>("toggle") {@Overridepublic void onClick(AjaxRequestTarget target) {- showViolations.set(!showViolations.get());+ if (expandedFiles.contains(filePath))+ expandedFiles.remove(filePath);+ else+ expandedFiles.add(filePath);target.add(item);}@@ -186,7 +191,7 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {@Overridepublic String getObject() {- return showViolations.get()? "expanded": "collapsed";+ return expandedFiles.contains(filePath)? "expanded": "collapsed";}}));@@ -213,7 +218,7 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showViolations.get()+ setVisible(expandedFiles.contains(filePath)&& item.getModelObject().getViolations().size() > MAX_VIOLATIONS_TO_DISPLAY);}@@ -260,7 +265,7 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showViolations.get());+ setVisible(expandedFiles.contains(filePath));}});@@ -268,6 +273,9 @@ public class CheckstyleFilesPage extends CheckstyleReportPage {}});+ if (!filesView.getModelObject().isEmpty())+ expandedFiles.add(filesView.getModelObject().iterator().next().getPath());+filesContainer.add(new OnePagingNavigator("pagingNavigator", filesView, null));filesContainer.add(new NoRecordsPlaceholder("noRecords", filesView));}diff --git a/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleRulesPage.java b/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleRulesPage.javaindex c28b95c2e6..33e2fe9f91 100644--- a/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleRulesPage.java+++ b/server-plugin/server-plugin-report-checkstyle/src/main/java/org/server/plugin/report/checkstyle/CheckstyleRulesPage.java@@ -2,8 +2,9 @@ package org.server.plugin.report.checkstyle;import java.io.Serializable;import java.util.ArrayList;+import java.util.Collection;+import java.util.HashSet;import java.util.List;-import java.util.concurrent.atomic.AtomicBoolean;import java.util.stream.Collectors;import javax.annotation.Nullable;@@ -67,6 +68,8 @@ public class CheckstyleRulesPage extends CheckstyleReportPage {private List<String> ruleNames;+ private Collection<String> expandedRules = new HashSet<>();+public CheckstyleRulesPage(PageParameters params) {super(params);@@ -169,14 +172,16 @@ public class CheckstyleRulesPage extends CheckstyleReportPage {@Overrideprotected void populateItem(ListItem<ViolationRule> item) {ViolationRule rule = item.getModelObject();-- AtomicBoolean showViolations = new AtomicBoolean(getCurrentPage() == 0 && item.getIndex() == 0);+ String ruleName = rule.getName();AjaxLink<Void> toggleLink = new AjaxLink<Void>("toggle") {@Overridepublic void onClick(AjaxRequestTarget target) {- showViolations.set(!showViolations.get());+ if (expandedRules.contains(ruleName))+ expandedRules.remove(ruleName);+ else+ expandedRules.add(ruleName);target.add(item);}@@ -184,12 +189,12 @@ public class CheckstyleRulesPage extends CheckstyleReportPage {toggleLink.add(newSeverityIcon("icon", rule.getSeverity()));- toggleLink.add(new Label("label", rule.getName()));+ toggleLink.add(new Label("label", ruleName));toggleLink.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {@Overridepublic String getObject() {- return showViolations.get()? "expanded": "collapsed";+ return expandedRules.contains(ruleName)? "expanded": "collapsed";}}));@@ -202,7 +207,7 @@ public class CheckstyleRulesPage extends CheckstyleReportPage {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showViolations.get()+ setVisible(expandedRules.contains(ruleName)&& item.getModelObject().getViolations().size() > MAX_VIOLATIONS_TO_DISPLAY);}@@ -248,7 +253,7 @@ public class CheckstyleRulesPage extends CheckstyleReportPage {@Overrideprotected void onConfigure() {super.onConfigure();- setVisible(showViolations.get());+ setVisible(expandedRules.contains(ruleName));}});@@ -256,6 +261,9 @@ public class CheckstyleRulesPage extends CheckstyleReportPage {}});+ if (!rulesView.getModelObject().isEmpty())+ expandedRules.add(rulesView.getModelObject().iterator().next().getName());+rulesContainer.add(new OnePagingNavigator("pagingNavigator", rulesView, null));rulesContainer.add(new NoRecordsPlaceholder("noRecords", rulesView));}