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.ArrayList;
|
|
19 |
import java.util.Collections;
|
|
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import org.apache.wicket.markup.html.basic.Label;
|
|
23 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
1fa5e8
|
24 |
import org.apache.wicket.markup.html.panel.Fragment;
|
698678
|
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;
|
|
28 |
import org.apache.wicket.model.StringResourceModel;
|
|
29 |
import org.eclipse.jgit.lib.Constants;
|
|
30 |
import org.eclipse.jgit.lib.Repository;
|
|
31 |
|
1f9dae
|
32 |
import com.gitblit.models.RefModel;
|
JM |
33 |
import com.gitblit.models.RepositoryModel;
|
698678
|
34 |
import com.gitblit.utils.JGitUtils;
|
87cc1e
|
35 |
import com.gitblit.utils.StringUtils;
|
698678
|
36 |
import com.gitblit.wicket.WicketUtils;
|
JM |
37 |
import com.gitblit.wicket.pages.BranchesPage;
|
|
38 |
import com.gitblit.wicket.pages.LogPage;
|
1fa5e8
|
39 |
import com.gitblit.wicket.pages.MetricsPage;
|
698678
|
40 |
import com.gitblit.wicket.pages.SummaryPage;
|
JM |
41 |
import com.gitblit.wicket.pages.TreePage;
|
|
42 |
|
bc10f9
|
43 |
public class BranchesPanel extends BasePanel {
|
698678
|
44 |
|
JM |
45 |
private static final long serialVersionUID = 1L;
|
1fa5e8
|
46 |
|
JM |
47 |
private final boolean hasBranches;
|
698678
|
48 |
|
2a7306
|
49 |
public BranchesPanel(String wicketId, final RepositoryModel model, Repository r,
|
JM |
50 |
final int maxCount) {
|
698678
|
51 |
super(wicketId);
|
JM |
52 |
|
|
53 |
// branches
|
|
54 |
List<RefModel> branches = new ArrayList<RefModel>();
|
5cc4f2
|
55 |
branches.addAll(JGitUtils.getLocalBranches(r, false, maxCount));
|
cf9550
|
56 |
if (model.showRemoteBranches) {
|
5cc4f2
|
57 |
branches.addAll(JGitUtils.getRemoteBranches(r, false, maxCount));
|
cf9550
|
58 |
}
|
698678
|
59 |
Collections.sort(branches);
|
JM |
60 |
Collections.reverse(branches);
|
|
61 |
if (maxCount > 0 && branches.size() > maxCount) {
|
|
62 |
branches = new ArrayList<RefModel>(branches.subList(0, maxCount));
|
|
63 |
}
|
|
64 |
|
|
65 |
if (maxCount > 0) {
|
|
66 |
// summary page
|
|
67 |
// show branches page link
|
2a7306
|
68 |
add(new LinkPanel("branches", "title", new StringResourceModel("gb.branches", this,
|
JM |
69 |
null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
|
698678
|
70 |
} else {
|
JM |
71 |
// branches page
|
|
72 |
// show repository summary page link
|
2a7306
|
73 |
add(new LinkPanel("branches", "title", model.name, SummaryPage.class,
|
JM |
74 |
WicketUtils.newRepositoryParameter(model.name)));
|
698678
|
75 |
}
|
155bf7
|
76 |
|
698678
|
77 |
ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
|
JM |
78 |
DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
|
|
79 |
private static final long serialVersionUID = 1L;
|
2a7306
|
80 |
int counter;
|
698678
|
81 |
|
JM |
82 |
public void populateItem(final Item<RefModel> item) {
|
|
83 |
final RefModel entry = item.getModelObject();
|
|
84 |
|
bc10f9
|
85 |
item.add(WicketUtils.createDateLabel("branchDate", entry.getDate(), getTimeZone()));
|
698678
|
86 |
|
2a7306
|
87 |
item.add(new LinkPanel("branchName", "list name", StringUtils.trimString(
|
JM |
88 |
entry.displayName, 28), LogPage.class, WicketUtils.newObjectParameter(
|
|
89 |
model.name, entry.getName())));
|
155bf7
|
90 |
|
698678
|
91 |
// only show branch type on the branches page
|
JM |
92 |
boolean remote = entry.getName().startsWith(Constants.R_REMOTES);
|
2a7306
|
93 |
item.add(new Label("branchType", remote ? getString("gb.remote")
|
JM |
94 |
: getString("gb.local")).setVisible(maxCount <= 0));
|
155bf7
|
95 |
|
1fa5e8
|
96 |
if (maxCount <= 0) {
|
JM |
97 |
Fragment fragment = new Fragment("branchLinks", "branchPageLinks", this);
|
|
98 |
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
|
|
99 |
.newObjectParameter(model.name, entry.getName())));
|
|
100 |
fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
|
101 |
.newObjectParameter(model.name, entry.getName())));
|
|
102 |
fragment.add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
|
|
103 |
WicketUtils.newObjectParameter(model.name, entry.getName())));
|
|
104 |
item.add(fragment);
|
|
105 |
} else {
|
|
106 |
Fragment fragment = new Fragment("branchLinks", "branchPanelLinks", this);
|
|
107 |
fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class, WicketUtils
|
|
108 |
.newObjectParameter(model.name, entry.getName())));
|
|
109 |
fragment.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
|
|
110 |
.newObjectParameter(model.name, entry.getName())));
|
|
111 |
item.add(fragment);
|
|
112 |
}
|
698678
|
113 |
WicketUtils.setAlternatingBackground(item, counter);
|
JM |
114 |
counter++;
|
|
115 |
}
|
|
116 |
};
|
|
117 |
add(branchesView);
|
|
118 |
if (branches.size() < maxCount || maxCount <= 0) {
|
|
119 |
add(new Label("allBranches", "").setVisible(false));
|
|
120 |
} else {
|
2a7306
|
121 |
add(new LinkPanel("allBranches", "link", new StringResourceModel("gb.allBranches",
|
JM |
122 |
this, null), BranchesPage.class, WicketUtils.newRepositoryParameter(model.name)));
|
698678
|
123 |
}
|
1fa5e8
|
124 |
// We always have 1 branch
|
JM |
125 |
hasBranches = branches.size() > 1;
|
|
126 |
}
|
|
127 |
|
|
128 |
public BranchesPanel hideIfEmpty() {
|
|
129 |
setVisible(hasBranches);
|
|
130 |
return this;
|
698678
|
131 |
}
|
JM |
132 |
}
|