KickJava   Java API By Example, From Geeks To Geeks.

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


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

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