]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor AbstractFilterDashboard : use Open/Close principle
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 25 May 2012 17:47:38 +0000 (19:47 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 25 May 2012 17:47:47 +0000 (19:47 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java

index 60d35b21c9eed88a05957848bfc52c8aa7ad941b..7d4d2d25ed0241e355d1a3ec622e8a84b7eb3841 100644 (file)
@@ -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) {
+  }
 }
index 0e05c7ec82e9cfbc6b73c23699dc9fb494e57ed7..23a66302d01371e33fe44587d20fbf7b125698a5 100644 (file)
@@ -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
index 128152622f2ff60998d82a75b30c5424771b21c2..32fd31d0373aacf349aa664adeeb02fd8a0e668b 100644 (file)
@@ -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));