001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.plugins.design.ui.dependencies.client; 021 022 import com.google.gwt.user.client.ui.FlowPanel; 023 import com.google.gwt.user.client.ui.Widget; 024 import org.sonar.gwt.Metrics; 025 import org.sonar.gwt.ui.Loading; 026 import org.sonar.gwt.ui.Page; 027 import org.sonar.wsclient.gwt.AbstractCallback; 028 import org.sonar.wsclient.gwt.AbstractListCallback; 029 import org.sonar.wsclient.gwt.Sonar; 030 import org.sonar.wsclient.services.Dependency; 031 import org.sonar.wsclient.services.DependencyQuery; 032 import org.sonar.wsclient.services.Resource; 033 import org.sonar.wsclient.services.ResourceQuery; 034 035 import java.util.List; 036 037 public class DependenciesTab extends Page { 038 public static final String GWT_ID = "org.sonar.plugins.design.ui.dependencies.DependenciesTab"; 039 040 private FlowPanel panel = null; 041 private DependenciesTable dependenciesTable = null; 042 private Loading loading; 043 044 @Override 045 protected Widget doOnResourceLoad(Resource resource) { 046 prepare(); 047 Data data = new Data(resource.getId()); 048 loadMeasures(data); 049 loadDependencies(data); 050 return panel; 051 } 052 053 private void prepare() { 054 if (panel == null) { 055 panel = new FlowPanel(); 056 panel.getElement().setId("deps"); 057 loading = new Loading(); 058 dependenciesTable = new DependenciesTable(); 059 panel.setWidth("100%"); 060 } 061 panel.clear(); 062 panel.add(loading); 063 } 064 065 private void loadMeasures(final Data data) { 066 ResourceQuery query = new ResourceQuery(data.getResourceId()); 067 query.setMetrics(Metrics.EFFERENT_COUPLINGS, Metrics.AFFERENT_COUPLINGS); 068 query.setVerbose(true); 069 Sonar.getInstance().find(query, new AbstractCallback<org.sonar.wsclient.services.Resource>() { 070 @Override 071 protected void doOnResponse(org.sonar.wsclient.services.Resource resource) { 072 data.setMeasures(resource); 073 displayMeasures(data); 074 } 075 }); 076 } 077 078 private void loadDependencies(final Data data) { 079 DependencyQuery query = DependencyQuery.createForResource(data.getResourceId()); 080 Sonar.getInstance().findAll(query, new AbstractListCallback<Dependency>() { 081 082 @Override 083 protected void doOnResponse(List<Dependency> dependencies) { 084 data.setDependencies(dependencies); 085 displayMeasures(data); 086 } 087 }); 088 } 089 090 091 private void displayMeasures(Data data) { 092 if (data.isLoaded()) { 093 panel.clear(); 094 dependenciesTable.display(data); 095 panel.add(dependenciesTable); 096 } 097 } 098 }