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.

TreePage.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.pages;
  17. import java.util.List;
  18. import org.apache.wicket.PageParameters;
  19. import org.apache.wicket.markup.html.basic.Label;
  20. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  21. import org.apache.wicket.markup.html.link.ExternalLink;
  22. import org.apache.wicket.markup.html.panel.Fragment;
  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.Repository;
  28. import org.eclipse.jgit.revwalk.RevCommit;
  29. import com.gitblit.DownloadZipServlet;
  30. import com.gitblit.GitBlit;
  31. import com.gitblit.Keys;
  32. import com.gitblit.utils.ByteFormat;
  33. import com.gitblit.utils.JGitUtils;
  34. import com.gitblit.wicket.LinkPanel;
  35. import com.gitblit.wicket.RepositoryPage;
  36. import com.gitblit.wicket.WicketUtils;
  37. import com.gitblit.wicket.models.PathModel;
  38. import com.gitblit.wicket.panels.CommitHeaderPanel;
  39. import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
  40. public class TreePage extends RepositoryPage {
  41. public TreePage(PageParameters params) {
  42. super(params);
  43. final String path = WicketUtils.getPath(params);
  44. Repository r = getRepository();
  45. RevCommit commit = getCommit();
  46. List<PathModel> paths = JGitUtils.getFilesInPath(r, path, commit);
  47. // tree page links
  48. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, objectId, path)));
  49. add(new BookmarkablePageLink<Void>("headLink", TreePage.class, WicketUtils.newPathParameter(repositoryName, Constants.HEAD, path)));
  50. add(new ExternalLink("zipLink", DownloadZipServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), repositoryName, objectId, path)).setVisible(GitBlit.self().settings().getBoolean(Keys.web.allowZipDownloads, true)));
  51. add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
  52. // breadcrumbs
  53. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
  54. if (path != null && path.trim().length() > 0) {
  55. paths.add(0, PathModel.getParentPath(path, objectId));
  56. }
  57. final ByteFormat byteFormat = new ByteFormat();
  58. // changed paths list
  59. ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
  60. DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
  61. private static final long serialVersionUID = 1L;
  62. int counter = 0;
  63. public void populateItem(final Item<PathModel> item) {
  64. PathModel entry = item.getModelObject();
  65. item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
  66. if (entry.isParentPath) {
  67. // parent .. path
  68. item.add(WicketUtils.newBlankImage("pathIcon"));
  69. item.add(new Label("pathSize", ""));
  70. item.add(new LinkPanel("pathName", null, entry.name, TreePage.class, newPathParameter(entry.path)));
  71. item.add(new Label("pathLinks", ""));
  72. } else {
  73. if (entry.isTree()) {
  74. // folder/tree link
  75. item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
  76. item.add(new Label("pathSize", ""));
  77. item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class, newPathParameter(entry.path)));
  78. // links
  79. Fragment links = new Fragment("pathLinks", "treeLinks", this);
  80. links.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
  81. links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
  82. links.add(new ExternalLink("zip", DownloadZipServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), repositoryName, objectId, entry.path)).setVisible(GitBlit.self().settings().getBoolean(Keys.web.allowZipDownloads, true)));
  83. item.add(links);
  84. } else {
  85. // blob link
  86. item.add(WicketUtils.getFileImage("pathIcon", entry.name));
  87. item.add(new Label("pathSize", byteFormat.format(entry.size)));
  88. item.add(new LinkPanel("pathName", "list", entry.name, BlobPage.class, newPathParameter(entry.path)));
  89. // links
  90. Fragment links = new Fragment("pathLinks", "blobLinks", this);
  91. links.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
  92. links.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
  93. links.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));
  94. links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
  95. item.add(links);
  96. }
  97. }
  98. WicketUtils.setAlternatingBackground(item, counter);
  99. counter++;
  100. }
  101. };
  102. add(pathsView);
  103. }
  104. @Override
  105. protected String getPageName() {
  106. return getString("gb.tree");
  107. }
  108. }