* Return list for table with all recent used time sheets.
* @return
*/
protected List<TimesheetDO> getRecentTimesheets()
{
final TimesheetPrefData data = getTimesheetPrefData();
final List<TimesheetDO> list = new ArrayList<TimesheetDO>();
if (data != null && data.getRecents() != null) {
for (final TimesheetPrefEntry entry : data.getRecents()) {
final TimesheetDO sheet = getRecentSheet(entry);
list.add(sheet);
}
Collections.sort(list, new Comparator<TimesheetDO>() {
public int compare(final TimesheetDO t1, final TimesheetDO t2)
{
final Kost2DO kost1 = t1.getKost2();
final Kost2DO kost2 = t2.getKost2();
final ProjektDO project1 = kost1 != null ? kost1.getProjekt() : null;
final ProjektDO project2 = kost2 != null ? kost2.getProjekt() : null;
final String kunde1 = project1 != null && project1.getKunde() != null ? project1.getKunde().getName() : null;
final String kunde2 = project2 != null && project2.getKunde() != null ? project2.getKunde().getName() : null;
return new CompareToBuilder().append(kunde1, kunde2)
.append(project1 != null ? project1.getName() : null, project2 != null ? project2.getName() : null)
.append(t1.getTask() != null ? t1.getTask().getTitle() : null, t2.getTask() != null ? t2.getTask().getTitle() : null)
.toComparison();
}
});
// Don't show recent block for new users if all entries are already displayed.
if (data.getRecents().size() > SIZE_OF_FIRST_RECENT_BLOCK) {
int i = 0;
for (final TimesheetPrefEntry entry : data.getRecents()) {
final TimesheetDO sheet = getRecentSheet(entry);
list.add(i, sheet);
if (i++ >= SIZE_OF_FIRST_RECENT_BLOCK) {
break;
}