]> source.dussan.org Git - sonarqube.git/blob
d58987ec998b2ae31511c382509fece168b8576e
[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   @Override
47   public Dashboard createDashboard() {
48     Dashboard dashboard = Dashboard.create()
49         .setGlobal(true)
50         .setLayout(DashboardLayout.TWO_COLUMNS);
51
52     dashboard.addWidget(WelcomeWidget.ID, 1);
53
54     MeasureFilterDto filter = findSystemFilter(MyFavouritesFilter.NAME);
55     if (filter != null) {
56       dashboard
57           .addWidget(MeasureFilterListWidget.ID, 1)
58           .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
59           .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "50");
60     }
61
62     filter = findSystemFilter(ProjectFilter.NAME);
63     if (filter != null) {
64       dashboard
65           .addWidget(MeasureFilterListWidget.ID, 2)
66           .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
67           .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "20");
68
69       dashboard
70           .addWidget(MeasureFilterTreemapWidget.ID, 2)
71           .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
72           .setProperty(MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc")
73           .setProperty(MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, "violations_density");
74     }
75
76     return dashboard;
77   }
78
79   @Override
80   public String getName() {
81     return "Home";
82   }
83
84   private MeasureFilterDto findSystemFilter(String name) {
85     return filterDao.findSystemFilterByName(name);
86   }
87 }