James Moger
2012-09-10 fabe060d3a435f116128851f828e35c2af5fde67
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;
eb870f 37 import com.gitblit.models.SubmoduleModel;
5fe7df 38 import com.gitblit.utils.ByteFormat;
JM 39 import com.gitblit.utils.JGitUtils;
40 import com.gitblit.wicket.WicketUtils;
c1c3c6 41 import com.gitblit.wicket.panels.CommitHeaderPanel;
1f9dae 42 import com.gitblit.wicket.panels.LinkPanel;
5fe7df 43 import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
JM 44
45 public class TreePage extends RepositoryPage {
46
47     public TreePage(PageParameters params) {
cebf45 48         super(params);
5fe7df 49
f602a2 50         final String path = WicketUtils.getPath(params);
5fe7df 51
JM 52         Repository r = getRepository();
bc9d4a 53         RevCommit commit = getCommit();
f602a2 54         List<PathModel> paths = JGitUtils.getFilesInPath(r, path, commit);
5fe7df 55
JM 56         // tree page links
2a7306 57         add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
JM 58                 WicketUtils.newPathParameter(repositoryName, objectId, path)));
59         add(new BookmarkablePageLink<Void>("headLink", TreePage.class,
60                 WicketUtils.newPathParameter(repositoryName, Constants.HEAD, path)));
61         add(new ExternalLink("zipLink", DownloadZipServlet.asLink(getRequest()
62                 .getRelativePathPrefixToContextRoot(), repositoryName, objectId, path))
63                 .setVisible(GitBlit.getBoolean(Keys.web.allowZipDownloads, true)));
608ece 64
c1c3c6 65         add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
5fe7df 66
JM 67         // breadcrumbs
f602a2 68         add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
JM 69         if (path != null && path.trim().length() > 0) {
28d6b2 70             // add .. parent path entry
JM 71             String parentPath = null;
72             if (path.lastIndexOf('/') > -1) {
73                 parentPath = path.substring(0, path.lastIndexOf('/'));
74             }
eb870f 75             PathModel model = new PathModel("..", parentPath, 0, FileMode.TREE.getBits(), null, objectId);
28d6b2 76             model.isParentPath = true;
JM 77             paths.add(0, model);
5fe7df 78         }
JM 79
80         final ByteFormat byteFormat = new ByteFormat();
155bf7 81
2179fb 82         final String baseUrl = WicketUtils.getGitblitURL(getRequest());
JM 83
155bf7 84         // changed paths list
5fe7df 85         ListDataProvider<PathModel> pathsDp = new ListDataProvider<PathModel>(paths);
JM 86         DataView<PathModel> pathsView = new DataView<PathModel>("changedPath", pathsDp) {
87             private static final long serialVersionUID = 1L;
2a7306 88             int counter;
5fe7df 89
JM 90             public void populateItem(final Item<PathModel> item) {
91                 PathModel entry = item.getModelObject();
92                 item.add(new Label("pathPermissions", JGitUtils.getPermissionsFromMode(entry.mode)));
93                 if (entry.isParentPath) {
94                     // parent .. path
1e8390 95                     item.add(WicketUtils.newBlankImage("pathIcon"));
fc8426 96                     item.add(new Label("pathSize", ""));
2a7306 97                     item.add(new LinkPanel("pathName", null, entry.name, TreePage.class,
a2709d 98                             WicketUtils
JM 99                                     .newPathParameter(repositoryName, entry.commitId, entry.path)));
1a3fc5 100                     item.add(new Label("pathLinks", ""));
5fe7df 101                 } else {
JM 102                     if (entry.isTree()) {
103                         // folder/tree link
1e8390 104                         item.add(WicketUtils.newImage("pathIcon", "folder_16x16.png"));
fc8426 105                         item.add(new Label("pathSize", ""));
2a7306 106                         item.add(new LinkPanel("pathName", "list", entry.name, TreePage.class,
a2709d 107                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
JM 108                                         entry.path)));
155bf7 109
1a3fc5 110                         // links
JM 111                         Fragment links = new Fragment("pathLinks", "treeLinks", this);
2a7306 112                         links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
JM 113                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
114                                         entry.path)));
115                         links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
116                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
117                                         entry.path)));
2179fb 118                         links.add(new ExternalLink("zip", DownloadZipServlet.asLink(baseUrl,
JM 119                                 repositoryName, objectId, entry.path)).setVisible(GitBlit
120                                 .getBoolean(Keys.web.allowZipDownloads, true)));
1a3fc5 121                         item.add(links);
eb870f 122                     } else if (entry.isSubmodule()) {
JM 123                         // submodule
124                         String submoduleId = entry.objectId;                        
125                         String submodulePath;
126                         boolean hasSubmodule = false;
127                         SubmoduleModel submodule = getSubmodule(entry.path);
128                         submodulePath = submodule.gitblitPath;
129                         hasSubmodule = submodule.hasSubmodule;
130                         
131                         item.add(WicketUtils.newImage("pathIcon", "git-orange-16x16.png"));
132                         item.add(new Label("pathSize", ""));
133                         item.add(new LinkPanel("pathName", "list", entry.name + " @ " + 
134                                 getShortObjectId(submoduleId), TreePage.class,
135                                 WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
136                         
137                         Fragment links = new Fragment("pathLinks", "submoduleLinks", this);
138                         links.add(new BookmarkablePageLink<Void>("view", SummaryPage.class,
139                                 WicketUtils.newRepositoryParameter(submodulePath)).setEnabled(hasSubmodule));
140                         links.add(new BookmarkablePageLink<Void>("tree", TreePage.class,
141                                 WicketUtils.newPathParameter(submodulePath, submoduleId,
142                                         "")).setEnabled(hasSubmodule));
143                         links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
144                                 WicketUtils.newPathParameter(submodulePath, submoduleId,
145                                         "")).setEnabled(hasSubmodule));
146                         links.add(new ExternalLink("zip", DownloadZipServlet.asLink(baseUrl,
147                                 submodulePath, submoduleId, "")).setVisible(GitBlit
148                                 .getBoolean(Keys.web.allowZipDownloads, true)).setEnabled(hasSubmodule));
149                         item.add(links);                        
5fe7df 150                     } else {
JM 151                         // blob link
c1c3c6 152                         item.add(WicketUtils.getFileImage("pathIcon", entry.name));
5fe7df 153                         item.add(new Label("pathSize", byteFormat.format(entry.size)));
2a7306 154                         item.add(new LinkPanel("pathName", "list", entry.name, BlobPage.class,
a2709d 155                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
JM 156                                         entry.path)));
155bf7 157
1a3fc5 158                         // links
JM 159                         Fragment links = new Fragment("pathLinks", "blobLinks", this);
2a7306 160                         links.add(new BookmarkablePageLink<Void>("view", BlobPage.class,
JM 161                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
162                                         entry.path)));
163                         links.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils
164                                 .newPathParameter(repositoryName, entry.commitId, entry.path)));
716745 165                         links.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
JM 166                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
167                                         entry.path)));
2a7306 168                         links.add(new BookmarkablePageLink<Void>("history", HistoryPage.class,
JM 169                                 WicketUtils.newPathParameter(repositoryName, entry.commitId,
170                                         entry.path)));
1a3fc5 171                         item.add(links);
5fe7df 172                     }
JM 173                 }
1a3fc5 174                 WicketUtils.setAlternatingBackground(item, counter);
5fe7df 175                 counter++;
JM 176             }
177         };
178         add(pathsView);
179     }
155bf7 180
cebf45 181     @Override
JM 182     protected String getPageName() {
1e47ab 183         return getString("gb.tree");
cebf45 184     }
5fe7df 185 }