001: package org.osbl.client.wings.concern;
002:
003: import org.concern.Controller;
004: import org.concern.ControllerLookup;
005: import org.osbl.client.wings.shell.Client;
006: import org.osbl.client.wings.form.ObjectTableModel;
007: import org.osbl.client.wings.concern.format.ProcessFormat;
008: import org.conform.BeanMeta;
009: import org.conform.PropertyMeta;
010: import org.conform.wings.ComponentFactory;
011: import org.concern.model.Process;
012: import org.concern.model.Event;
013: import org.wingx.table.XDefaultTableColumnModel;
014: import org.wingx.table.XTableColumnModel;
015:
016: import javax.swing.table.AbstractTableModel;
017: import java.util.*;
018:
019: /**
020: * @author hengels
021: * @version $Revision$
022: */
023: public class ProcessTableModel extends AbstractTableModel implements
024: ObjectTableModel {
025: private final static String[] propertyNames = new String[] {
026: "name", "subject", "instanceCount", };
027:
028: private BeanMeta beanMeta;
029: private XTableColumnModel columnModel = new XDefaultTableColumnModel();
030:
031: List<Process> processes = Collections.EMPTY_LIST;
032:
033: public ProcessTableModel(BeanMeta beanMeta) {
034: this .beanMeta = (BeanMeta) beanMeta.clone();
035: List<PropertyMeta> properties = new LinkedList<PropertyMeta>();
036:
037: // synthetic column for instanceCount
038: for (int i = 0; i < propertyNames.length; i++) {
039: String propertyName = propertyNames[i];
040: PropertyMeta property;
041: if ("instanceCount".equals(propertyName)) {
042: property = new PropertyMeta(beanMeta, "instanceCount",
043: Integer.class);
044: property.setLabel(Client.getInstance()
045: .getResourceProvider().getMessage(
046: Process.class.getName()
047: + ".instanceCount"));
048: } else
049: property = this .beanMeta.getProperty(propertyName);
050:
051: properties.add(property);
052: }
053:
054: this .beanMeta.setProperties(properties
055: .toArray(new PropertyMeta[properties.size()]));
056:
057: for (int i = 0; i < propertyNames.length; i++) {
058: String propertyName = propertyNames[i];
059: columnModel.addColumn(ComponentFactory.INSTANCE
060: .createTableColumn(this .beanMeta, propertyName, i));
061: }
062: }
063:
064: public void refresh() {
065: ControllerLookup controllerLookup = ControllerLookup
066: .getInstance();
067: String[] processNames = controllerLookup.getControllerNames();
068: processes = new ArrayList<Process>(processNames.length);
069: for (int i = 0; i < processNames.length; i++) {
070: String processName = processNames[i];
071: Controller controller = controllerLookup
072: .getController(processName);
073: Process process = controller.getProcess();
074: if (findCreateForm(process) == null)
075: continue;
076:
077: int instanceCount = controller.getSubjects(
078: Controller.STATE_RUNNING).size();
079: process.set("instanceCount", instanceCount);
080: processes.add(process);
081: }
082:
083: fireTableRowsUpdated(0, processes.size());
084: }
085:
086: public static String findCreateForm(Process process) {
087: Collection<Event> events = process.getEvents();
088: for (Event event : events) {
089: String formClassName = (String) event
090: .getEnvironmentEntry("formClassName");
091: if (formClassName != null)
092: return formClassName;
093: }
094: return null;
095: }
096:
097: public XTableColumnModel getColumnModel() {
098: return columnModel;
099: }
100:
101: public int getRowCount() {
102: return processes.size();
103: }
104:
105: public int getColumnCount() {
106: return columnModel.getColumnCount();
107: }
108:
109: public Object getRowId(int rowIndex) {
110: return getRow(rowIndex).getName();
111: }
112:
113: public Object getValueAt(int rowIndex, int columnIndex) {
114: Process process = processes.get(rowIndex);
115:
116: switch (columnIndex) {
117: case 0:
118: return ProcessFormat.INSTANCE.format(process);
119: case 1:
120: return Client.getInstance().getResourceProvider()
121: .getMessage(process.getSubject());
122: case 2:
123: return process.get("instanceCount");
124: }
125: return "?";
126: }
127:
128: public String getColumnName(int column) {
129: return "" + columnModel.getColumn(column).getHeaderValue();
130: }
131:
132: public Class<?> getColumnClass(int columnIndex) {
133: return beanMeta.getProperties()[columnIndex].getType();
134: }
135:
136: Process getRow(int row) {
137: return processes.get(row);
138: }
139: }
|