1 package org.enhydra.shark.corbaclient.worklist; 2 3 4 import java.awt.Component ; 5 import java.awt.Dimension ; 6 import java.awt.event.*; 7 import java.util.*; 8 9 import javax.swing.*; 10 import javax.swing.table.DefaultTableModel ; 11 import javax.swing.table.TableColumn ; 12 13 import org.enhydra.shark.corbaclient.*; 14 import org.enhydra.shark.corbaclient.worklist.actions.*; 15 import org.enhydra.shark.corbaclient.SharkClient; 16 import org.omg.TimeBase.UtcT; 17 import org.omg.WfBase.NameValue; 18 import org.omg.WorkflowModel.*; 19 20 28 public class Worklist extends ActionPanel { 29 30 31 private Map workitems=new HashMap(); 32 33 private Map procVariables=new HashMap(); 34 35 36 private JTable worklistTable; 37 41 private WorklistTableModel worklistTableModel; 42 43 49 SharkClient workflowClient; 50 51 55 WfResource myResource; 56 57 60 public Worklist (SharkClient wc,boolean disableButtons) { 61 super(); 62 this.workflowClient=wc; 63 super.init(); 64 65 setButtonPanelEnabled(!disableButtons); 66 } 67 68 protected void createActions () { 69 defaultActions=new Action[] { 70 new CompleteWorkitem(this), 71 new UpdateActivityVariables(this), 72 new WorkitemDescription(this) 73 }; 74 } 75 79 protected Component createCenterComponent () { 80 JScrollPane tablePane=new JScrollPane(); 81 worklistTableModel=new WorklistTableModel(); 82 worklistTable=new JTable(worklistTableModel); 83 worklistTable.setColumnSelectionAllowed(false); 85 worklistTable.setRowSelectionAllowed(true); 86 worklistTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 87 worklistTable.getTableHeader().setReorderingAllowed(false); 88 worklistTable.setPreferredScrollableViewportSize(new Dimension (500,300)); 89 TableColumn column=worklistTable.getColumnModel().getColumn(0); 91 column.setMinWidth(0); 92 column.setMaxWidth(0); 93 column.setPreferredWidth(0); 94 column.setResizable(false); 95 96 worklistTable.addMouseListener(new MouseAdapter() { 98 public void mouseClicked (MouseEvent me) { 99 102 if (me.getClickCount()>1) { 103 getAction(Utils.getUnqualifiedClassName(CompleteWorkitem.class)). 104 actionPerformed(null); 105 } 106 } 107 }); 108 109 worklistTable.getInputMap(JComponent.WHEN_FOCUSED). 111 put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,false),"edit"); 112 worklistTable.getActionMap().put("edit",new AbstractAction() { 113 public void actionPerformed(ActionEvent e) { 114 getAction(Utils.getUnqualifiedClassName(CompleteWorkitem.class)). 115 actionPerformed(null); 116 } 117 }); 118 119 tablePane.setViewportView(worklistTable); 120 return tablePane; 121 } 122 123 128 public void setResource (WfResource newResource) { 129 try { 130 if (!newResource.resource_key().equals(myResource.resource_key())) { 131 clear(); 132 } 133 } catch (Exception ex) { 134 } 136 137 138 myResource=newResource; 139 refresh(); 140 } 141 142 147 public void setButtonPanelEnabled (boolean enabled) { 148 for (int i=0; i<buttonPanel.getComponentCount()-1; i++) { 150 buttonPanel.getComponent(i).setEnabled(enabled); 151 } 152 } 153 154 157 public WfResource getResource () { 158 return myResource; 159 } 160 161 166 public WfAssignment getSelectedAssignment () { 167 int selRow=worklistTable.getSelectedRow(); 168 if (selRow>=0) { 169 String id=(String )worklistTableModel.getValueAt(selRow,0); 170 return (WfAssignment)workitems.get(id); 171 } 172 return null; 173 } 174 175 180 public boolean isWorkitemContextUpdated (String workitemKey) { 181 return procVariables.containsKey(workitemKey); 182 } 183 184 187 public NameValue[] getWorkitemContext (String workitemKey) { 188 return (NameValue[])procVariables.get(workitemKey); 189 } 190 191 194 public void putWorkitemContext (String workitemKey,NameValue[] context) { 195 procVariables.put(workitemKey,context); 196 } 197 198 202 public void clear () { 203 myResource=null; 204 workitems.clear(); 205 procVariables.clear(); 206 worklistTableModel.clearTable(); 207 } 208 209 213 public void releaseAllAssignments () { 214 Iterator it=workitems.values().iterator(); 215 while (it.hasNext()) { 216 WfAssignment ass=(WfAssignment)it.next(); 217 try { 218 ass.set_accepted_status(false); 219 } catch (Exception ex) {} 220 } 221 workitems.clear(); 222 } 223 224 232 public synchronized void refresh () { 233 WfAssignment[] ass=null; 235 try { 236 ass=myResource.get_sequence_work_item(0); 237 } catch (Exception ex) { 238 return; 239 } 240 241 ArrayList toAdd=new ArrayList(); 243 ArrayList toRemove=new ArrayList(); 244 ArrayList toRetain=new ArrayList(); 245 createWorkitemLists(ass,toAdd,toRemove,toRetain); 246 247 Iterator it=toRemove.iterator(); 249 while (it.hasNext()) { 250 try { 252 worklistTableModel.removeRow(it.next()); 254 } catch (Exception ex){} 255 } 256 257 it=toAdd.iterator(); 259 while (it.hasNext()) { 260 WfActivity wa=(WfActivity)it.next(); 261 try { 262 if (wa.state().startsWith("open")) { 263 Vector vRow=new Vector(); 264 vRow.add(wa.key()); 265 if (wa.state().equals("open.running")) { 266 vRow.add(new Boolean (true)); 267 } else { 268 vRow.add(new Boolean (false)); 269 } 270 WfProcess proc=wa.container(); 271 String name=proc.name(); 272 String pDefName=SharkClient.getAdminMiscUtilities().getProcessMgrProcDefName(proc.manager().name()); 273 if (pDefName.equals("") || pDefName.equals(name)) { 274 String procId=proc.key(); 275 int ind_=procId.indexOf("_"); 276 if (ind_>0) { 277 name=name+"-"+procId.substring(0,ind_); 278 } 279 } 280 vRow.add(name); 281 vRow.add(wa.name()); 282 vRow.add(new Integer (wa.priority())); 283 String date=""; 284 String duration=""; 285 if (wa.state().startsWith("open.running")) { 286 try { 287 UtcT lastStateT=wa.last_state_time(); 288 date=WorkflowUtilities.getDateFromUTC(lastStateT); 289 duration=WorkflowUtilities.getDuration(lastStateT); 290 } catch (Exception ex) { 291 } 292 } 293 vRow.add(date); 294 vRow.add(duration); 295 worklistTableModel.addRow(vRow); 296 } 297 } catch (Exception ex){} 298 } 299 300 it=toRetain.iterator(); 303 while (it.hasNext()) { 304 WfActivity wa=(WfActivity)it.next(); 305 try { 306 String id=wa.key(); 307 boolean accepted=((WfAssignment)workitems.get(id)).get_accepted_status(); 308 String date=""; 309 String duration=""; 310 if (accepted) { 311 try { 312 UtcT lastStateT=wa.last_state_time(); 313 date=WorkflowUtilities.getDateFromUTC(lastStateT); 314 duration=WorkflowUtilities.getDuration(lastStateT); 315 } catch (Exception ex) { 316 } 317 } 318 worklistTableModel.updateWorkitemProperties(wa.key(),accepted, 319 date,duration); 320 } catch (Exception ex){} 321 } 322 } 323 324 328 private void createWorkitemLists (WfAssignment[] ass, 329 ArrayList toAdd,ArrayList toRemove,ArrayList toRetain) { 330 331 Map newWorkitems=new HashMap(); 333 if (ass!=null) { 334 for (int i=0; i<ass.length; i++) { 335 WfActivity wa; 336 try { 337 wa=ass[i].activity(); 338 newWorkitems.put(wa.key(),ass[i]); 339 } catch (Exception ex) {} 340 } 341 } 342 343 ArrayList toAddIds=new ArrayList(newWorkitems.keySet()); 345 toAddIds.removeAll(workitems.keySet()); 346 ArrayList toRemoveIds=new ArrayList(workitems.keySet()); 347 toRemoveIds.removeAll(newWorkitems.keySet()); 348 ArrayList toRetainIds=new ArrayList(workitems.keySet()); 349 toRetainIds.retainAll(newWorkitems.keySet()); 350 351 Iterator addIt=toAddIds.iterator(); 356 while (addIt.hasNext()) { 357 try { 358 toAdd.add(((WfAssignment)newWorkitems.get(addIt.next())).activity()); 359 } catch (Exception ex) {} 360 } 361 Iterator removeIt=toRemoveIds.iterator(); 363 while (removeIt.hasNext()) { 364 try { 365 Object nextId=removeIt.next(); 366 toRemove.add(nextId); 368 procVariables.remove(nextId); 369 } catch (Exception ex) {} 370 } 371 Iterator retIt=toRetainIds.iterator(); 373 while (retIt.hasNext()) { 374 try { 375 toRetain.add(((WfAssignment)newWorkitems.get(retIt.next())).activity()); 376 } catch (Exception ex) {} 377 } 378 379 workitems.clear(); 381 workitems=newWorkitems; 382 } 383 384 387 class WorklistTableModel extends DefaultTableModel { 388 392 WorklistTableModel () { 393 super(new String [] { 394 ResourceManager.getLanguageDependentString("IdKey"), 395 ResourceManager.getLanguageDependentString("AcceptedKey"), 396 ResourceManager.getLanguageDependentString("ProcessNameKey"), 398 ResourceManager.getLanguageDependentString("WorkitemKey"), 399 ResourceManager.getLanguageDependentString("PriorityKey"), 400 ResourceManager.getLanguageDependentString("StartedKey"), 401 ResourceManager.getLanguageDependentString("DurationKey") 402 },0); 403 } 404 405 408 public void removeRow (Object workitemKey) { 409 int rowCnt=getRowCount(); 410 for (int row=0; row<rowCnt;row++) { 411 if (getValueAt(row,0).equals(workitemKey)) { 412 removeRow(row); 413 break; 414 } 415 } 416 } 417 418 421 public void clearTable () { 422 int rowCnt=getRowCount(); 423 for (int row=rowCnt-1; row>=0; row--) { 425 removeRow(row); 426 } 427 } 428 429 438 public void updateWorkitemProperties (String workitemKey,boolean accept, 439 String newDate,String newDuration) { 440 int rowCnt=getRowCount(); 441 for (int row=0; row<rowCnt;row++) { 442 if (getValueAt(row,0).equals(workitemKey)) { 443 super.setValueAt(new Boolean (accept),row,1); 444 super.setValueAt(newDate,row,5); 445 super.setValueAt(newDuration,row,6); 446 break; 447 } 448 } 449 } 450 451 457 public Class getColumnClass(int c) { 458 return getValueAt(0, c).getClass(); 459 } 460 461 464 public boolean isCellEditable(int row, int col) { 465 if (col==1) { 466 return true; 467 } 468 return false; 469 } 470 471 475 public void setValueAt(Object value, int row, int col) { 476 super.setValueAt(value,row,col); 477 if (col==1) { 478 boolean accepted=((Boolean )value).booleanValue(); 479 try { 480 WfAssignment ass=(WfAssignment)workitems.get(getValueAt(row,0)); 481 ass.set_accepted_status(accepted); 482 if (accepted) { 483 UtcT lastStateT=ass.activity().last_state_time(); 484 String newDate=WorkflowUtilities.getDateFromUTC(lastStateT); 485 String newDuration=WorkflowUtilities.getDuration(lastStateT); 486 super.setValueAt(newDate,row,5); 487 super.setValueAt(newDuration,row,6); 488 } else { 489 super.setValueAt("",row,5); 490 super.setValueAt("",row,6); 491 } 492 } catch (CannotAcceptSuspended cas) { 493 JOptionPane.showMessageDialog(workflowClient.getFrame(), 494 ResourceManager.getLanguageDependentString( 495 "WarningCannotAcceptSuspendedWorkitem"), 496 workflowClient.getAppTitle(),JOptionPane.WARNING_MESSAGE); 497 refresh(); 498 } catch (Exception ex) { 499 JOptionPane.showMessageDialog(workflowClient.getFrame(), 500 ResourceManager.getLanguageDependentString( 501 "WarningTheWorkitemIsPerformedByAnotherUser"), 502 workflowClient.getAppTitle(),JOptionPane.WARNING_MESSAGE); 503 refresh(); 504 } 505 } 506 } 507 508 } 509 510 } 511 | Popular Tags |