use of org.apache.wicket.markup.repeater.data.DataView 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);
}
use of org.apache.wicket.markup.repeater.data.DataView in project gitblit by gitblit.
the class MyTicketsPage method buildPager.
protected void buildPager(final String query, final String milestone, final String[] states, final String assignedTo, final String sort, final boolean desc, final String repositoryId, final int page, int pageSize, int count, int total) {
boolean showNav = total > (2 * pageSize);
boolean allowPrev = page > 1;
boolean allowNext = (pageSize * (page - 1) + count) < total;
add(new BookmarkablePageLink<Void>("prevLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page - 1)).setEnabled(allowPrev).setVisible(showNav));
add(new BookmarkablePageLink<Void>("nextLink", MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, page + 1)).setEnabled(allowNext).setVisible(showNav));
if (total <= pageSize) {
add(new Label("pageLink").setVisible(false));
return;
}
// determine page numbers to display
int pages = count == 0 ? 0 : ((total / pageSize) + (total % pageSize == 0 ? 0 : 1));
// preferred number of pagelinks
int segments = 5;
if (pages < segments) {
// not enough data for preferred number of page links
segments = pages;
}
int minpage = Math.min(Math.max(1, page - 2), pages - (segments - 1));
int maxpage = Math.min(pages, minpage + (segments - 1));
List<Integer> sequence = new ArrayList<Integer>();
for (int i = minpage; i <= maxpage; i++) {
sequence.add(i);
}
ListDataProvider<Integer> pagesDp = new ListDataProvider<Integer>(sequence);
DataView<Integer> pagesView = new DataView<Integer>("pageLink", pagesDp) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(final Item<Integer> item) {
final Integer i = item.getModelObject();
LinkPanel link = new LinkPanel("page", null, "" + i, MyTicketsPage.class, queryParameters(query, milestone, states, assignedTo, sort, desc, repositoryId, i));
link.setRenderBodyOnly(true);
if (i == page) {
WicketUtils.setCssClass(item, "active");
}
item.add(link);
}
};
add(pagesView);
}
Aggregations