001: package com.opensymphony.workflow.designer.model;
002:
003: import java.util.*;
004:
005: import com.opensymphony.workflow.loader.FunctionDescriptor;
006: import com.opensymphony.workflow.loader.PaletteDescriptor;
007: import com.opensymphony.workflow.loader.ConfigFunctionDescriptor;
008: import com.opensymphony.workflow.designer.ResourceManager;
009: import com.opensymphony.workflow.designer.WorkflowGraphModel;
010:
011: /**
012: * @author Andrea Capitani (a.capitani@leonardomultimedia.it)
013: * Date: Nov 20, 2004
014: * Time: 3:05:16 PM
015: */
016: public class TriggersTableModel extends MapTableModel {
017: private String[] header = new String[] {
018: ResourceManager.getString("id"),
019: ResourceManager.getString("name"),
020: ResourceManager.getString("type") };
021: private WorkflowGraphModel graphModel;
022:
023: public WorkflowGraphModel getGraphModel() {
024: return graphModel;
025: }
026:
027: public void setGraphModel(WorkflowGraphModel graphModel) {
028: this .graphModel = graphModel;
029: }
030:
031: public boolean isCellEditable(int rowIndex, int columnIndex) {
032: return false;
033: }
034:
035: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
036: int id = getRowTriggerID(rowIndex);
037: if (id == -1)
038: return;
039:
040: FunctionDescriptor function = (FunctionDescriptor) map
041: .get(new Integer(id));
042: if (function != null) {
043: switch (columnIndex) {
044: case 0: // ID
045: break;
046: case 1: // Name
047: if (aValue != null)
048: function.setName(aValue.toString());
049: break;
050: case 2: // Type
051: if (aValue != null)
052: function.setType(aValue.toString());
053: break;
054: }
055: }
056: }
057:
058: public int getColumnCount() {
059: return header.length;
060: }
061:
062: public String getColumnName(int column) {
063: return header[column];
064: }
065:
066: public Class getColumnClass(int columnIndex) {
067: return String.class;
068: }
069:
070: public Object getValueAt(int rowIndex, int columnIndex) {
071: // get the row id
072: int id = getRowTriggerID(rowIndex);
073: if (id == -1)
074: return "";
075: FunctionDescriptor function = (FunctionDescriptor) map
076: .get(new Integer(id));
077: if (function != null) {
078: PaletteDescriptor palette = graphModel.getPalette();
079: ConfigFunctionDescriptor config = palette
080: .getTriggerFunction(function.getName());
081: switch (columnIndex) {
082: case 0: // ID
083: return String.valueOf(id);
084: case 1: // Name
085: String name = config != null
086: && config.getDisplayName() != null ? config
087: .getDisplayName() : ResourceManager
088: .getString("unknown");
089: return name;
090: case 2: // Type
091: return function.getType();
092: default:
093: return "";
094: }
095: }
096: return "";
097: }
098:
099: private int getRowTriggerID(int rowIndex) {
100: int counter = 0;
101: Iterator it = map.keySet().iterator();
102:
103: while (it.hasNext()) {
104: Integer id = (Integer) it.next();
105: if (counter == rowIndex) {
106: return id.intValue();
107: }
108: counter++;
109: }
110: return -1; // not found!!
111: }
112: }
|