001 package org.hackystat.projectbrowser.page.dailyprojectdata.complexity; 002 003 import org.apache.wicket.markup.html.basic.Label; 004 import org.apache.wicket.markup.html.list.ListItem; 005 import org.apache.wicket.markup.html.list.ListView; 006 import org.apache.wicket.markup.html.panel.Panel; 007 import org.apache.wicket.model.PropertyModel; 008 import org.hackystat.projectbrowser.ProjectBrowserSession; 009 import org.hackystat.projectbrowser.page.dailyprojectdata.DailyProjectDataSession; 010 011 012 /** 013 * Data panel for complexity. 014 * 015 * @author Philip Johnson 016 * @author Shaoxuan Zhang 017 * 018 */ 019 public class ComplexityPanel extends Panel { 020 021 /** Support serialization. */ 022 private static final long serialVersionUID = 1L; 023 024 /** 025 * Create this panel, providing the appropriate wicket ID. 026 * 027 * @param id The wicket component id. 028 */ 029 public ComplexityPanel(String id) { 030 super(id); 031 DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession(); 032 // prepare the data model. 033 ComplexityDataModel dataModel = session.getComplexityDataModel(); 034 add(new Label("valuesType", session.getContextSensitiveMenu("Values").getSelectedValue())); 035 add(new Label("complexityType", "Cyclomatic")); 036 ListView memberDataListView = new ListView("complexityDataList", new PropertyModel(dataModel, 037 "complexityDataList")) { 038 /** Support serialization. */ 039 private static final long serialVersionUID = 1L; 040 041 @Override 042 protected void populateItem(ListItem item) { 043 ComplexityData complexityData = (ComplexityData) item.getModelObject(); 044 item.add(new Label("project", complexityData.getProject().getName())); 045 DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession(); 046 String valueType = session.getContextSensitiveMenu("Values").getSelectedValue(); 047 boolean isCount = ("Count".equals(valueType)); 048 item.add(complexityData.getPanel("bucket0", 0, isCount)); 049 item.add(complexityData.getPanel("bucket1", 1, isCount)); 050 item.add(complexityData.getPanel("bucket2", 2, isCount)); 051 item.add(complexityData.getPanel("bucket3", 3, isCount)); 052 item.add(complexityData.getPanel("bucket4", 4, isCount)); 053 item.add(new Label("total", complexityData.getTotalString())); 054 } 055 }; 056 add(memberDataListView); 057 } 058 059 /** 060 * Returns true if this panel should be displayed. 061 * The panel should be displayed if its corresponding data model has information. 062 * @return True if this panel should be displayed. 063 */ 064 @Override 065 public boolean isVisible() { 066 DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession(); 067 return !session.getComplexityDataModel().isEmpty(); 068 } 069 }