01: package org.rapla.plugin.tableview;
02:
03: import java.util.Date;
04: import java.util.Locale;
05:
06: import javax.swing.table.DefaultTableModel;
07:
08: import org.rapla.components.xmlbundle.I18nBundle;
09: import org.rapla.entities.domain.Appointment;
10: import org.rapla.entities.domain.Reservation;
11:
12: public class ReservationTableModel extends DefaultTableModel {
13: private static final long serialVersionUID = 1L;
14:
15: Reservation[] reservations = new Reservation[] {};
16: Locale locale;
17: I18nBundle i18n;
18:
19: //String[] columns;
20: public ReservationTableModel(Locale locale, I18nBundle i18n) {
21: this .locale = locale;
22: this .i18n = i18n;
23: String[] columns = new String[] { i18n.getString("name"),
24: i18n.getString("start_date"),
25: i18n.getString("last_changed") };
26: this .setColumnIdentifiers(columns);
27: }
28:
29: public void setReservations(Reservation[] events) {
30: this .reservations = events;
31: super .fireTableDataChanged();
32: }
33:
34: public Reservation getReservationAt(int row) {
35: return this .reservations[row];
36: }
37:
38: public boolean isCellEditable(int row, int column) {
39: return false;
40: }
41:
42: public int getRowCount() {
43: if (reservations != null)
44: return reservations.length;
45: else
46: return 0;
47: }
48:
49: public Date findStartDate(Reservation event) {
50: Appointment[] apps = event.getAppointments();
51: Date minimumDate = null;
52: for (int i = 0; i < apps.length; i++) {
53: Appointment app = apps[i];
54: if (minimumDate == null
55: || app.getStart().before(minimumDate)) {
56: minimumDate = app.getStart();
57: }
58: }
59: return minimumDate;
60: }
61:
62: public Object getValueAt(int rowIndex, int columnIndex) {
63: Reservation event = reservations[rowIndex];
64: switch (columnIndex) {
65: case 0:
66: return event.getName(locale);
67: case 1:
68: return findStartDate(event);
69: case 2:
70: return event.getLastChangeTime();
71: }
72: return event;
73: }
74:
75: public Class getColumnClass(int columnIndex) {
76: switch (columnIndex) {
77: case 0:
78: return String.class;
79: case 1:
80: return Date.class;
81: case 2:
82: return Date.class;
83: }
84: return super.getColumnClass(columnIndex);
85: }
86:
87: }
|