001    package org.hackystat.projectbrowser.page.dailyprojectdata.commit;
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 Commit.
014     * 
015     * @author Philip Johnson
016     */
017    public class CommitPanel extends Panel {
018    
019      /** Support serialization. */
020      private static final long serialVersionUID = 1L;
021    
022      /**
023       * Create this panel, providing the appropriate wicket ID.
024       * 
025       * @param id The wicket component id.
026       */
027      public CommitPanel(String id) {
028        super(id);
029        DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
030        // prepare the data model.
031        CommitDataModel dataModel = session.getCommitDataModel();
032        ListView listView = new ListView("commitDataList", new PropertyModel(dataModel,
033            "commitDataList")) {
034          /** Support serialization. */
035          private static final long serialVersionUID = 1L;
036    
037          @Override
038          protected void populateItem(ListItem item) {
039            CommitData data = (CommitData) item.getModelObject();
040            item.add(new Label("project", data.getProject().getName()));
041            item.add(new Label("commitdata", data.getCommitData()));
042            item.add(new Label("total", String.format("%d/%d", data.getTotalCommit(), 
043                data.getTotalChurn())));
044          }
045        };
046        add(listView);
047      }
048    
049      /**
050       * Returns true if this panel should be displayed.  
051       * The panel should be displayed if its corresponding data model has information.
052       * @return True if this panel should be displayed. 
053       */
054      @Override
055      public boolean isVisible() {
056        DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
057        return !session.getCommitDataModel().isEmpty(); 
058      }
059    }