View Javadoc

1   package de.jaret.examples.timebars.scheduling.swing;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import javax.swing.table.AbstractTableModel;
7   
8   import de.jaret.examples.timebars.scheduling.model.Job;
9   
10  public class JobTableModel extends AbstractTableModel{
11  
12      private List<Job> _jobs = new ArrayList<Job>();
13      
14      public void addJob(Job job) {
15          _jobs.add(job);
16          fireTableRowsInserted(_jobs.size(), _jobs.size());
17      }
18      
19      public Job getJob(int index) {
20          return _jobs.get(index);
21      }
22      
23      public void removeJob(Job job) {
24          int index = _jobs.indexOf(job);
25          if (index != -1) {
26              _jobs.remove(index);
27              fireTableRowsDeleted(index, index);
28          }
29      }
30      
31      public int getColumnCount() {
32          return 5;
33      }
34  
35      public int getRowCount() {
36          return _jobs.size();
37      }
38  
39      public Object getValueAt(int rowIndex, int columnIndex) {
40          Job job = _jobs.get(rowIndex);
41          
42          switch (columnIndex) {
43          case 0:
44              return job.getName();
45          case 1:
46              return job.getPriority();
47          case 2:
48              return job.getBegin().toDisplayString();
49          case 3:
50              return job.getEnd().toDisplayString();
51          case 4:
52              return job.getSeconds()/60;
53          default:
54              break;
55          }
56          return null;
57      }
58      
59      @Override
60      public String getColumnName(int column) {
61          switch (column) {
62          case 0:
63              return "Name";
64          case 1:
65              return "Priority";
66          case 2:
67              return "Begin";
68          case 3:
69              return "End";
70          case 4:
71              return "Minutes";
72          default:
73              break;
74          }
75          return null;
76      }
77  
78  }