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.

RefsPanel.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 java.util.Map;
  21. import org.apache.wicket.Component;
  22. import org.apache.wicket.markup.html.panel.Panel;
  23. import org.apache.wicket.markup.repeater.Item;
  24. import org.apache.wicket.markup.repeater.data.DataView;
  25. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  26. import org.eclipse.jgit.lib.Constants;
  27. import org.eclipse.jgit.lib.ObjectId;
  28. import org.eclipse.jgit.revwalk.RevCommit;
  29. import com.gitblit.wicket.LinkPanel;
  30. import com.gitblit.wicket.WicketUtils;
  31. import com.gitblit.wicket.pages.CommitPage;
  32. import com.gitblit.wicket.pages.LogPage;
  33. import com.gitblit.wicket.pages.TagPage;
  34. public class RefsPanel extends Panel {
  35. private static final long serialVersionUID = 1L;
  36. public RefsPanel(String id, final String repositoryName, RevCommit c, Map<ObjectId, List<String>> refs) {
  37. super(id);
  38. List<String> refNames = refs.get(c.getId());
  39. if (refNames == null) {
  40. refNames = new ArrayList<String>();
  41. }
  42. Collections.sort(refNames);
  43. // refNames.remove(Constants.HEAD);
  44. ListDataProvider<String> refsDp = new ListDataProvider<String>(refNames);
  45. DataView<String> refsView = new DataView<String>("ref", refsDp) {
  46. private static final long serialVersionUID = 1L;
  47. public void populateItem(final Item<String> item) {
  48. String entry = item.getModelObject();
  49. Component c = null;
  50. if (entry.startsWith(Constants.R_HEADS)) {
  51. // local head
  52. c = new LinkPanel("refName", null, entry.substring(Constants.R_HEADS.length()), LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry));
  53. WicketUtils.setCssClass(c, "headRef");
  54. } else if (entry.startsWith(Constants.R_REMOTES)) {
  55. // remote head
  56. c = new LinkPanel("refName", null, entry.substring(Constants.R_REMOTES.length()), LogPage.class, WicketUtils.newObjectParameter(repositoryName, entry));
  57. WicketUtils.setCssClass(c, "remoteRef");
  58. } else if (entry.startsWith(Constants.R_TAGS)) {
  59. // tag
  60. c = new LinkPanel("refName", null, entry.substring(Constants.R_TAGS.length()), TagPage.class, WicketUtils.newObjectParameter(repositoryName, entry));
  61. WicketUtils.setCssClass(c, "tagRef");
  62. } else {
  63. // other
  64. c = new LinkPanel("refName", null, entry, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, entry));
  65. WicketUtils.setCssClass(c, "otherRef");
  66. }
  67. WicketUtils.setHtmlTooltip(c, entry);
  68. item.add(c);
  69. }
  70. };
  71. add(refsView);
  72. }
  73. }