2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
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.
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.
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
20 package org.sonar.plugins.design.ui.dependencies.client;
22 import com.google.gwt.user.client.ui.FlowPanel;
23 import com.google.gwt.user.client.ui.Widget;
24 import org.sonar.gwt.Metrics;
25 import org.sonar.gwt.ui.Loading;
26 import org.sonar.gwt.ui.Page;
27 import org.sonar.wsclient.gwt.AbstractCallback;
28 import org.sonar.wsclient.gwt.AbstractListCallback;
29 import org.sonar.wsclient.gwt.Sonar;
30 import org.sonar.wsclient.services.Dependency;
31 import org.sonar.wsclient.services.DependencyQuery;
32 import org.sonar.wsclient.services.Resource;
33 import org.sonar.wsclient.services.ResourceQuery;
35 import java.util.List;
37 public class DependenciesTab extends Page {
38 public static final String GWT_ID = "org.sonar.plugins.design.ui.dependencies.DependenciesTab";
40 private FlowPanel panel = null;
41 private DependenciesTable dependenciesTable = null;
42 private Loading loading;
45 protected Widget doOnResourceLoad(Resource resource) {
47 Data data = new Data(resource.getId());
49 loadDependencies(data);
53 private void prepare() {
55 panel = new FlowPanel();
56 panel.getElement().setId("deps");
57 loading = new Loading();
58 dependenciesTable = new DependenciesTable();
59 panel.setWidth("100%");
65 private void loadMeasures(final Data data) {
66 ResourceQuery query = new ResourceQuery(data.getResourceId());
67 query.setMetrics(Metrics.EFFERENT_COUPLINGS, Metrics.AFFERENT_COUPLINGS);
68 query.setVerbose(true);
69 Sonar.getInstance().find(query, new AbstractCallback<org.sonar.wsclient.services.Resource>() {
71 protected void doOnResponse(org.sonar.wsclient.services.Resource resource) {
72 data.setMeasures(resource);
73 displayMeasures(data);
78 private void loadDependencies(final Data data) {
79 DependencyQuery query = DependencyQuery.createForResource(data.getResourceId());
80 Sonar.getInstance().findAll(query, new AbstractListCallback<Dependency>() {
83 protected void doOnResponse(List<Dependency> dependencies) {
84 data.setDependencies(dependencies);
85 displayMeasures(data);
91 private void displayMeasures(Data data) {
92 if (data.isLoaded()) {
94 dependenciesTable.display(data);
95 panel.add(dependenciesTable);