final List<IColumn<HRViewUserData, String>> columns = new ArrayList<IColumn<HRViewUserData, String>>();
final CellItemListener<HRViewUserData> cellItemListener = new CellItemListener<HRViewUserData>() {
public void populateItem(final Item<ICellPopulator<HRViewUserData>> item, final String componentId,
final IModel<HRViewUserData> rowModel)
{
final HRViewUserData entry = rowModel.getObject();
appendCssClasses(item, entry.getPlanningId(), entry.isDeleted());
}
};
columns.add(new UserPropertyColumn<HRViewUserData>(getString("timesheet.user"), "user.fullname", "user", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<HRViewUserData>> item, final String componentId,
final IModel<HRViewUserData> rowModel)
{
final Integer planningId = rowModel.getObject().getPlanningId();
final String[] params;
if (planningId == null) {
// Preset fields for adding new entry:
final Integer userId = rowModel.getObject().getUserId();
params = new String[] { WebConstants.PARAMETER_USER_ID, userId != null ? String.valueOf(userId) : null,
WebConstants.PARAMETER_DATE, weekMillis != null ? String.valueOf(weekMillis) : null};
} else {
params = null;
}
item.add(new ListSelectActionPanel(componentId, rowModel, HRPlanningEditPage.class, planningId, HRListPage.this,
getLabelString(rowModel), params));
cellItemListener.populateItem(item, componentId, rowModel);
addRowClick(item);
}
}.withUserFormatter(userFormatter));
columns.add(new CellItemListenerPropertyColumn<HRViewUserData>(getString("sum"), "plannedDaysSum", "plannedDaysSum", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<HRViewUserData>> item, final String componentId,
final IModel<HRViewUserData> rowModel)
{
final HRViewUserData userData = rowModel.getObject();
final HRFilter filter = form.getSearchFilter();
addListEntry(item, componentId, userData.getPlannedDaysSum(), userData.getActualDaysSum(), new Link<Object>("actualDaysLink") {
@Override
public void onClick()
{
// Redirect to time sheet list page and show the corresponding time sheets.
final PageParameters parameters = new PageParameters();
parameters.add(TimesheetListPage.PARAMETER_KEY_STORE_FILTER, false);
parameters.add(TimesheetListPage.PARAMETER_KEY_START_TIME, filter.getStartTime().getTime());
parameters.add(TimesheetListPage.PARAMETER_KEY_STOP_TIME, filter.getStopTime().getTime());
parameters.add(TimesheetListPage.PARAMETER_KEY_USER_ID, userData.getUserId());
final TimesheetListPage timesheetListPage = new TimesheetListPage(parameters);
setResponsePage(timesheetListPage);
}
});
item.add(AttributeModifier.append("style", new Model<String>("text-align: right;")));
cellItemListener.populateItem(item, componentId, rowModel);
}
});
columns.add(new CellItemListenerPropertyColumn<HRViewUserData>(getString("rest"), "plannedDaysRestSum", "plannedDaysRestSum",
cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<HRViewUserData>> item, final String componentId,
final IModel<HRViewUserData> rowModel)
{
final HRViewUserData userData = rowModel.getObject();
addLabel(item, componentId, userData.getPlannedDaysRestSum(), userData.getActualDaysRestSum());
item.add(AttributeModifier.append("style", new Model<String>("text-align: right;")));
cellItemListener.populateItem(item, componentId, rowModel);
}
});
for (final ProjektDO project : getHRViewData().getProjects()) {
columns.add(new CellItemListenerPropertyColumn<HRViewUserData>(project.getProjektIdentifierDisplayName(), null, null,
cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<HRViewUserData>> item, final String componentId,
final IModel<HRViewUserData> rowModel)
{
cellItemListener.populateItem(item, componentId, rowModel);
final HRViewUserData userData = rowModel.getObject();
final HRViewUserEntryData entry = userData.getEntry(project);
if (entry == null) {
item.add(createInvisibleDummyComponent(componentId));
return;
}
final HRFilter filter = form.getSearchFilter();
addListEntry(item, componentId, entry.getPlannedDays(), entry.getActualDays(), new Link<Object>("actualDaysLink") {
@Override
public void onClick()
{
// Redirect to time sheet list page and show the corresponding time sheets.
final PageParameters parameters = new PageParameters();
parameters.add(TimesheetListPage.PARAMETER_KEY_STORE_FILTER, false);
parameters.add(TimesheetListPage.PARAMETER_KEY_TASK_ID, project.getTaskId());
parameters.add(TimesheetListPage.PARAMETER_KEY_START_TIME, filter.getStartTime().getTime());
parameters.add(TimesheetListPage.PARAMETER_KEY_STOP_TIME, filter.getStopTime().getTime());
parameters.add(TimesheetListPage.PARAMETER_KEY_USER_ID, userData.getUserId());
final TimesheetListPage timesheetListPage = new TimesheetListPage(parameters);
setResponsePage(timesheetListPage);
}
});
item.add(AttributeModifier.append("style", new Model<String>("text-align: right;")));