001    package org.hackystat.projectbrowser.page.dailyprojectdata.unittest;
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 unittest.
014     * 
015     * @author Philip Johnson
016     * @author Shaoxuan Zhang
017     * 
018     */
019    public class UnitTestPanel 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 UnitTestPanel(String id) {
030        super(id);
031        DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
032        // prepare the data model.
033        UnitTestDataModel dataModel = session.getUnitTestDataModel();
034        add(new Label("valuesType", session.getContextSensitiveMenu("Values").getSelectedValue()));
035        ListView unitTestListView = new ListView("unitTestDataList", new PropertyModel(dataModel,
036            "unitTestDataList")) {
037          /** Support serialization. */
038          private static final long serialVersionUID = 1L;
039    
040          @Override
041          protected void populateItem(ListItem item) {
042            UnitTestData unittestData = (UnitTestData) item.getModelObject();
043            item.add(new Label("project", unittestData.getProject().getName()));
044            DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
045            String valueType = session.getContextSensitiveMenu("Values").getSelectedValue();
046            if ("Count".equals(valueType)) {
047              item.add(new Label("bucket0", unittestData.getBucketCountString(0)));
048              item.add(new Label("bucket1", unittestData.getBucketCountString(1)));
049            }
050            else {
051              item.add(new Label("bucket0", unittestData.getBucketPercentageString(0)));
052              item.add(new Label("bucket1", unittestData.getBucketPercentageString(1)));
053            }
054            item.add(new Label("total", unittestData.getTotalString()));
055          }
056        };
057        add(unitTestListView);
058      }
059    
060      /**
061       * Returns true if this panel should be displayed.  
062       * The panel should be displayed if its corresponding data model has information.
063       * @return True if this panel should be displayed. 
064       */
065      @Override
066      public boolean isVisible() {
067        DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
068        return !session.getUnitTestDataModel().isEmpty(); 
069      }
070    }