001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2012 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.page.client;
021    
022    import com.google.gwt.user.client.ui.Panel;
023    import com.google.gwt.user.client.ui.VerticalPanel;
024    import com.google.gwt.user.client.ui.Widget;
025    import org.sonar.gwt.Configuration;
026    import org.sonar.gwt.Metrics;
027    import org.sonar.gwt.ui.Page;
028    import org.sonar.wsclient.gwt.AbstractCallback;
029    import org.sonar.wsclient.gwt.Sonar;
030    import org.sonar.wsclient.services.Measure;
031    import org.sonar.wsclient.services.Resource;
032    import org.sonar.wsclient.services.ResourceQuery;
033    
034    public class DesignPage extends Page {
035    
036      public static final String GWT_ID = "org.sonar.plugins.design.ui.page.DesignPage";
037      private Dsm matrix;
038    
039      @Override
040      protected Widget doOnResourceLoad(Resource resource) {
041        String dependencyId = Configuration.getRequestParameter("depId");
042        if (dependencyId != null) {
043          DependencyInfo.getInstance().setPopupMode(true).show(dependencyId);
044          return DependencyInfo.getInstance();
045        }
046        VerticalPanel layout = new VerticalPanel();
047        layout.setWidth("100%");
048        Panel hPanel = new VerticalPanel();
049        matrix = new Dsm();
050        hPanel.add(matrix);
051        hPanel.add(DependencyInfo.getInstance());
052        layout.add(hPanel);
053        loadMatrix(resource);
054        return layout;
055      }
056    
057      private void loadMatrix(Resource resource) {
058        Sonar.getInstance().find(ResourceQuery.createForMetrics(resource.getId().toString(), "dsm"), new AbstractCallback<Resource>() {
059    
060          @Override
061          protected void doOnResponse(Resource resource) {
062            if (resource == null || resource.getMeasure(Metrics.DEPENDENCY_MATRIX) == null) {
063              matrix.displayNoData();
064              
065            } else {
066              Measure dsm = resource.getMeasure(Metrics.DEPENDENCY_MATRIX);
067              matrix.display(DsmData.parse(dsm.getData()));
068            }
069          }
070        });
071      }
072    }