]> source.dussan.org Git - sonarqube.git/blob
4a84cd06756d557ef4c58f94ae6fd12b5744998a
[sonarqube.git] /
1 /*
2  * Sonar, open source software quality management tool.
3  * Copyright (C) 2008-2012 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
6  * Sonar is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * Sonar is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Sonar; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19  */
20 package org.sonar.plugins.core.dashboards;
21
22 import org.sonar.api.web.Dashboard;
23 import org.sonar.api.web.DashboardLayout;
24 import org.sonar.api.web.DashboardTemplate;
25 import org.sonar.core.measure.MeasureFilterDao;
26 import org.sonar.core.measure.MeasureFilterDto;
27 import org.sonar.plugins.core.filters.MyFavouritesFilter;
28 import org.sonar.plugins.core.filters.ProjectFilter;
29 import org.sonar.plugins.core.widgets.MeasureFilterListWidget;
30 import org.sonar.plugins.core.widgets.MeasureFilterTreemapWidget;
31 import org.sonar.plugins.core.widgets.WelcomeWidget;
32
33 /**
34  * Projects global dashboard for Sonar
35  *
36  * @since 3.1
37  */
38 public final class GlobalDefaultDashboard extends DashboardTemplate {
39
40   private MeasureFilterDao filterDao;
41
42   public GlobalDefaultDashboard(MeasureFilterDao filterDao) {
43     this.filterDao = filterDao;
44   }
45
46
47   @Override
48   public Dashboard createDashboard() {
49     Dashboard dashboard = Dashboard.create()
50       .setGlobal(true)
51       .setLayout(DashboardLayout.TWO_COLUMNS);
52
53     dashboard.addWidget(WelcomeWidget.ID, 1);
54
55     MeasureFilterDto filter = findSystemFilter(MyFavouritesFilter.NAME);
56     if (filter != null) {
57       dashboard
58         .addWidget(MeasureFilterListWidget.ID, 1)
59         .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
60         .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "50");
61     }
62
63     filter = findSystemFilter(ProjectFilter.NAME);
64     if (filter != null) {
65       dashboard
66         .addWidget(MeasureFilterListWidget.ID, 2)
67         .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
68         .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "20");
69
70       dashboard
71         .addWidget(MeasureFilterTreemapWidget.ID, 2)
72         .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
73         .setProperty(MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc")
74         .setProperty(MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, "violations_density");
75     }
76
77     return dashboard;
78   }
79
80   @Override
81   public String getName() {
82     return "Projects";
83   }
84
85   private MeasureFilterDto findSystemFilter(String name) {
86     return filterDao.findSystemFilterByName(name);
87   }
88 }