use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class RepositoryUrlPanel method createPrimaryUrlPanel.
protected Fragment createPrimaryUrlPanel(String wicketId, final RepositoryModel repository, List<RepositoryUrl> repositoryUrls) {
Fragment urlPanel = new Fragment(wicketId, "repositoryUrlFragment", this);
urlPanel.setRenderBodyOnly(true);
if (repositoryUrls.size() == 1) {
//
// Single repository url, no dropdown menu
//
urlPanel.add(new Label("menu").setVisible(false));
} else {
//
// Multiple repository urls, show url drop down menu
//
ListDataProvider<RepositoryUrl> urlsDp = new ListDataProvider<RepositoryUrl>(repositoryUrls);
DataView<RepositoryUrl> repoUrlMenuItems = new DataView<RepositoryUrl>("repoUrls", urlsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<RepositoryUrl> item) {
RepositoryUrl repoUrl = item.getModelObject();
// repository url
Fragment fragment = new Fragment("repoUrl", "actionFragment", this);
Component content = new Label("content", repoUrl.url).setRenderBodyOnly(true);
WicketUtils.setCssClass(content, "commandMenuItem");
fragment.add(content);
item.add(fragment);
Label permissionLabel = new Label("permission", repoUrl.hasPermission() ? repoUrl.permission.toString() : externalPermission);
WicketUtils.setPermissionClass(permissionLabel, repoUrl.permission);
String tooltip = getProtocolPermissionDescription(repository, repoUrl);
WicketUtils.setHtmlTooltip(permissionLabel, tooltip);
fragment.add(permissionLabel);
fragment.add(createCopyFragment(repoUrl.url));
}
};
Fragment urlMenuFragment = new Fragment("menu", "urlProtocolMenuFragment", this);
urlMenuFragment.setRenderBodyOnly(true);
urlMenuFragment.add(new Label("menuText", getString("gb.url")));
urlMenuFragment.add(repoUrlMenuItems);
urlPanel.add(urlMenuFragment);
}
// access restriction icon and tooltip
if (repository.isMirror) {
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "mirror_16x16.png", getString("gb.isMirror")));
} else if (app().services().isServingRepositories()) {
switch(repository.accessRestriction) {
case NONE:
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
break;
case PUSH:
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png", getAccessRestrictions().get(repository.accessRestriction)));
break;
case CLONE:
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png", getAccessRestrictions().get(repository.accessRestriction)));
break;
case VIEW:
urlPanel.add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png", getAccessRestrictions().get(repository.accessRestriction)));
break;
default:
if (repositoryUrls.size() == 1) {
// force left end cap to have some width
urlPanel.add(WicketUtils.newBlankIcon("accessRestrictionIcon"));
} else {
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
}
}
} else {
if (repositoryUrls.size() == 1) {
// force left end cap to have some width
urlPanel.add(WicketUtils.newBlankIcon("accessRestrictionIcon"));
} else {
urlPanel.add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
}
}
urlPanel.add(new Label("primaryUrl", primaryUrl.url).setRenderBodyOnly(true));
Label permissionLabel = new Label("primaryUrlPermission", primaryUrl.hasPermission() ? primaryUrl.permission.toString() : externalPermission);
String tooltip = getProtocolPermissionDescription(repository, primaryUrl);
WicketUtils.setHtmlTooltip(permissionLabel, tooltip);
urlPanel.add(permissionLabel);
urlPanel.add(createCopyFragment(primaryUrl.url));
return urlPanel;
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class SshKeysPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
setOutputMarkupId(true);
final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<SshKey> item) {
final SshKey key = item.getModelObject();
item.add(new Label("comment", key.getComment()));
item.add(new Label("fingerprint", key.getFingerprint()));
item.add(new Label("permission", key.getPermission().toString()));
item.add(new Label("algorithm", key.getAlgorithm()));
AjaxLink<Void> delete = new AjaxLink<Void>("delete") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (app().keys().removeKey(user.username, key)) {
// reset the keys list
keys.clear();
keys.addAll(app().keys().getKeys(user.username));
// update the panel
target.addComponent(SshKeysPanel.this);
}
}
};
if (!canWriteKeys) {
delete.setVisibilityAllowed(false);
}
item.add(delete);
}
};
add(keysView);
Form<Void> addKeyForm = new Form<Void>("addKeyForm");
final IModel<String> keyData = Model.of("");
addKeyForm.add(new TextAreaOption("addKeyData", getString("gb.key"), null, "span5", keyData));
final IModel<AccessPermission> keyPermission = Model.of(AccessPermission.PUSH);
addKeyForm.add(new ChoiceOption<AccessPermission>("addKeyPermission", getString("gb.permission"), getString("gb.sshKeyPermissionDescription"), keyPermission, Arrays.asList(AccessPermission.SSHPERMISSIONS)));
final IModel<String> keyComment = Model.of("");
addKeyForm.add(new TextOption("addKeyComment", getString("gb.sshKeyComment"), getString("gb.sshKeyCommentDescription"), "span5", keyComment));
addKeyForm.add(new AjaxButton("addKeyButton") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
UserModel user = GitBlitWebSession.get().getUser();
String data = keyData.getObject();
if (StringUtils.isEmpty(data)) {
// do not submit empty key
return;
}
SshKey key = new SshKey(data);
try {
key.getPublicKey();
} catch (Exception e) {
// failed to parse the key
return;
}
AccessPermission permission = keyPermission.getObject();
key.setPermission(permission);
String comment = keyComment.getObject();
if (!StringUtils.isEmpty(comment)) {
key.setComment(comment);
}
if (app().keys().addKey(user.username, key)) {
// reset add key fields
keyData.setObject("");
keyPermission.setObject(AccessPermission.PUSH);
keyComment.setObject("");
// reset the keys list
keys.clear();
keys.addAll(app().keys().getKeys(user.username));
// update the panel
target.addComponent(SshKeysPanel.this);
}
}
});
if (!canWriteKeys) {
addKeyForm.setVisibilityAllowed(false);
}
add(addKeyForm);
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class TicketPage method createPatchsetPanel.
protected Fragment createPatchsetPanel(String wicketId, RepositoryModel repository, UserModel user) {
final Patchset currentPatchset = ticket.getCurrentPatchset();
List<Patchset> patchsets = new ArrayList<Patchset>(ticket.getPatchsetRevisions(currentPatchset.number));
patchsets.remove(currentPatchset);
Collections.reverse(patchsets);
Fragment panel = new Fragment(wicketId, "collapsiblePatchsetFragment", this);
// patchset header
String ps = "<b>" + currentPatchset.number + "</b>";
if (currentPatchset.rev == 1) {
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetN"), ps)).setEscapeModelStrings(false));
} else {
String rev = "<b>" + currentPatchset.rev + "</b>";
panel.add(new Label("uploadedWhat", MessageFormat.format(getString("gb.uploadedPatchsetNRevisionN"), ps, rev)).setEscapeModelStrings(false));
}
panel.add(new LinkPanel("patchId", null, "rev " + currentPatchset.rev, CommitPage.class, WicketUtils.newObjectParameter(repositoryName, currentPatchset.tip), true));
// compare menu
panel.add(new LinkPanel("compareMergeBase", null, getString("gb.compareToMergeBase"), ComparePage.class, WicketUtils.newRangeParameter(repositoryName, currentPatchset.base, currentPatchset.tip), true));
ListDataProvider<Patchset> compareMenuDp = new ListDataProvider<Patchset>(patchsets);
DataView<Patchset> compareMenu = new DataView<Patchset>("comparePatch", compareMenuDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Patchset> item) {
Patchset patchset = item.getModelObject();
LinkPanel link = new LinkPanel("compareLink", null, MessageFormat.format(getString("gb.compareToN"), patchset.number + "-" + patchset.rev), ComparePage.class, WicketUtils.newRangeParameter(getRepositoryModel().name, patchset.tip, currentPatchset.tip), true);
item.add(link);
}
};
panel.add(compareMenu);
// reviews
List<Change> reviews = ticket.getReviews(currentPatchset);
ListDataProvider<Change> reviewsDp = new ListDataProvider<Change>(reviews);
DataView<Change> reviewsView = new DataView<Change>("reviews", reviewsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Change> item) {
Change change = item.getModelObject();
final String username = change.author;
UserModel user = app().users().getUserModel(username);
if (user == null) {
item.add(new Label("reviewer", username));
} else {
item.add(new LinkPanel("reviewer", null, user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(username)));
}
// indicate review score
Review review = change.review;
Label scoreLabel = new Label("score");
String scoreClass = getScoreClass(review.score);
String tooltip = getScoreDescription(review.score);
WicketUtils.setCssClass(scoreLabel, scoreClass);
if (!StringUtils.isEmpty(tooltip)) {
WicketUtils.setHtmlTooltip(scoreLabel, tooltip);
}
item.add(scoreLabel);
}
};
panel.add(reviewsView);
if (ticket.isOpen() && user.canReviewPatchset(repository) && app().tickets().isAcceptingTicketUpdates(repository)) {
// can only review open tickets
Review myReview = null;
for (Change change : ticket.getReviews(currentPatchset)) {
if (change.author.equals(user.username)) {
myReview = change.review;
}
}
// user can review, add review controls
Fragment reviewControls = new Fragment("reviewControls", "reviewControlsFragment", this);
// show "approve" button if no review OR not current score
if (user.canApprovePatchset(repository) && (myReview == null || Score.approved != myReview.score)) {
reviewControls.add(createReviewLink("approveLink", Score.approved));
} else {
reviewControls.add(new Label("approveLink").setVisible(false));
}
// show "looks good" button if no review OR not current score
if (myReview == null || Score.looks_good != myReview.score) {
reviewControls.add(createReviewLink("looksGoodLink", Score.looks_good));
} else {
reviewControls.add(new Label("looksGoodLink").setVisible(false));
}
// show "needs improvement" button if no review OR not current score
if (myReview == null || Score.needs_improvement != myReview.score) {
reviewControls.add(createReviewLink("needsImprovementLink", Score.needs_improvement));
} else {
reviewControls.add(new Label("needsImprovementLink").setVisible(false));
}
// show "veto" button if no review OR not current score
if (user.canVetoPatchset(repository) && (myReview == null || Score.vetoed != myReview.score)) {
reviewControls.add(createReviewLink("vetoLink", Score.vetoed));
} else {
reviewControls.add(new Label("vetoLink").setVisible(false));
}
panel.add(reviewControls);
} else {
// user can not review
panel.add(new Label("reviewControls").setVisible(false));
}
String insertions = MessageFormat.format("<span style=\"color:darkGreen;font-weight:bold;\">+{0}</span>", ticket.insertions);
String deletions = MessageFormat.format("<span style=\"color:darkRed;font-weight:bold;\">-{0}</span>", ticket.deletions);
panel.add(new Label("patchsetStat", MessageFormat.format(StringUtils.escapeForHtml(getString("gb.diffStat"), false), insertions, deletions)).setEscapeModelStrings(false));
// changed paths list
List<PathChangeModel> paths = JGitUtils.getFilesInRange(getRepository(), currentPatchset.base, currentPatchset.tip);
ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
private static final long serialVersionUID = 1L;
int counter;
@Override
public void populateItem(final Item<PathChangeModel> item) {
final PathChangeModel entry = item.getModelObject();
Label changeType = new Label("changeType", "");
WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
setChangeTypeTooltip(changeType, entry.changeType);
item.add(changeType);
boolean hasSubmodule = false;
String submodulePath = null;
if (entry.isTree()) {
// tree
item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path), true));
item.add(new Label("diffStat").setVisible(false));
} else if (entry.isSubmodule()) {
// submodule
String submoduleId = entry.objectId;
SubmoduleModel submodule = getSubmodule(entry.path);
submodulePath = submodule.gitblitPath;
hasSubmodule = submodule.hasSubmodule;
item.add(new LinkPanel("pathName", "list", entry.path + " @ " + getShortObjectId(submoduleId), TreePage.class, WicketUtils.newPathParameter(submodulePath, submoduleId, ""), true).setEnabled(hasSubmodule));
item.add(new Label("diffStat").setVisible(false));
} else {
// blob
String displayPath = entry.path;
String path = entry.path;
if (entry.isSymlink()) {
RevCommit commit = JGitUtils.getCommit(getRepository(), PatchsetCommand.getTicketBranch(ticket.number));
path = JGitUtils.getStringContent(getRepository(), commit.getTree(), path);
displayPath = entry.path + " -> " + path;
}
if (entry.changeType.equals(ChangeType.ADD)) {
// add show view
item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
} else if (entry.changeType.equals(ChangeType.DELETE)) {
// delete, show label
item.add(new Label("pathName", displayPath));
} else {
// mod, show diff
item.add(new LinkPanel("pathName", "list", displayPath, BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, path), true));
}
item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
}
// quick links
if (entry.isSubmodule()) {
// submodule
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD)));
item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils.newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
} else {
// tree or blob
item.add(setNewTarget(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils.newBlobDiffParameter(repositoryName, currentPatchset.base, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.ADD) && !entry.changeType.equals(ChangeType.DELETE)));
item.add(setNewTarget(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils.newPathParameter(repositoryName, currentPatchset.tip, entry.path))).setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
}
WicketUtils.setAlternatingBackground(item, counter);
counter++;
}
};
panel.add(pathsView);
addPtCheckoutInstructions(user, repository, panel);
addGitCheckoutInstructions(user, repository, panel);
return panel;
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class LuceneSearchPage method setup.
private void setup(PageParameters params) {
setupPage("", "");
// default values
ArrayList<String> repositories = new ArrayList<String>();
String query = "";
boolean allRepos = false;
int page = 1;
int pageSize = app().settings().getInteger(Keys.web.itemsPerPage, 50);
// display user-accessible selections
UserModel user = GitBlitWebSession.get().getUser();
List<String> availableRepositories = new ArrayList<String>();
for (RepositoryModel model : app().repositories().getRepositoryModels(user)) {
if (model.hasCommits && !ArrayUtils.isEmpty(model.indexedBranches)) {
availableRepositories.add(model.name);
}
}
if (params != null) {
String repository = WicketUtils.getRepositoryName(params);
if (!StringUtils.isEmpty(repository)) {
repositories.add(repository);
}
page = WicketUtils.getPage(params);
if (params.containsKey("repositories")) {
String value = params.getString("repositories", "");
List<String> list = StringUtils.getStringsFromValue(value);
repositories.addAll(list);
}
allRepos = params.getAsBoolean("allrepos", false);
if (allRepos) {
repositories.addAll(availableRepositories);
}
if (params.containsKey("query")) {
query = params.getString("query", "");
} else {
String value = WicketUtils.getSearchString(params);
String type = WicketUtils.getSearchType(params);
com.gitblit.Constants.SearchType searchType = com.gitblit.Constants.SearchType.forName(type);
if (!StringUtils.isEmpty(value)) {
if (searchType == SearchType.COMMIT) {
query = "type:" + searchType.name().toLowerCase() + " AND \"" + value + "\"";
} else {
query = searchType.name().toLowerCase() + ":\"" + value + "\"";
}
}
}
}
boolean luceneEnabled = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
if (luceneEnabled) {
if (availableRepositories.size() == 0) {
info(getString("gb.noIndexedRepositoriesWarning"));
}
} else {
error(getString("gb.luceneDisabled"));
}
// enforce user-accessible repository selections
Set<String> uniqueRepositories = new LinkedHashSet<String>();
for (String selectedRepository : repositories) {
if (availableRepositories.contains(selectedRepository)) {
uniqueRepositories.add(selectedRepository);
}
}
ArrayList<String> searchRepositories = new ArrayList<String>(uniqueRepositories);
// search form
final Model<String> queryModel = new Model<String>(query);
final Model<ArrayList<String>> repositoriesModel = new Model<ArrayList<String>>(searchRepositories);
final Model<Boolean> allreposModel = new Model<Boolean>(allRepos);
SessionlessForm<Void> form = new SessionlessForm<Void>("searchForm", getClass()) {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
String q = queryModel.getObject();
if (StringUtils.isEmpty(q)) {
error(getString("gb.undefinedQueryWarning"));
return;
}
if (repositoriesModel.getObject().size() == 0 && !allreposModel.getObject()) {
error(getString("gb.noSelectedRepositoriesWarning"));
return;
}
PageParameters params = new PageParameters();
params.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
params.put("query", queryModel.getObject());
params.put("allrepos", allreposModel.getObject());
LuceneSearchPage page = new LuceneSearchPage(params);
setResponsePage(page);
}
};
ListMultipleChoice<String> selections = new ListMultipleChoice<String>("repositories", repositoriesModel, availableRepositories, new StringChoiceRenderer());
selections.setMaxRows(8);
form.add(selections.setEnabled(luceneEnabled));
form.add(new TextField<String>("query", queryModel).setEnabled(luceneEnabled));
form.add(new CheckBox("allrepos", allreposModel));
form.add(new ExternalLink("querySyntax", LUCENE_QUERY_SYNTAX_LINK));
add(form.setEnabled(luceneEnabled));
// execute search
final List<SearchResult> results = new ArrayList<SearchResult>();
if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
results.addAll(app().repositories().search(query, page, pageSize, searchRepositories));
}
// results header
if (results.size() == 0) {
if (!ArrayUtils.isEmpty(searchRepositories) && !StringUtils.isEmpty(query)) {
add(new Label("resultsHeader", query).setRenderBodyOnly(true));
add(new Label("resultsCount", getString("gb.noHits")).setRenderBodyOnly(true));
} else {
add(new Label("resultsHeader").setVisible(false));
add(new Label("resultsCount").setVisible(false));
}
} else {
add(new Label("resultsHeader", query).setRenderBodyOnly(true));
add(new Label("resultsCount", MessageFormat.format(getString("gb.queryResults"), results.get(0).hitId, results.get(results.size() - 1).hitId, results.get(0).totalHits)).setRenderBodyOnly(true));
}
// search results view
ListDataProvider<SearchResult> resultsDp = new ListDataProvider<SearchResult>(results);
final DataView<SearchResult> resultsView = new DataView<SearchResult>("searchResults", resultsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<SearchResult> item) {
final SearchResult sr = item.getModelObject();
switch(sr.type) {
case commit:
{
Label icon = WicketUtils.newIcon("type", "icon-refresh");
WicketUtils.setHtmlTooltip(icon, "commit");
item.add(icon);
item.add(new LinkPanel("summary", null, sr.summary, CommitPage.class, WicketUtils.newObjectParameter(sr.repository, sr.commitId)));
// show tags
Fragment fragment = new Fragment("tags", "tagsPanel", LuceneSearchPage.this);
List<String> tags = sr.tags;
if (tags == null) {
tags = new ArrayList<String>();
}
ListDataProvider<String> tagsDp = new ListDataProvider<String>(tags);
final DataView<String> tagsView = new DataView<String>("tag", tagsDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<String> item) {
String tag = item.getModelObject();
Component c = new LinkPanel("tagLink", null, tag, TagPage.class, WicketUtils.newObjectParameter(sr.repository, Constants.R_TAGS + tag));
WicketUtils.setCssClass(c, "tagRef");
item.add(c);
}
};
fragment.add(tagsView);
item.add(fragment);
break;
}
case blob:
{
Label icon = WicketUtils.newIcon("type", "icon-file");
WicketUtils.setHtmlTooltip(icon, "blob");
item.add(icon);
item.add(new LinkPanel("summary", null, sr.path, BlobPage.class, WicketUtils.newPathParameter(sr.repository, sr.branch, sr.path)));
item.add(new Label("tags").setVisible(false));
break;
}
}
item.add(new Label("fragment", sr.fragment).setEscapeModelStrings(false).setVisible(!StringUtils.isEmpty(sr.fragment)));
item.add(new LinkPanel("repository", null, sr.repository, SummaryPage.class, WicketUtils.newRepositoryParameter(sr.repository)));
if (StringUtils.isEmpty(sr.branch)) {
item.add(new Label("branch", "null"));
} else {
item.add(new LinkPanel("branch", "branch", StringUtils.getRelativePath(Constants.R_HEADS, sr.branch), LogPage.class, WicketUtils.newObjectParameter(sr.repository, sr.branch)));
}
item.add(new Label("author", sr.author));
item.add(WicketUtils.createDatestampLabel("date", sr.date, getTimeZone(), getTimeUtils()));
}
};
add(resultsView.setVisible(results.size() > 0));
PageParameters pagerParams = new PageParameters();
pagerParams.put("repositories", StringUtils.flattenStrings(repositoriesModel.getObject()));
pagerParams.put("query", queryModel.getObject());
boolean showPager = false;
int totalPages = 0;
if (results.size() > 0) {
totalPages = (results.get(0).totalHits / pageSize) + (results.get(0).totalHits % pageSize > 0 ? 1 : 0);
showPager = results.get(0).totalHits > pageSize;
}
add(new PagerPanel("topPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
add(new PagerPanel("bottomPager", page, totalPages, LuceneSearchPage.class, pagerParams).setVisible(showPager));
}
use of org.apache.wicket.markup.repeater.data.ListDataProvider in project gitblit by gitblit.
the class ProjectsPage method setup.
private void setup(PageParameters params) {
setupPage("", "");
// check to see if we should display a login message
boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
add(new Label("projectsPanel"));
return;
}
List<ProjectModel> projects = getProjects(params);
Collections.sort(projects);
ListDataProvider<ProjectModel> dp = new ListDataProvider<ProjectModel>(projects);
DataView<ProjectModel> dataView = new DataView<ProjectModel>("project", dp) {
private static final long serialVersionUID = 1L;
int counter;
@Override
protected void onBeforeRender() {
super.onBeforeRender();
counter = 0;
}
@Override
public void populateItem(final Item<ProjectModel> item) {
final ProjectModel entry = item.getModelObject();
PageParameters pp = WicketUtils.newProjectParameter(entry.name);
item.add(new LinkPanel("projectTitle", "list", entry.getDisplayName(), ProjectPage.class, pp));
item.add(new LinkPanel("projectDescription", "list", entry.description, ProjectPage.class, pp));
item.add(new Label("repositoryCount", entry.repositories.size() + " " + (entry.repositories.size() == 1 ? getString("gb.repository") : getString("gb.repositories"))));
String lastChange;
if (entry.lastChange.getTime() == 0) {
lastChange = "--";
} else {
lastChange = getTimeUtils().timeAgo(entry.lastChange);
}
Label lastChangeLabel = new Label("projectLastChange", lastChange);
item.add(lastChangeLabel);
WicketUtils.setCssClass(lastChangeLabel, getTimeUtils().timeAgoCss(entry.lastChange));
WicketUtils.setAlternatingBackground(item, counter);
counter++;
}
};
add(dataView);
}
Aggregations