James Moger
2011-04-23 f5d0ad7e706f1743b01dcc71f42112d533de89c2
commit | author | age
a645ba 1 package com.gitblit.wicket.panels;
JM 2
3 import java.text.MessageFormat;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.Map;
7 import java.util.concurrent.atomic.AtomicInteger;
8
9 import org.apache.wicket.markup.html.basic.Label;
10 import org.apache.wicket.markup.html.panel.Panel;
11 import org.apache.wicket.markup.repeater.Item;
12 import org.apache.wicket.markup.repeater.data.DataView;
13 import org.apache.wicket.markup.repeater.data.ListDataProvider;
14 import org.eclipse.jgit.diff.DiffEntry.ChangeType;
15
16 import com.gitblit.utils.JGitUtils;
17 import com.gitblit.wicket.WicketUtils;
18 import com.gitblit.wicket.models.PathModel.PathChangeModel;
19
20 public class CommitLegendPanel extends Panel {
21
22     private static final long serialVersionUID = 1L;
23
24     public CommitLegendPanel(String id, List<PathChangeModel> paths) {
25         super(id);
26         final Map<ChangeType, AtomicInteger> stats = JGitUtils.getChangedPathsStats(paths);        
27         ListDataProvider<ChangeType> legendDp = new ListDataProvider<ChangeType>(new ArrayList<ChangeType>(stats.keySet()));
28         DataView<ChangeType> legendsView = new DataView<ChangeType>("legend", legendDp) {
29             private static final long serialVersionUID = 1L;
30
31             public void populateItem(final Item<ChangeType> item) {
32                 ChangeType entry = item.getModelObject();
33
34                 Label changeType = new Label("changeType", "");
35                 WicketUtils.setChangeTypeCssClass(changeType, entry);
36                 item.add(changeType);
37                 int count = stats.get(entry).intValue();
38                 String description  = "";
39                 switch(entry) {
40                 case ADD:
41                     description = MessageFormat.format(getString("gb.filesAdded"), count);
42                     break;
43                 case MODIFY:
44                     description = MessageFormat.format(getString("gb.filesModified"), count);
45                     break;
46                 case DELETE:
47                     description = MessageFormat.format(getString("gb.filesDeleted"), count);
48                     break;
49                 case COPY:
50                     description = MessageFormat.format(getString("gb.filesCopied"), count);
51                     break;
52                 case RENAME:
53                     description = MessageFormat.format(getString("gb.filesRenamed"), count);
54                     break;
55                 }                
56                 item.add(new Label("description", description));
57             }
58         };
59         add(legendsView);
60     }
61 }