2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube 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.
11 * SonarQube 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.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.plugins.design.ui.libraries.client;
22 import com.google.gwt.i18n.client.Dictionary;
23 import com.google.gwt.user.client.ui.*;
24 import org.sonar.gwt.ui.Icons;
25 import org.sonar.gwt.ui.Loading;
26 import org.sonar.wsclient.gwt.AbstractListCallback;
27 import org.sonar.wsclient.gwt.Sonar;
28 import org.sonar.wsclient.services.DependencyTree;
29 import org.sonar.wsclient.services.DependencyTreeQuery;
30 import org.sonar.wsclient.services.Resource;
32 import java.util.List;
34 public class ProjectPanel extends FlowPanel {
38 private Filters filters;
40 public ProjectPanel(Resource project, Filters filters) {
41 this.filters = filters;
43 getElement().setId("libs-" + project.getKey());
44 add(new Loading(project.getName()));
45 loadLibraries(project);
48 private void loadLibraries(final Resource project) {
49 Sonar.getInstance().findAll(DependencyTreeQuery.createForProject(project.getId().toString()), new AbstractListCallback<DependencyTree>() {
52 protected void doOnResponse(List<DependencyTree> dependencyTrees) {
56 if (dependencyTrees == null || dependencyTrees.isEmpty()) {
59 add(createNoLibsMessage());
62 display(dependencyTrees, null);
71 private void createTitle(Resource project) {
72 String html = Icons.forQualifier(project.getQualifier()).getHTML();
73 html += " <span class=''> " + project.getName() + "</span> ";
75 if (project.getVersion() != null) {
76 html += project.getVersion() + " ";
78 title = new HTML(html);
81 private void display(List<DependencyTree> depTrees, TreeItem parentLibrary) {
82 if (depTrees != null) {
83 for (DependencyTree depTree : depTrees) {
84 Library library = new Library(depTree);
85 if (parentLibrary == null) {
86 tree.addItem(library);
87 library.setState(true);
89 parentLibrary.addItem(library);
91 display(depTree.getTo(), library);
92 library.setState(true);
97 private void createTree() {
99 tree.setAnimationEnabled(false);
104 private Label createNoLibsMessage() {
105 Label msg = new Label(Dictionary.getDictionary("l10n").get("libs.noLibraries"));
106 msg.setStyleName("nolibs");
110 public void filter() {
111 boolean visible = (tree.getItemCount() == 0 && !filters.hasKeyword());
112 for (int index = 0; index < tree.getItemCount(); index++) {
113 Library lib = (Library) tree.getItem(index);
114 visible |= !lib.filter(filters.getKeywordFilter().getKeyword(), filters.isTestFiltered());
119 public void expandCollapse(boolean expand) {
120 for (int index = 0; index < tree.getItemCount(); index++) {
121 openItem(tree.getItem(index), expand);
125 private void openItem(TreeItem item, boolean open) {
127 for (int i = 0; i < item.getChildCount(); i++) {
128 openItem(item.getChild(i), open);