James Moger
2011-04-23 f5d0ad7e706f1743b01dcc71f42112d533de89c2
commit | author | age
698678 1 package com.gitblit.wicket.panels;
JM 2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import org.apache.wicket.markup.html.basic.Label;
8 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
9 import org.apache.wicket.markup.repeater.Item;
10 import org.apache.wicket.markup.repeater.data.DataView;
11 import org.apache.wicket.markup.repeater.data.ListDataProvider;
12 import org.apache.wicket.model.StringResourceModel;
13 import org.eclipse.jgit.lib.Constants;
14 import org.eclipse.jgit.lib.Repository;
15
16 import com.gitblit.utils.JGitUtils;
87cc1e 17 import com.gitblit.utils.StringUtils;
698678 18 import com.gitblit.wicket.LinkPanel;
JM 19 import com.gitblit.wicket.WicketUtils;
20 import com.gitblit.wicket.models.RefModel;
21 import com.gitblit.wicket.pages.BranchesPage;
22 import com.gitblit.wicket.pages.LogPage;
23 import com.gitblit.wicket.pages.SummaryPage;
24 import com.gitblit.wicket.pages.TreePage;
25
bc10f9 26 public class BranchesPanel extends BasePanel {
698678 27
JM 28     private static final long serialVersionUID = 1L;
29
30     public BranchesPanel(String wicketId, final String repositoryName, Repository r, final int maxCount) {
31         super(wicketId);
32
33         // branches
34         List<RefModel> branches = new ArrayList<RefModel>();
35         branches.addAll(JGitUtils.getLocalBranches(r, maxCount));
36         branches.addAll(JGitUtils.getRemoteBranches(r, maxCount));
37         Collections.sort(branches);
38         Collections.reverse(branches);
39         if (maxCount > 0 && branches.size() > maxCount) {
40             branches = new ArrayList<RefModel>(branches.subList(0, maxCount));
41         }
42
43         if (maxCount > 0) {
44             // summary page
45             // show branches page link
46             add(new LinkPanel("branches", "title", new StringResourceModel("gb.branches", this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
47         } else {
48             // branches page
49             // show repository summary page link
50             add(new LinkPanel("branches", "title", repositoryName, SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
51         }
155bf7 52
698678 53         ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
JM 54         DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
55             private static final long serialVersionUID = 1L;
56             int counter = 0;
57
58             public void populateItem(final Item<RefModel> item) {
59                 final RefModel entry = item.getModelObject();
60
bc10f9 61                 item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));
698678 62
87cc1e 63                 item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(entry.getDisplayName(), 28), LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
155bf7 64
698678 65                 // only show branch type on the branches page
JM 66                 boolean remote = entry.getName().startsWith(Constants.R_REMOTES);
155bf7 67                 item.add(new Label("branchType", remote ? getString("gb.remote") : getString("gb.local")).setVisible(maxCount <= 0));
JM 68
ef5c58 69                 item.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
JM 70                 item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newObjectParameter(repositoryName, entry.getName())));
698678 71
JM 72                 WicketUtils.setAlternatingBackground(item, counter);
73                 counter++;
74             }
75         };
76         add(branchesView);
77         if (branches.size() < maxCount || maxCount <= 0) {
78             add(new Label("allBranches", "").setVisible(false));
79         } else {
80             add(new LinkPanel("allBranches", "link", new StringResourceModel("gb.allBranches", this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
81         }
82     }
83 }