KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > monitoring > HistoryTable


1 package org.enhydra.shark.swingclient.workflowadmin.monitoring;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import javax.swing.*;
6 import javax.swing.border.*;
7 import javax.swing.event.*;
8 import javax.swing.table.*;
9 import java.util.*;
10
11
12 import org.enhydra.shark.api.client.wfmodel.*;
13 import org.enhydra.jawe.xml.elements.*;
14 import org.enhydra.shark.swingclient.*;
15 import org.enhydra.shark.swingclient.workflowadmin.*;
16 import org.enhydra.shark.swingclient.workflowadmin.monitoring.actions.*;
17 import org.enhydra.jawe.xml.elements.*;
18 import org.enhydra.shark.api.client.wfservice.AdminMisc;
19
20 /**
21  * Shows the dialog with the table containing all history for the given process.
22  *
23  * @author Sasa Bojanic
24  * @version 1.0
25  */

26 public class HistoryTable extends ActionPanel {
27
28    private TablePanel historyTablePanel;
29
30    private WfProcess myProcess;
31    private WorkflowProcess myProcessDefinition;
32
33    private ProcessMonitor processMonitor;
34
35
36    public HistoryTable (ProcessMonitor pm,WfProcess proc,WorkflowProcess wp) {
37       super();
38       this.myProcess=proc;
39       this.myProcessDefinition=wp;
40       super.init();
41       this.setPreferredSize(new Dimension(1000,600));
42       super.initDialog(pm.getWorkflowAdmin().getFrame(),
43             ResourceManager.getLanguageDependentString("DialogEventHistory"),
44             true,false);
45    }
46
47    protected void createActions () {}
48
49    /**
50    * Create the center component of this panel.
51    */

52    protected Component createCenterComponent() {
53       Vector columnNames=new Vector();
54       columnNames.add(ResourceManager.getLanguageDependentString("TimeKey"));
55       columnNames.add(ResourceManager.getLanguageDependentString("DescriptionKey"));
56       historyTablePanel=new TablePanel(columnNames,true);
57       fillTable();
58       JTable t=historyTablePanel.getTable();
59       TableColumnModel tcm=t.getColumnModel();
60       TableColumn column=t.getColumnModel().getColumn(0);
61       column.setPreferredWidth(125);
62       column=t.getColumnModel().getColumn(1);
63       column.setPreferredWidth(825);
64       return historyTablePanel;
65    }
66
67    protected void applyChanges () {
68       myDialog.dispose();
69    }
70
71    protected void cancelChanges () {
72       myDialog.dispose();
73    }
74
75    public void fillTable () {
76       java.util.List JavaDoc l=new ArrayList();
77       try {
78          // get all process events, and put it into list
79
WfEventAudit[] procEvents;
80          try {
81             procEvents=myProcess.get_sequence_history(0);
82          } catch (Exception JavaDoc ex) {
83             procEvents=null;
84          }
85          if (procEvents!=null) {
86             for (int i=0; i<procEvents.length; i++) {
87                l.add(new HistoryData(procEvents[i]));
88             }
89          }
90
91          // getting all process activities, and then their events, and put it into list
92
WfActivity[] acts=myProcess.get_sequence_step(0);
93          if (acts!=null) {
94             for (int i=0; i<acts.length; i++) {
95                WfEventAudit[] actEvents;
96                try {
97                   actEvents=acts[i].get_sequence_history(0);
98                } catch (Exception JavaDoc ex) {
99                   actEvents=null;
100                }
101                if (actEvents!=null) {
102                   for (int j=0; j<actEvents.length; j++) {
103                      l.add(new HistoryData(actEvents[j]));
104                   }
105                }
106             }
107          }
108       } catch (Exception JavaDoc ex) {ex.printStackTrace();}
109
110 //System.out.println("There are "+l.size()+" events for process");
111
// sort the list of events chronologically
112
Collections.sort(l,new HistoryDataComparator());
113
114       // add mappings to the table
115
Iterator it=l.iterator();
116       while (it.hasNext()) {
117          HistoryData hd=(HistoryData)it.next();
118          try {
119             Vector v=new Vector();
120             v.add(hd.time);
121             v.add(hd.description);
122             try {
123                historyTablePanel.addElement(v);
124             } catch (Exception JavaDoc ex) {
125                System.out.println("Incorrect vector size");
126             }
127          } catch (Exception JavaDoc ex) {ex.printStackTrace();}
128       }
129    }
130
131    class HistoryData {
132       long utcTime;
133       String JavaDoc time;
134       String JavaDoc description;
135
136       HistoryData (WfEventAudit ev) {
137          init(ev);
138       }
139
140       private void init (WfEventAudit ev) {
141          AdminMisc s=SharkAdmin.getAdminMiscUtilities();
142          try {
143             utcTime=ev.time_stamp().time;
144             time=WorkflowUtilities.getDateFromUTC(ev.time_stamp());
145             if (ev instanceof WfCreateProcessEventAudit) {
146                WfCreateProcessEventAudit ea=(WfCreateProcessEventAudit)ev;
147                description="Process instantiated";
148                if (ea.p_activity_key()!=null) {
149                   description+=" by activity [packageId="+s.getProcessMgrPkgId(ea.p_process_mgr_name())+
150                         ", procDefId="+s.getProcessDefinitionId(ea.p_process_key())+
151                         ", actDefId="+s.getActivityDefinitionId(ea.p_process_key(),ea.p_activity_key())+
152                         ", procId="+ea.p_process_key()+
153                         ", actId="+ea.p_activity_key()+"]";
154
155                }
156 //System.out.println("desccpe="+description);
157
} else if (ev instanceof WfStateEventAudit) {
158                WfStateEventAudit ea=(WfStateEventAudit)ev;
159                if (ea.activity_key()!=null) {
160                   description="Activity [actDefId="+s.getActivityDefinitionId(ea.process_key(),ea.activity_key())+
161                         ", actId="+ea.activity_key()+"] changed state";
162                } else {
163                   description="Process changed state";
164                }
165                // if the object hasn't got previous state, the next
166
// will throw an exception because of null transfered through
167
// the network
168
if (ea.old_state()!=null) {
169                   description+=" from "+ea.old_state();
170                }
171                description+=" to "+ea.new_state();
172 //System.out.println("descse="+description);
173
} else if (ev instanceof WfDataEventAudit) {
174                WfDataEventAudit ea=(WfDataEventAudit)ev;
175                if (ea.activity_key()!=null) {
176                   s.getActivityDefinitionId(ea.process_key(),ea.activity_key());
177                   if (ea.event_type().equals("activityResultChanged")) {
178                      description="Activity context changed as a result of an activity setResult() method";
179                   } else {
180                      description="Activity [actDefId="+s.getActivityDefinitionId(ea.process_key(),ea.activity_key())+
181                         ", actId="+ea.activity_key()+"] context changed ";
182                   }
183                } else {
184                   description="Process context changed ";
185                }
186 //System.out.println("descde="+description);
187
} else if (ev instanceof WfAssignmentEventAudit) {
188                WfAssignmentEventAudit ea=(WfAssignmentEventAudit)ev;
189                description="Activity [actDefId="+s.getActivityDefinitionId(ea.process_key(),ea.activity_key())+
190                         ", actId="+ea.activity_key()+"]";
191                if (ea.old_resource_key()!=null) {
192                   if (ea.old_resource_key().equals(ea.new_resource_key())) {
193                      if (ea.is_accepted()) {
194                         description+=" is accepted by "+ea.new_resource_key();
195                      } else {
196                         description+=" is rejected by "+ea.new_resource_key();
197                      }
198                   } else {
199                      description+=" is reassigned from "+ea.old_resource_key()+
200                         " to "+ea.new_resource_key();
201                   }
202                } else {
203                   description+=" is assigned to "+ea.new_resource_key();
204                }
205 //System.out.println("descae="+description);
206

207             } else {
208 //System.out.println("Event happend for class "+ev.getClass().getName());
209
}
210          } catch (Exception JavaDoc ex) {ex.printStackTrace();}
211       }
212
213
214    }
215
216    class HistoryDataComparator implements Comparator {
217       public int compare(Object JavaDoc o1,Object JavaDoc o2) {
218          HistoryData hd1=(HistoryData)o1;
219          HistoryData hd2=(HistoryData)o2;
220          long t1=hd1.utcTime;
221          long t2=hd2.utcTime;
222
223          return (t1<t2 ? -1 : (t1==t2 ? 0 : 1));
224       }
225    }
226
227 }
228
Popular Tags