KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > worklist > actions > CompleteWorkitem


1 package org.enhydra.shark.corbaclient.worklist.actions;
2
3
4 import java.awt.*;
5 import java.awt.event.*;
6
7 import javax.swing.*;
8
9 import org.omg.WfBase.*;
10 import org.omg.WorkflowModel.*;
11 import org.enhydra.shark.corbaclient.*;
12 import org.enhydra.shark.corbaclient.worklist.*;
13
14 /**
15  * Implements the action of completing the workitem. It get's the workitem
16  * that corredponds to the selecte table row, checks if it's variables are
17  * updated, and signals to the workitem that it is completed.
18  *
19  * @author Sasa Bojanic
20  * @version 1.0
21  */

22 public class CompleteWorkitem extends ActionBase {
23
24    public CompleteWorkitem (Worklist worklist) {
25       super(worklist);
26    }
27
28    public void actionPerformed(ActionEvent e) {
29       Worklist worklist=(Worklist)actionPanel;
30       WfAssignment ass=worklist.getSelectedAssignment();
31       if (ass!=null) {
32          // check if the workitem is accepted
33
try {
34             boolean accepted=ass.get_accepted_status();
35             if (!accepted) {
36                JOptionPane.showMessageDialog(actionPanel.getWindow(),
37                                              ResourceManager.getLanguageDependentString(
38                                                 "WarningTheWorkitemMustBeAcceptedBeforeExecution"),
39                                              SharkClient.getAppTitle(),JOptionPane.WARNING_MESSAGE);
40                return;
41             }
42
43             WfActivity wa=ass.activity();
44             String JavaDoc waKey=wa.key();
45             // set the result of activity
46
if (!worklist.isWorkitemContextUpdated(waKey)) {
47                NameValue[] actContext=WorkflowUtilities.getActivityContext(
48                   wa.process_context(),wa,WorkflowUtilities.VARIABLE_TO_PROCESS_ALL);
49
50                if (actContext!=null && actContext.length>0) {
51                   int updateVar=JOptionPane.showConfirmDialog(
52                      worklist.getWindow(),
53                      ResourceManager.getLanguageDependentString(
54                                                                 "MessageDoYouWantToUpdateProcessVariables"),
55                      ResourceManager.getLanguageDependentString("WorkitemKey")+" - "+
56                         wa.name(),
57                      JOptionPane.YES_NO_OPTION,
58                      JOptionPane.QUESTION_MESSAGE);
59                   if (updateVar==JOptionPane.YES_OPTION) {
60                      Window w=worklist.getWindow();
61                      NameValue[] readOnlyContext=WorkflowUtilities.getActivityContext(
62                         actContext,wa,WorkflowUtilities.VARIABLE_TO_PROCESS_VIEW);
63                      UpdateVariables upvd=new UpdateVariables(w,
64                                                               ResourceManager.getLanguageDependentString("DialogUpdateProcessVariables"),
65                                                               wa.container().key(),
66                                                               actContext,
67                                                               readOnlyContext);
68                      upvd.showDialog();
69                      if (actContext!=null) {
70                         worklist.putWorkitemContext(waKey,actContext);
71                      }
72                   }
73                }
74             }
75             if (worklist.isWorkitemContextUpdated(waKey)) {
76                NameValue[] actContext=worklist.getWorkitemContext(waKey);
77                NameValue[] updContext=WorkflowUtilities.getActivityContext(actContext,
78                                                                            wa,WorkflowUtilities.VARIABLE_TO_PROCESS_UPDATE);
79                wa.set_result(updContext);
80             }
81             wa.complete();
82             worklist.refresh();
83          } catch (CannotComplete cnc) {
84             JOptionPane.showMessageDialog(worklist.getWindow(),
85                                           ResourceManager.getLanguageDependentString(
86                                              "WarningTheWorkitemCannotBeCompleted"),
87                                           SharkClient.getAppTitle(),JOptionPane.WARNING_MESSAGE);
88
89          } catch (Exception JavaDoc ex) {ex.printStackTrace();}
90       }
91    }
92
93 }
94
95
Popular Tags