001: package org.osbl.client.wings.concern;
002:
003: import org.concern.*;
004: import org.osbl.client.wings.form.ObjectTableModel;
005: import org.osbl.client.wings.form.StringEditableCellRenderer;
006: import org.conform.BeanMeta;
007: import org.conform.wings.ComponentFactory;
008: import org.wings.session.SessionManager;
009: import org.wingx.table.*;
010:
011: import java.util.*;
012:
013: /**
014: * @author hengels
015: * @version $Revision$
016: */
017: public class SubjectTableModel extends XTableModel implements
018: ObjectTableModel {
019: private final static String[] propertyNames = new String[] {
020: "subjectLine", "process", "originator", "created", };
021: private final static String[] filterColumnNames = new String[] {
022: "line.line", "subject.process", "subject.originator",
023: "subject.created", };
024:
025: private BeanMeta beanMeta;
026: private XTableColumnModel columnModel = new XDefaultTableColumnModel();
027:
028: List subjects = Collections.EMPTY_LIST;
029:
030: protected Worklist worklist;
031: protected String assignee;
032: private String[] processes;
033: private int state;
034: private String[] orders;
035: private String[] originators;
036: private String[] keywords;
037:
038: public SubjectTableModel(BeanMeta beanMeta) {
039: this .beanMeta = beanMeta;
040: worklist = ControllerLookup.getInstance().getWorklist();
041:
042: for (int i = 0; i < propertyNames.length; i++) {
043: String columnName = propertyNames[i];
044: columnModel.addColumn(ComponentFactory.INSTANCE
045: .createTableColumn(beanMeta, columnName, i));
046: }
047: columnModel.getColumn("process").setSortable(true);
048: columnModel.getColumn("originator").setSortable(true);
049: columnModel.getColumn("created").setSortable(true);
050:
051: columnModel.getColumn("subjectLine").setFilterable(true);
052: columnModel.getColumn("subjectLine").setFilterRenderer(
053: new StringEditableCellRenderer());
054: columnModel.getColumn("process").setFilterable(true);
055: columnModel.getColumn("process").setFilterRenderer(
056: new ProcessFilterRenderer());
057: columnModel.getColumn("originator").setFilterable(true);
058: columnModel.getColumn("originator").setFilterRenderer(
059: new StringEditableCellRenderer());
060: }
061:
062: public String[] getKeywords() {
063: return keywords;
064: }
065:
066: public void setKeywords(String[] keywords) {
067: this .keywords = keywords;
068: }
069:
070: public void setAssignee(String assignee) {
071: this .assignee = assignee;
072: }
073:
074: public void setProcesses(String[] processes) {
075: this .processes = processes;
076: }
077:
078: public String[] getOriginators() {
079: return originators;
080: }
081:
082: public void setOriginators(String[] originators) {
083: this .originators = originators;
084: }
085:
086: public int getState() {
087: return state;
088: }
089:
090: public void setState(int state) {
091: this .state = state;
092: }
093:
094: public void refresh() {
095: if (state == Controller.STATE_DESTROYED) {
096: subjects = worklist.listArchivedSubjects(processes,
097: keywords, originators, orders(), locale(), 200);
098: } else
099: subjects = worklist.listSubjects(assignees(), processes,
100: keywords, originators, state, orders(), locale(),
101: 200);
102:
103: fireTableDataChanged();
104: }
105:
106: private String locale() {
107: return SessionManager.getSession().getLocale().toString();
108: }
109:
110: private String[] assignees() {
111: return assignee != null ? new String[] { "*", assignee } : null;
112: }
113:
114: public void setFilter(int col, Object value) {
115: super .setFilter(col, value);
116: switch (col) {
117: case 0:
118: keywords = tokenize((String) value);
119: break;
120: case 1:
121: processes = (String[]) value;
122: break;
123: case 2:
124: originators = tokenize((String) value);
125: break;
126: }
127: }
128:
129: protected String[] tokenize(String string) {
130: if (string == null)
131: return new String[0];
132:
133: StringTokenizer tokens = new StringTokenizer(string, " ,");
134: String[] strings = new String[tokens.countTokens()];
135: for (int i = 0; tokens.hasMoreTokens(); i++)
136: strings[i] = tokens.nextToken();
137:
138: return strings;
139: }
140:
141: public void setSort(int col, int order) {
142: super .setSort(col, order);
143: orders = null;
144: }
145:
146: private String[] orders() {
147: if (orders == null) {
148: List<String> orders = new LinkedList<String>();
149: for (int i = 0; i < getColumnCount(); i++) {
150: int sort = getSort(i);
151: if (sort == SORT_NONE)
152: continue;
153:
154: orders.add((sort == SORT_ASCENDING ? "" : "-")
155: + SubjectTableModel.filterColumnNames[i]);
156: }
157: this .orders = orders.toArray(new String[orders.size()]);
158: }
159: return orders;
160: }
161:
162: public XTableColumnModel getColumnModel() {
163: return columnModel;
164: }
165:
166: public int getRowCount() {
167: return subjects.size();
168: }
169:
170: public int getColumnCount() {
171: return columnModel.getColumnCount();
172: }
173:
174: public Object getRowId(int rowIndex) {
175: return getRow(rowIndex).getSubjectId();
176: }
177:
178: public Object getValueAt(int rowIndex, int columnIndex) {
179: Subject subject = (Subject) subjects.get(rowIndex);
180:
181: switch (columnIndex) {
182: case 0:
183: String subjectLine = subject.getSubjectLine();
184: if (subjectLine != null && subjectLine.length() > 60)
185: subjectLine = subjectLine.substring(0, 56) + " ...";
186: return subjectLine;
187: case 1:
188: return subject.getProcess();
189: case 2:
190: return subject.getOriginator();
191: case 3:
192: return subject.getCreated();
193: }
194: return "?";
195: }
196:
197: public String getColumnName(int column) {
198: return "" + columnModel.getColumn(column).getHeaderValue();
199: }
200:
201: public Class<?> getColumnClass(int columnIndex) {
202: return beanMeta.getProperties()[columnIndex].getType();
203: }
204:
205: Subject getRow(int row) {
206: return (Subject) subjects.get(row);
207: }
208: }
|