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.i18n.client.Dictionary; 023 import com.google.gwt.user.client.ui.*; 024 import org.sonar.wsclient.services.Measure; 025 import org.sonar.wsclient.services.Resource; 026 027 public class Header extends Composite { 028 private FlowPanel header; 029 030 public Header() { 031 header = new FlowPanel(); 032 header.setStyleName("gwt-ViewerHeader"); 033 initWidget(header); 034 } 035 036 private void addMeasure(Panel panel, Resource resource, String key, String label) { 037 Measure measure = resource.getMeasure(key); 038 if (measure != null) { 039 HTML html = new HTML(label + ": "); 040 html.setStyleName("metric"); 041 panel.add(html); 042 043 html = new HTML(measure.getFormattedValue("-")); 044 html.setStyleName("value"); 045 panel.add(html); 046 } 047 } 048 049 public void display(Data data) { 050 header.clear(); 051 HorizontalPanel panel = new HorizontalPanel(); 052 header.add(panel); 053 Dictionary l10n = Dictionary.getDictionary("l10n"); 054 addMeasure(panel, data.getResource(), "classes", l10n.get("depsTab.classes")); 055 addMeasure(panel, data.getResource(), "dit", l10n.get("depsTab.dit")); 056 addMeasure(panel, data.getResource(), "noc", l10n.get("depsTab.noc")); 057 addMeasure(panel, data.getResource(), "rfc", l10n.get("depsTab.rfc")); 058 addLcom4(data, panel); 059 } 060 061 private void addLcom4(Data data, HorizontalPanel panel) { 062 Measure lcom4 = data.getResource().getMeasure("lcom4"); 063 if (lcom4 != null && lcom4.getIntValue()!=null) { 064 HTML html = new HTML(Dictionary.getDictionary("l10n").get("depsTab.lcom4") + ": "); 065 html.setStyleName("metric"); 066 panel.add(html); 067 068 html = new HTML(lcom4.getIntValue() + ""); 069 html.setStyleName("value"); 070 if (lcom4.getIntValue()>1) { 071 html.addStyleName("red bold"); 072 } 073 074 panel.add(html); 075 } 076 } 077 }