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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.panels;
  17. import java.util.ArrayList;
  18. import java.util.Collections;
  19. import java.util.List;
  20. import org.apache.wicket.markup.html.basic.Label;
  21. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  22. import org.apache.wicket.markup.repeater.Item;
  23. import org.apache.wicket.markup.repeater.data.DataView;
  24. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  25. import org.apache.wicket.model.StringResourceModel;
  26. import org.eclipse.jgit.lib.Constants;
  27. import org.eclipse.jgit.lib.Repository;
  28. import com.gitblit.utils.JGitUtils;
  29. import com.gitblit.utils.StringUtils;
  30. import com.gitblit.wicket.LinkPanel;
  31. import com.gitblit.wicket.WicketUtils;
  32. import com.gitblit.wicket.models.RefModel;
  33. import com.gitblit.wicket.models.RepositoryModel;
  34. import com.gitblit.wicket.pages.BranchesPage;
  35. import com.gitblit.wicket.pages.LogPage;
  36. import com.gitblit.wicket.pages.SummaryPage;
  37. import com.gitblit.wicket.pages.TreePage;
  38. public class BranchesPanel extends BasePanel {
  39. private static final long serialVersionUID = 1L;
  40. public BranchesPanel(String wicketId, final RepositoryModel model, Repository r, final int maxCount) {
  41. super(wicketId);
  42. // branches
  43. List<RefModel> branches = new ArrayList<RefModel>();
  44. branches.addAll(JGitUtils.getLocalBranches(r, maxCount));
  45. if (model.showRemoteBranches) {
  46. branches.addAll(JGitUtils.getRemoteBranches(r, maxCount));
  47. }
  48. Collections.sort(branches);
  49. Collections.reverse(branches);
  50. if (maxCount > 0 && branches.size() > maxCount) {
  51. branches = new ArrayList<RefModel>(branches.subList(0, maxCount));
  52. }
  53. if (maxCount > 0) {
  54. // summary page
  55. // show branches page link
  56. add(new LinkPanel("branches", "title", new StringResourceModel("gb.branches", this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
  57. } else {
  58. // branches page
  59. // show repository summary page link
  60. add(new LinkPanel("branches", "title", model.name, SummaryPage.class, WicketUtils.newRepositoryParameter(model.name)));
  61. }
  62. ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
  63. DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
  64. private static final long serialVersionUID = 1L;
  65. int counter = 0;
  66. public void populateItem(final Item<RefModel> item) {
  67. final RefModel entry = item.getModelObject();
  68. item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));
  69. item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(entry.getDisplayName(), 28), LogPage.class, WicketUtils.newObjectParameter(model.name, entry.getName())));
  70. // only show branch type on the branches page
  71. boolean remote = entry.getName().startsWith(Constants.R_REMOTES);
  72. item.add(new Label("branchType", remote ? getString("gb.remote") : getString("gb.local")).setVisible(maxCount <= 0));
  73. item.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils.newObjectParameter(model.name, entry.getName())));
  74. item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newObjectParameter(model.name, entry.getName())));
  75. WicketUtils.setAlternatingBackground(item, counter);
  76. counter++;
  77. }
  78. };
  79. add(branchesView);
  80. if (branches.size() < maxCount || maxCount <= 0) {
  81. add(new Label("allBranches", "").setVisible(false));
  82. } else {
  83. add(new LinkPanel("allBranches", "link", new StringResourceModel("gb.allBranches", this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
  84. }
  85. }
  86. }