commit | author | age
|
5fe7df
|
1 |
package com.gitblit.wicket.panels;
|
JM |
2 |
|
|
3 |
import java.io.Serializable;
|
|
4 |
import java.util.ArrayList;
|
|
5 |
import java.util.List;
|
|
6 |
|
|
7 |
import org.apache.wicket.markup.html.basic.Label;
|
|
8 |
import org.apache.wicket.markup.html.panel.Panel;
|
|
9 |
import org.apache.wicket.markup.repeater.Item;
|
|
10 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
11 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
12 |
|
|
13 |
import com.gitblit.wicket.LinkPanel;
|
698678
|
14 |
import com.gitblit.wicket.WicketUtils;
|
5fe7df
|
15 |
import com.gitblit.wicket.pages.TreePage;
|
JM |
16 |
|
|
17 |
public class PathBreadcrumbsPanel extends Panel {
|
|
18 |
|
|
19 |
private static final long serialVersionUID = 1L;
|
|
20 |
|
|
21 |
private final String ROOT = "--ROOT--";
|
|
22 |
|
1a3fc5
|
23 |
public PathBreadcrumbsPanel(String id, final String repositoryName, String pathName, final String objectId) {
|
5fe7df
|
24 |
super(id);
|
JM |
25 |
List<BreadCrumb> crumbs = new ArrayList<BreadCrumb>();
|
|
26 |
crumbs.add(new BreadCrumb("[" + repositoryName + "]", ROOT, false));
|
|
27 |
|
fc8426
|
28 |
if (pathName != null && pathName.length() > 0) {
|
JM |
29 |
String[] paths = pathName.split("/");
|
|
30 |
StringBuilder sb = new StringBuilder();
|
|
31 |
|
|
32 |
for (int i = 0; i < paths.length; i++) {
|
|
33 |
String path = paths[i];
|
|
34 |
sb.append(path);
|
|
35 |
crumbs.add(new BreadCrumb(path, sb.toString(), (i == (paths.length - 1))));
|
|
36 |
sb.append("/");
|
|
37 |
}
|
5fe7df
|
38 |
}
|
JM |
39 |
|
|
40 |
ListDataProvider<BreadCrumb> crumbsDp = new ListDataProvider<BreadCrumb>(crumbs);
|
|
41 |
DataView<BreadCrumb> pathsView = new DataView<BreadCrumb>("path", crumbsDp) {
|
|
42 |
private static final long serialVersionUID = 1L;
|
|
43 |
|
|
44 |
public void populateItem(final Item<BreadCrumb> item) {
|
|
45 |
final BreadCrumb entry = item.getModelObject();
|
|
46 |
String path = entry.getPath();
|
1a3fc5
|
47 |
if (entry.isLeaf) {
|
JM |
48 |
item.add(new Label("pathLink", entry.name));
|
|
49 |
item.add(new Label("pathSeparator", "").setVisible(false));
|
|
50 |
} else {
|
|
51 |
item.add(new LinkPanel("pathLink", null, entry.name, TreePage.class, WicketUtils.newPathParameter(repositoryName, objectId, path)));
|
|
52 |
item.add(new Label("pathSeparator", "/"));
|
5fe7df
|
53 |
}
|
JM |
54 |
}
|
|
55 |
};
|
|
56 |
add(pathsView);
|
|
57 |
}
|
|
58 |
|
|
59 |
private class BreadCrumb implements Serializable {
|
fc8426
|
60 |
|
5fe7df
|
61 |
private static final long serialVersionUID = 1L;
|
fc8426
|
62 |
|
5fe7df
|
63 |
final String name;
|
JM |
64 |
final String path;
|
|
65 |
final boolean isLeaf;
|
fc8426
|
66 |
|
5fe7df
|
67 |
BreadCrumb(String name, String path, boolean isLeaf) {
|
JM |
68 |
this.name = name;
|
|
69 |
this.path = path;
|
|
70 |
this.isLeaf = isLeaf;
|
|
71 |
}
|
|
72 |
|
|
73 |
String getPath() {
|
|
74 |
if (path.equals(ROOT)) {
|
|
75 |
return null;
|
|
76 |
}
|
|
77 |
return path;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
} |