{
final List<IColumn<TimesheetDO, String>> columns = new ArrayList<IColumn<TimesheetDO, String>>();
final CellItemListener<TimesheetDO> cellItemListener = new CellItemListener<TimesheetDO>() {
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId, final IModel<TimesheetDO> rowModel)
{
final TimesheetDO timesheet = rowModel.getObject();
final Serializable highlightedRowId;
if (page instanceof AbstractListPage< ? , ? , ? >) {
highlightedRowId = ((AbstractListPage< ? , ? , ? >) page).getHighlightedRowId();
} else {
highlightedRowId = null;
}
appendCssClasses(item, timesheet.getId(), highlightedRowId, timesheet.isDeleted());
}
};
if (page instanceof TimesheetMassUpdatePage) {
columns.add(new UserPropertyColumn<TimesheetDO>(page.getString("timesheet.user"), getSortable("user.fullname", sortable), "user",
cellItemListener).withUserFormatter(userFormatter));
} else {
// Show first column not for TimesheetMassUpdatePage!
if (isMassUpdateMode == true && page instanceof TimesheetListPage) {
final TimesheetListPage timesheetListPage = (TimesheetListPage) page;
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>("", null, "selected", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId,
final IModel<TimesheetDO> rowModel)
{
final TimesheetDO timesheet = rowModel.getObject();
final CheckBoxPanel checkBoxPanel = new CheckBoxPanel(componentId, timesheetListPage.new SelectItemModel(timesheet.getId()),
null);
item.add(checkBoxPanel);
cellItemListener.populateItem(item, componentId, rowModel);
addRowClick(item, isMassUpdateMode);
}
});
columns.add(new UserPropertyColumn<TimesheetDO>(page.getString("timesheet.user"), getSortable("user.fullname", sortable), "user",
cellItemListener).withUserFormatter(userFormatter));
} else {
columns.add(new UserPropertyColumn<TimesheetDO>(page.getString("timesheet.user"), getSortable("user.fullname", sortable), "user",
cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId,
final IModel<TimesheetDO> rowModel)
{
item.add(new ListSelectActionPanel(componentId, rowModel, TimesheetEditPage.class, rowModel.getObject().getId(), page,
getLabelString(rowModel)));
cellItemListener.populateItem(item, componentId, rowModel);
addRowClick(item);
}
}.withUserFormatter(userFormatter));
}
}
final SystemInfoCache systemInfoCache = SystemInfoCache.instance();
if (systemInfoCache.isCost2EntriesExists() == true) {
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(new Model<String>(page.getString("fibu.kunde")), getSortable(
"kost2.projekt.kunde.name", sortable), "kost2.projekt.kunde.name", cellItemListener));
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(new Model<String>(page.getString("fibu.projekt")), getSortable(
"kost2.projekt.name", sortable), "kost2.projekt.name", cellItemListener));
}
columns.add(new TaskPropertyColumn<TimesheetDO>(page.getString("task"), getSortable("task.title", sortable), "task", cellItemListener)
.withTaskTree(taskTree));
if (systemInfoCache.isCost2EntriesExists() == true) {
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("fibu.kost2"), getSortable("kost2.shortDisplayName",
sortable), "kost2.shortDisplayName", cellItemListener));
}
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("calendar.weekOfYearShortLabel"), getSortable(
"formattedWeekOfYear", sortable), "formattedWeekOfYear", cellItemListener));
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("calendar.dayOfWeekShortLabel"), getSortable("startTime",
sortable), "startTime", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId, final IModel<TimesheetDO> rowModel)
{
final TimesheetDO timesheet = rowModel.getObject();
final Label label = new Label(componentId, dateTimeFormatter.getFormattedDate(timesheet.getStartTime(),
DateFormats.getFormatString(DateFormatType.DAY_OF_WEEK_SHORT)));
cellItemListener.populateItem(item, componentId, rowModel);
item.add(label);
}
});
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("timePeriod"), getSortable("startTime", sortable),
"timePeriod", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId, final IModel<TimesheetDO> rowModel)
{
final TimesheetDO timesheet = rowModel.getObject();
final Label label = new Label(componentId, dateTimeFormatter.getFormattedTimePeriod(timesheet.getTimePeriod()));
label.setEscapeModelStrings(false);
cellItemListener.populateItem(item, componentId, rowModel);
item.add(label);
}
});
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("timesheet.duration"), getSortable("duration", sortable),
"duration", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId, final IModel<TimesheetDO> rowModel)
{
final TimesheetDO timesheet = rowModel.getObject();
final Label label = new Label(componentId, dateTimeFormatter.getFormattedDuration(timesheet.getDuration()));
label.setEscapeModelStrings(false);
cellItemListener.populateItem(item, componentId, rowModel);
item.add(label);
}
});
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("timesheet.location"), getSortable("location", sortable),
"location", cellItemListener));
columns.add(new CellItemListenerPropertyColumn<TimesheetDO>(page.getString("description"), getSortable("shortDescription", sortable),
"shortDescription", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<TimesheetDO>> item, final String componentId, final IModel<TimesheetDO> rowModel)
{
final TimesheetDO timesheet = rowModel.getObject();
final Label label = new Label(componentId, new Model<String>() {
@Override
public String getObject()
{
String text;
if (timesheetFilter != null && timesheetFilter.isLongFormat() == true) {
text = HtmlHelper.escapeXml(timesheet.getDescription());
} else {
text = HtmlHelper.escapeXml(timesheet.getShortDescription());
}
if (isMassUpdateMode == true) {
return text;
} else {
return JiraUtils.linkJiraIssues(text); // Not in mass update mode: link on table row results otherwises in JIRA-Link.