From 86c1e331b375f8e24ec479b2e6acb30235b5a84a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 25 May 2012 19:47:38 +0200 Subject: [PATCH] Refactor AbstractFilterDashboard : use Open/Close principle --- .../plugins/core/dashboards/AbstractFilterDashboard.java | 9 ++++++++- .../plugins/core/dashboards/MyFavouritesDashboard.java | 6 +++--- .../sonar/plugins/core/filters/MyFavouritesFilter.java | 6 ++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java index 60d35b21c9e..7d4d2d25ed0 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java @@ -34,7 +34,7 @@ abstract class AbstractFilterDashboard extends DashboardTemplate { protected abstract String getFilterKey(); @Override - public Dashboard createDashboard() { + public final Dashboard createDashboard() { Dashboard dashboard = Dashboard.create() .setGlobal(true) .setLayout(DashboardLayout.ONE_COLUMN); @@ -43,6 +43,13 @@ abstract class AbstractFilterDashboard extends DashboardTemplate { .addWidget("filter", 1) .setProperty(FilterWidget.FILTER, getFilterKey()); + doCompleteDashboard(dashboard); return dashboard; } + + /** + * Override this method to complete dashboard + */ + protected void doCompleteDashboard(Dashboard dashboard) { + } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java index 0e05c7ec82e..23a66302d01 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java @@ -35,11 +35,11 @@ public final class MyFavouritesDashboard extends AbstractFilterDashboard { @Override protected String getFilterKey() { - return new MyFavouritesFilter().getName(); + return MyFavouritesFilter.NAME; } @Override - public Dashboard createDashboard() { - return super.createDashboard().setActivated(false); + protected void doCompleteDashboard(Dashboard dashboard) { + dashboard.setActivated(false); } } \ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java index 128152622f2..32fd31d0373 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java @@ -31,9 +31,11 @@ import org.sonar.api.web.FilterTemplate; * @since 3.1 */ public class MyFavouritesFilter extends FilterTemplate { + public static final String NAME = "My favourites"; + @Override public String getName() { - return "My favourites"; + return NAME; } @Override @@ -41,7 +43,7 @@ public class MyFavouritesFilter extends FilterTemplate { Filter filter = Filter.create(); filter.setDisplayAs(Filter.LIST); filter.setFavouritesOnly(true); - filter.add(Criterion.createForQualifier("VW", "SVW", "TRK", "BRC", "DIR", "PAC", "FIL", "CLA", "UTS", "LIB")); + filter.add(Criterion.createForQualifier("VW", "SVW", "TRK", "BRC", "DIR", "PAC", "FIL", "CLA", "UTS")); filter.add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false)); filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false)); filter.add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)); -- 2.39.5