001    package org.hackystat.projectbrowser.page.dailyprojectdata.coupling;
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 coupling.
014     * 
015     * @author Philip Johnson
016     * @author Shaoxuan Zhang
017     * 
018     */
019    public class CouplingPanel 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 CouplingPanel(String id) {
030        super(id);
031        DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
032        // prepare the data model.
033        CouplingDataModel dataModel = session.getCouplingDataModel();
034        add(new Label("valuesType", session.getContextSensitiveMenu("Values").getSelectedValue()));
035        add(new Label("couplingType", 
036            session.getContextSensitiveMenu("Coupling Type").getSelectedValue()));
037        ListView memberDataListView = new ListView("couplingDataList", new PropertyModel(dataModel,
038            "couplingDataList")) {
039          /** Support serialization. */
040          private static final long serialVersionUID = 1L;
041    
042          @Override
043          protected void populateItem(ListItem item) {
044            CouplingData couplingData = (CouplingData) item.getModelObject();
045            item.add(new Label("project", couplingData.getProject().getName()));
046            DailyProjectDataSession session = ProjectBrowserSession.get().getDailyProjectDataSession();
047            String valueType = session.getContextSensitiveMenu("Values").getSelectedValue();
048            boolean isCount = ("Count".equals(valueType));
049            item.add(couplingData.getPanel("bucket0", 0, isCount));
050            item.add(couplingData.getPanel("bucket1", 1, isCount));
051            item.add(couplingData.getPanel("bucket2", 2, isCount));
052            item.add(couplingData.getPanel("bucket3", 3, isCount));
053            item.add(couplingData.getPanel("bucket4", 4, isCount));
054            item.add(new Label("total", couplingData.getTotalString()));
055          }
056        };
057        add(memberDataListView);
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.getCouplingDataModel().isEmpty(); 
069      }
070    }