KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.corbaclient.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 import org.omg.WorkflowModel.*;
12 import org.enhydra.jawe.xml.elements.*;
13 import org.enhydra.shark.corbaclient.*;
14 import org.enhydra.shark.corbaclient.workflowadmin.monitoring.actions.*;
15 import org.enhydra.jawe.xml.elements.*;
16 import org.enhydra.shark.corba.WorkflowService.*;
17
18 /**
19  * Shows the dialog with the table containing all history for the given process.
20  *
21  * @author Sasa Bojanic
22  * @version 1.0
23  */

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

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

252             } else {
253 //System.out.println("Event happend for class "+ev.getClass().getName());
254
}
255          } catch (Exception JavaDoc ex) {ex.printStackTrace();}
256       }
257
258
259    }
260
261    class HistoryDataComparator implements Comparator {
262       public int compare(Object JavaDoc o1,Object JavaDoc o2) {
263          HistoryData hd1=(HistoryData)o1;
264          HistoryData hd2=(HistoryData)o2;
265          long t1=hd1.utcTime;
266          long t2=hd2.utcTime;
267
268          return (t1<t2 ? -1 : (t1==t2 ? 0 : 1));
269       }
270    }
271
272 }
273
274
275
Popular Tags