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 |
*/
|
698678
|
16 |
package com.gitblit.wicket.panels;
|
JM |
17 |
|
|
18 |
import java.util.List;
|
|
19 |
|
|
20 |
import org.apache.wicket.markup.html.basic.Label;
|
|
21 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
98ce17
|
22 |
import org.apache.wicket.markup.html.panel.Fragment;
|
698678
|
23 |
import org.apache.wicket.markup.repeater.Item;
|
JM |
24 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
25 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
26 |
import org.apache.wicket.model.StringResourceModel;
|
4ab184
|
27 |
import org.eclipse.jgit.lib.Constants;
|
698678
|
28 |
import org.eclipse.jgit.lib.Repository;
|
JM |
29 |
|
1f9dae
|
30 |
import com.gitblit.models.RefModel;
|
698678
|
31 |
import com.gitblit.utils.JGitUtils;
|
87cc1e
|
32 |
import com.gitblit.utils.StringUtils;
|
698678
|
33 |
import com.gitblit.wicket.WicketUtils;
|
4ab184
|
34 |
import com.gitblit.wicket.pages.BlobPage;
|
698678
|
35 |
import com.gitblit.wicket.pages.CommitPage;
|
JM |
36 |
import com.gitblit.wicket.pages.LogPage;
|
4ab184
|
37 |
import com.gitblit.wicket.pages.RawPage;
|
JM |
38 |
import com.gitblit.wicket.pages.RepositoryPage;
|
698678
|
39 |
import com.gitblit.wicket.pages.TagPage;
|
JM |
40 |
import com.gitblit.wicket.pages.TagsPage;
|
4ab184
|
41 |
import com.gitblit.wicket.pages.TreePage;
|
698678
|
42 |
|
bc10f9
|
43 |
public class TagsPanel extends BasePanel {
|
698678
|
44 |
|
JM |
45 |
private static final long serialVersionUID = 1L;
|
008322
|
46 |
|
1fa5e8
|
47 |
private final boolean hasTags;
|
698678
|
48 |
|
JM |
49 |
public TagsPanel(String wicketId, final String repositoryName, Repository r, final int maxCount) {
|
|
50 |
super(wicketId);
|
|
51 |
|
|
52 |
// header
|
5cc4f2
|
53 |
List<RefModel> tags = JGitUtils.getTags(r, false, maxCount);
|
698678
|
54 |
if (maxCount > 0) {
|
JM |
55 |
// summary page
|
|
56 |
// show tags page link
|
2a7306
|
57 |
add(new LinkPanel("header", "title", new StringResourceModel("gb.tags", this, null),
|
JM |
58 |
TagsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
698678
|
59 |
} else {
|
JM |
60 |
// tags page
|
a45caa
|
61 |
add(new Label("header", new StringResourceModel("gb.tags", this, null)));
|
698678
|
62 |
}
|
JM |
63 |
|
|
64 |
ListDataProvider<RefModel> tagsDp = new ListDataProvider<RefModel>(tags);
|
|
65 |
DataView<RefModel> tagView = new DataView<RefModel>("tag", tagsDp) {
|
|
66 |
private static final long serialVersionUID = 1L;
|
2a7306
|
67 |
int counter;
|
698678
|
68 |
|
JM |
69 |
public void populateItem(final Item<RefModel> item) {
|
|
70 |
RefModel entry = item.getModelObject();
|
|
71 |
|
9adf62
|
72 |
item.add(WicketUtils.createDateLabel("tagDate", entry.getDate(), getTimeZone(), getTimeUtils()));
|
698678
|
73 |
|
4ab184
|
74 |
Class<? extends RepositoryPage> linkClass;
|
JM |
75 |
switch (entry.getReferencedObjectType()) {
|
|
76 |
case Constants.OBJ_BLOB:
|
|
77 |
linkClass = BlobPage.class;
|
|
78 |
break;
|
|
79 |
case Constants.OBJ_TREE:
|
|
80 |
linkClass = TreePage.class;
|
|
81 |
break;
|
|
82 |
case Constants.OBJ_COMMIT:
|
|
83 |
default:
|
|
84 |
linkClass = CommitPage.class;
|
|
85 |
break;
|
f5d0ad
|
86 |
}
|
4ab184
|
87 |
item.add(new LinkPanel("tagName", "list name", entry.displayName, linkClass,
|
JM |
88 |
WicketUtils.newObjectParameter(repositoryName, entry
|
|
89 |
.getReferencedObjectId().getName())));
|
88598b
|
90 |
|
85c2e6
|
91 |
// workaround for RevTag returning a lengthy shortlog. :(
|
a45caa
|
92 |
String message = StringUtils.trimString(entry.getShortMessage(),
|
JM |
93 |
com.gitblit.Constants.LEN_SHORTLOG);
|
85c2e6
|
94 |
|
4ab184
|
95 |
if (linkClass.equals(BlobPage.class)) {
|
JM |
96 |
// Blob Tag Object
|
|
97 |
item.add(WicketUtils.newImage("tagIcon", "file_16x16.png"));
|
2a7306
|
98 |
item.add(new LinkPanel("tagDescription", "list", message, TagPage.class,
|
JM |
99 |
WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()
|
|
100 |
.getName())));
|
4ab184
|
101 |
|
JM |
102 |
Fragment fragment = new Fragment("tagLinks", "blobLinks", this);
|
|
103 |
fragment.add(new BookmarkablePageLink<Void>("tag", TagPage.class, WicketUtils
|
2a7306
|
104 |
.newObjectParameter(repositoryName, entry.getObjectId().getName()))
|
JM |
105 |
.setEnabled(entry.isAnnotatedTag()));
|
4ab184
|
106 |
|
JM |
107 |
fragment.add(new BookmarkablePageLink<Void>("blob", linkClass, WicketUtils
|
|
108 |
.newObjectParameter(repositoryName, entry.getReferencedObjectId()
|
2a7306
|
109 |
.getName())));
|
4ab184
|
110 |
|
JM |
111 |
fragment.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils
|
|
112 |
.newObjectParameter(repositoryName, entry.getReferencedObjectId()
|
|
113 |
.getName())));
|
98ce17
|
114 |
item.add(fragment);
|
698678
|
115 |
} else {
|
4ab184
|
116 |
// TODO Tree Tag Object
|
JM |
117 |
// Standard Tag Object
|
|
118 |
if (entry.isAnnotatedTag()) {
|
|
119 |
item.add(WicketUtils.newImage("tagIcon", "tag_16x16.png"));
|
|
120 |
item.add(new LinkPanel("tagDescription", "list", message, TagPage.class,
|
|
121 |
WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()
|
|
122 |
.getName())));
|
|
123 |
|
|
124 |
Fragment fragment = new Fragment("tagLinks", "annotatedLinks", this);
|
|
125 |
fragment.add(new BookmarkablePageLink<Void>("tag", TagPage.class,
|
|
126 |
WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()
|
|
127 |
.getName())).setEnabled(entry.isAnnotatedTag()));
|
|
128 |
|
|
129 |
fragment.add(new BookmarkablePageLink<Void>("commit", linkClass,
|
|
130 |
WicketUtils.newObjectParameter(repositoryName, entry
|
|
131 |
.getReferencedObjectId().getName())));
|
|
132 |
|
|
133 |
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class,
|
|
134 |
WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
135 |
item.add(fragment);
|
|
136 |
} else {
|
|
137 |
item.add(WicketUtils.newBlankImage("tagIcon"));
|
|
138 |
item.add(new LinkPanel("tagDescription", "list", message, CommitPage.class,
|
|
139 |
WicketUtils.newObjectParameter(repositoryName, entry.getObjectId()
|
|
140 |
.getName())));
|
|
141 |
Fragment fragment = new Fragment("tagLinks", "lightweightLinks", this);
|
|
142 |
fragment.add(new BookmarkablePageLink<Void>("commit", CommitPage.class,
|
|
143 |
WicketUtils.newObjectParameter(repositoryName, entry
|
|
144 |
.getReferencedObjectId().getName())));
|
|
145 |
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class,
|
|
146 |
WicketUtils.newObjectParameter(repositoryName, entry.getName())));
|
|
147 |
item.add(fragment);
|
|
148 |
}
|
698678
|
149 |
}
|
JM |
150 |
|
|
151 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
152 |
counter++;
|
|
153 |
}
|
|
154 |
};
|
|
155 |
add(tagView);
|
|
156 |
if (tags.size() < maxCount || maxCount <= 0) {
|
|
157 |
add(new Label("allTags", "").setVisible(false));
|
|
158 |
} else {
|
2a7306
|
159 |
add(new LinkPanel("allTags", "link", new StringResourceModel("gb.allTags", this, null),
|
JM |
160 |
TagsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
698678
|
161 |
}
|
008322
|
162 |
|
1fa5e8
|
163 |
hasTags = tags.size() > 0;
|
JM |
164 |
}
|
008322
|
165 |
|
1fa5e8
|
166 |
public TagsPanel hideIfEmpty() {
|
JM |
167 |
setVisible(hasTags);
|
|
168 |
return this;
|
698678
|
169 |
}
|
JM |
170 |
}
|