You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BranchesPanel.java 3.5KB

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