01: package org.osbl.client.wings.control;
02:
03: import org.concern.*;
04: import org.concern.model.*;
05: import org.wingx.table.RefreshableModel;
06:
07: import javax.swing.table.AbstractTableModel;
08: import java.util.*;
09:
10: /**
11: * @author hengels
12: * @version $Revision$
13: */
14: class StateTableModel extends AbstractTableModel implements
15: RefreshableModel {
16: private List conditions = new ArrayList();
17: private List states = new ArrayList();
18: private String[] columnNames = new String[] { "Condition", "State", };
19:
20: private Controller controller;
21: private Subject subject;
22:
23: public StateTableModel() {
24: }
25:
26: public void clean() {
27: conditions.clear();
28: states.clear();
29: }
30:
31: public void setController(Controller controller) {
32: if (this .controller != controller) {
33: this .controller = controller;
34: org.concern.model.Process process = controller.getProcess();
35: conditions = new ArrayList(process.getConditions().size());
36: for (Iterator iterator = process.getConditions().iterator(); iterator
37: .hasNext();) {
38: Condition condition = (Condition) iterator.next();
39: conditions.add(condition.getName());
40: }
41: }
42: }
43:
44: public void setSubject(Subject subject) {
45: this .subject = subject;
46: }
47:
48: public void refresh() {
49: if (controller == null || subject == null)
50: return;
51: try {
52: states.clear();
53: for (Iterator iterator = conditions.iterator(); iterator
54: .hasNext();) {
55: String conditionName = (String) iterator.next();
56: states.add(controller.matchCondition(subject
57: .getSubjectId(), conditionName));
58: }
59: } catch (UnknownSubjectException e) {
60: e.printStackTrace();
61: clean();
62: }
63: fireTableDataChanged();
64: }
65:
66: public int getColumnCount() {
67: return columnNames.length;
68: }
69:
70: public String getColumnName(int column) {
71: return columnNames[column];
72: }
73:
74: public int getRowCount() {
75: return states.size();
76: }
77:
78: Log getRow(int row) {
79: return (Log) states.get(row);
80: }
81:
82: public Object getValueAt(int rowIndex, int columnIndex) {
83: switch (columnIndex) {
84: case 0:
85: return conditions.get(rowIndex);
86: case 1:
87: Boolean state = (Boolean) states.get(rowIndex);
88: return state != null ? "" + state : "undefined";
89: }
90: return "?";
91: }
92: }
|