James Moger
2012-02-09 d1f12af94b21a04c3cf96caf1ab83c4bdf552236
commit | author | age
f13c4c 1 /*
JM 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  */
5fe7df 16 package com.gitblit.wicket.pages;
JM 17
18 import java.util.List;
19
20 import org.apache.wicket.PageParameters;
21 import org.apache.wicket.markup.html.basic.Label;
1a3fc5 22 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
9197d3 23 import org.apache.wicket.markup.html.link.ExternalLink;
1a3fc5 24 import org.apache.wicket.markup.html.panel.Fragment;
5fe7df 25 import org.apache.wicket.markup.repeater.Item;
JM 26 import org.apache.wicket.markup.repeater.data.DataView;
27 import org.apache.wicket.markup.repeater.data.ListDataProvider;
608ece 28 import org.eclipse.jgit.lib.Constants;
f08c1c 29 import org.eclipse.jgit.lib.FileMode;
5fe7df 30 import org.eclipse.jgit.lib.Repository;
JM 31 import org.eclipse.jgit.revwalk.RevCommit;
32
9197d3 33 import com.gitblit.DownloadZipServlet;
JM 34 import com.gitblit.GitBlit;
35 import com.gitblit.Keys;
1f9dae 36 import com.gitblit.models.PathModel;
5fe7df 37 import com.gitblit.utils.ByteFormat;
JM 38 import com.gitblit.utils.JGitUtils;
39 import com.gitblit.wicket.WicketUtils;
c1c3c6 40 import com.gitblit.wicket.panels.CommitHeaderPanel;
1f9dae 41 import com.gitblit.wicket.panels.LinkPanel;
5fe7df 42 import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
JM 43
44 public class TreePage extends RepositoryPage {
45
46     public TreePage(PageParameters params) {
cebf45 47         super(params);
5fe7df 48
f602a2 49         final String path = WicketUtils.getPath(params);
5fe7df 50
JM 51         Repository r = getRepository();
bc9d4a 52         RevCommit commit = getCommit();
f602a2 53         List<PathModel> paths = JGitUtils.getFilesInPath(r, path, commit);
5fe7df 54
JM 55         // tree page links
2a7306 56         add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
JM 57                 WicketUtils.newPathParameter(repositoryName, objectId, path)));
58         add(new BookmarkablePageLink<Void>("headLink", TreePage.class,
59                 WicketUtils.newPathParameter(repositoryName, Constants.HEAD, path)));
60         add(new ExternalLink("zipLink", DownloadZipServlet.asLink(getRequest()
61                 .getRelativePathPrefixToContextRoot(), repositoryName, objectId, path))
62                 .setVisible(GitBlit.getBoolean(Keys.web.allowZipDownloads, true)));
608ece 63
c1c3c6 64         add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
5fe7df 65
JM 66         // breadcrumbs
f602a2 67         add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
JM 68         if (path != null && path.trim().length() > 0) {
28d6b2 69             // add .. parent path entry
JM 70             String parentPath = null;
71             if (path.lastIndexOf('/') > -1) {
72                 parentPath = path.substring(0, path.lastIndexOf('/'));
73             }
f08c1c 74             PathModel model = new PathModel("..", parentPath, 0, FileMode.TREE.getBits(), objectId);
28d6b2 75             model.isParentPath = true;
JM 76             paths.add(0, model);
5fe7df 77         }
JM 78
79         final ByteFormat byteFormat = new ByteFormat();
155bf7 80
2179fb 81         final String baseUrl = WicketUtils.getGitblitURL(getRequest());
JM 82
155bf7 83         // changed paths list
5fe7df 84         ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
JM 85         DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
86             private static final long serialVersionUID = 1L;
2a7306 87             int counter;
5fe7df 88
JM 89             public void populateItem(final Item<PathModel> item) {
90                 PathModel entry = item.getModelObject();
91                 item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
92                 if (entry.isParentPath) {
93                     // parent .. path
1e8390 94                     item.add(WicketUtils.newBlankImage("pathIcon"));
fc8426 95                     item.add(new Label("pathSize", ""));
2a7306 96                     item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
a2709d 97                             WicketUtils
JM 98                                     .newPathParameter(repositoryName, entry.commitId, entry.path)));
1a3fc5 99                     item.add(new Label("pathLinks", ""));
5fe7df 100                 } else {
JM 101                     if (entry.isTree()) {
102                         // folder/tree link
1e8390 103                         item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
fc8426 104                         item.add(new Label("pathSize", ""));
2a7306 105                         item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
a2709d 106                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
JM 107                                         entry.path)));
155bf7 108
1a3fc5 109                         // links
JM 110                         Fragment links = new Fragment("pathLinks", "treeLinks", this);
2a7306 111                         links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
JM 112                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
113                                         entry.path)));
114                         links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
115                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
116                                         entry.path)));
2179fb 117                         links.add(new ExternalLink("zip", DownloadZipServlet.asLink(baseUrl,
JM 118                                 repositoryName, objectId, entry.path)).setVisible(GitBlit
119                                 .getBoolean(Keys.web.allowZipDownloads, true)));
1a3fc5 120                         item.add(links);
5fe7df 121                     } else {
JM 122                         // blob link
c1c3c6 123                         item.add(WicketUtils.getFileImage("pathIcon", entry.name));
5fe7df 124                         item.add(new Label("pathSize", byteFormat.format(entry.size)));
2a7306 125                         item.add(new LinkPanel("pathName", "list", entry.name, BlobPage.class,
a2709d 126                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
JM 127                                         entry.path)));
155bf7 128
1a3fc5 129                         // links
JM 130                         Fragment links = new Fragment("pathLinks", "blobLinks", this);
2a7306 131                         links.add(new BookmarkablePageLink<Void>("view", BlobPage.class,
JM 132                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
133                                         entry.path)));
134                         links.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils
135                                 .newPathParameter(repositoryName, entry.commitId, entry.path)));
716745 136                         links.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
JM 137                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
138                                         entry.path)));
2a7306 139                         links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
JM 140                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
141                                         entry.path)));
1a3fc5 142                         item.add(links);
5fe7df 143                     }
JM 144                 }
1a3fc5 145                 WicketUtils.setAlternatingBackground(item, counter);
5fe7df 146                 counter++;
JM 147             }
148         };
149         add(pathsView);
150     }
155bf7 151
cebf45 152     @Override
JM 153     protected String getPageName() {
1e47ab 154         return getString("gb.tree");
cebf45 155     }
5fe7df 156 }