001: package org.osbl.client.wings.control;
002:
003: import org.concern.*;
004: import org.wingx.table.RefreshableModel;
005: import org.wings.session.SessionManager;
006:
007: import javax.swing.table.AbstractTableModel;
008: import java.util.*;
009:
010: /**
011: * @author hengels
012: * @version $Revision$
013: */
014: class EnlistmentsTableModel extends AbstractTableModel implements
015: RefreshableModel {
016: private List activities = new ArrayList();
017: private List types = new ArrayList();
018: protected Map assignments = new HashMap();
019:
020: private String[] columnNames = new String[] { "Activity", "Type",
021: "Assignee", };
022:
023: private Controller controller;
024: private Subject subject;
025: protected Worklist worklist;
026:
027: public EnlistmentsTableModel() {
028: worklist = ControllerLookup.getInstance().getWorklist();
029: }
030:
031: public void clean() {
032: activities.clear();
033: types.clear();
034: }
035:
036: public void setController(Controller controller) {
037: this .controller = controller;
038: }
039:
040: public void setSubject(Subject subject) {
041: this .subject = subject;
042: }
043:
044: public void refresh() {
045: String locale = SessionManager.getSession().getLocale()
046: .toString();
047:
048: if (controller == null || subject == null)
049: return;
050: try {
051: activities.clear();
052: types.clear();
053: assignments.clear();
054: List tasks = controller.getTasks(subject.getSubjectId());
055: for (Iterator iterator = tasks.iterator(); iterator
056: .hasNext();) {
057: String task = (String) iterator.next();
058: activities.add(task);
059: types.add("Task");
060: }
061: List options = controller
062: .getOptions(subject.getSubjectId());
063: for (Iterator iterator = options.iterator(); iterator
064: .hasNext();) {
065: String option = (String) iterator.next();
066: activities.add(option);
067: types.add("Option");
068: }
069: List works = worklist
070: .listAssignments(
071: subject.getSubjectId(),
072: new String[] { controller.getProcessName() },
073: null, null, null, locale, 1000);
074:
075: for (Iterator iterator = works.iterator(); iterator
076: .hasNext();) {
077: Assignment assignment = (Assignment) iterator.next();
078: SortedSet assignees = (SortedSet) assignments
079: .get(assignment.getActivity());
080: if (assignees == null) {
081: assignees = new TreeSet();
082: assignments
083: .put(assignment.getActivity(), assignees);
084: }
085: assignees.add(assignment.getAssignee());
086: }
087: } catch (UnknownSubjectException e) {
088: e.printStackTrace();
089: clean();
090: }
091: fireTableDataChanged();
092: }
093:
094: public int getColumnCount() {
095: return columnNames.length;
096: }
097:
098: public String getColumnName(int column) {
099: return columnNames[column];
100: }
101:
102: public int getRowCount() {
103: return types.size();
104: }
105:
106: String getRow(int row) {
107: return (String) activities.get(row);
108: }
109:
110: public Object getValueAt(int rowIndex, int columnIndex) {
111: switch (columnIndex) {
112: case 0:
113: return activities.get(rowIndex);
114: case 1:
115: return types.get(rowIndex);
116: case 2:
117: return assignments.get(activities.get(rowIndex));
118: }
119: return "?";
120: }
121: }
|