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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.html.link.ExternalLink;
  23. import org.apache.wicket.markup.html.panel.Fragment;
  24. import org.apache.wicket.markup.repeater.Item;
  25. import org.apache.wicket.markup.repeater.data.DataView;
  26. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  27. import org.apache.wicket.model.StringResourceModel;
  28. import org.eclipse.jgit.lib.Repository;
  29. import com.gitblit.SyndicationServlet;
  30. import com.gitblit.models.RefModel;
  31. import com.gitblit.models.RepositoryModel;
  32. import com.gitblit.utils.JGitUtils;
  33. import com.gitblit.utils.JGitUtils.SearchType;
  34. import com.gitblit.utils.StringUtils;
  35. import com.gitblit.wicket.WicketUtils;
  36. import com.gitblit.wicket.pages.BranchesPage;
  37. import com.gitblit.wicket.pages.CommitPage;
  38. import com.gitblit.wicket.pages.LogPage;
  39. import com.gitblit.wicket.pages.MetricsPage;
  40. import com.gitblit.wicket.pages.SearchPage;
  41. import com.gitblit.wicket.pages.SummaryPage;
  42. import com.gitblit.wicket.pages.TreePage;
  43. public class BranchesPanel extends BasePanel {
  44. private static final long serialVersionUID = 1L;
  45. private final boolean hasBranches;
  46. public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,
  47. final int maxCount) {
  48. super(wicketId);
  49. // branches
  50. List<RefModel> branches = new ArrayList<RefModel>();
  51. branches.addAll(JGitUtils.getLocalBranches(r, false, maxCount));
  52. if (model.showRemoteBranches) {
  53. branches.addAll(JGitUtils.getRemoteBranches(r, false, maxCount));
  54. }
  55. Collections.sort(branches);
  56. Collections.reverse(branches);
  57. if (maxCount > 0 && branches.size() > maxCount) {
  58. branches = new ArrayList<RefModel>(branches.subList(0, maxCount));
  59. }
  60. if (maxCount > 0) {
  61. // summary page
  62. // show branches page link
  63. add(new LinkPanel("branches", "title", new StringResourceModel("gb.branches", this,
  64. null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
  65. } else {
  66. // branches page
  67. // show repository summary page link
  68. add(new LinkPanel("branches", "title", model.name, SummaryPage.class,
  69. WicketUtils.newRepositoryParameter(model.name)));
  70. }
  71. ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
  72. DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
  73. private static final long serialVersionUID = 1L;
  74. int counter;
  75. public void populateItem(final Item<RefModel> item) {
  76. final RefModel entry = item.getModelObject();
  77. item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));
  78. item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(
  79. entry.displayName, 28), LogPage.class, WicketUtils.newObjectParameter(
  80. model.name, entry.getName())));
  81. String author = entry.getAuthorIdent().getName();
  82. LinkPanel authorLink = new LinkPanel("branchAuthor", "list", author,
  83. SearchPage.class, WicketUtils.newSearchParameter(model.name,
  84. entry.getName(), author, SearchType.AUTHOR));
  85. setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
  86. item.add(authorLink);
  87. // short message
  88. String shortMessage = entry.getShortMessage();
  89. String trimmedMessage = StringUtils.trimShortLog(shortMessage);
  90. LinkPanel shortlog = new LinkPanel("branchLog", "list subject", trimmedMessage,
  91. CommitPage.class, WicketUtils.newObjectParameter(model.name,
  92. entry.getName()));
  93. if (!shortMessage.equals(trimmedMessage)) {
  94. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  95. }
  96. item.add(shortlog);
  97. if (maxCount <= 0) {
  98. Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);
  99. fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
  100. .newObjectParameter(model.name, entry.getName())));
  101. fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
  102. .newObjectParameter(model.name, entry.getName())));
  103. fragment.add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
  104. WicketUtils.newObjectParameter(model.name, entry.getName())));
  105. fragment.add(new ExternalLink("syndication", SyndicationServlet.asLink(
  106. getRequest().getRelativePathPrefixToContextRoot(), model.name,
  107. entry.getName(), 0)));
  108. item.add(fragment);
  109. } else {
  110. Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);
  111. fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
  112. .newObjectParameter(model.name, entry.getName())));
  113. fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
  114. .newObjectParameter(model.name, entry.getName())));
  115. item.add(fragment);
  116. }
  117. WicketUtils.setAlternatingBackground(item, counter);
  118. counter++;
  119. }
  120. };
  121. add(branchesView);
  122. if (branches.size() < maxCount || maxCount <= 0) {
  123. add(new Label("allBranches", "").setVisible(false));
  124. } else {
  125. add(new LinkPanel("allBranches", "link", new StringResourceModel("gb.allBranches",
  126. this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
  127. }
  128. // We always have 1 branch
  129. hasBranches = (branches.size() > 1)
  130. || ((branches.size() == 1) && !branches.get(0).displayName
  131. .equalsIgnoreCase("master"));
  132. }
  133. public BranchesPanel hideIfEmpty() {
  134. setVisible(hasBranches);
  135. return this;
  136. }
  137. }