KickJava   Java API By Example, From Geeks To Geeks.

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


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
9
10 import org.enhydra.shark.api.client.wfmodel.*;
11 import org.enhydra.jawe.xml.elements.*;
12 import org.enhydra.shark.swingclient.*;
13 import org.enhydra.shark.swingclient.workflowadmin.*;
14 import org.enhydra.shark.swingclient.workflowadmin.monitoring.actions.*;
15
16 /**
17  * Enables user to manage the state of activities.
18  *
19  * @author Sasa Bojanic
20  * @version 1.0
21  */

22 public class ManageActivities extends ActionPanel {
23
24    private static Dimension listFieldDimension=new Dimension(300,300);
25
26    private JList activities;
27    private JTextField activity=new JTextField();
28
29    private java.util.List JavaDoc allActivities;
30    private WfProcess myProcess;
31
32    private ProcessMonitor processMonitor;
33
34    public ManageActivities (ProcessMonitor pm,WfProcess proc,java.util.List JavaDoc acts) {
35       super();
36       this.processMonitor=pm;
37       this.myProcess=proc;
38       this.allActivities=acts;
39       super.init();
40       super.initDialog(pm.getWorkflowAdmin().getFrame(),
41             ResourceManager.getLanguageDependentString("DialogManageActivities"),
42             false,false);
43    }
44
45   protected void createActions () {
46       defaultActions=new Action[] {
47          new SuspendActivity(this),
48          new ResumeActivity(this),
49          new TerminateActivity(this),
50          new AbortActivity(this),
51          new ManuallyStartActivity(this)
52       };
53    }
54
55    /**
56    * Create the center component of this panel.
57    */

58    protected Component createCenterComponent() {
59       activity.setEnabled(false);
60
61       JScrollPane scrollActivities=new JScrollPane();
62       activities=new JList(allActivities.toArray());
63       activities.addListSelectionListener(new ListSelectionListener() {
64          public void valueChanged(ListSelectionEvent e) {
65             if (e.getValueIsAdjusting()) {
66                return;
67             }
68
69             JList theList = (JList)e.getSource();
70             if (theList.isSelectionEmpty()) {
71                activity.setText("");
72             } else {
73                Activity act=(Activity)theList.getSelectedValue();
74                WfActivity a=getLastActivityForDefinition(act,null,0);
75                try {
76                   String JavaDoc state=a.state();
77                   String JavaDoc stateKey=ResourceManager.getLanguageDependentString(state+"Key");
78                   activity.setText(stateKey);
79                } catch (Exception JavaDoc ex) {
80                   activity.setText(ResourceManager.getLanguageDependentString("NotOpenedKey"));
81                }
82             }
83          }
84       });
85
86       activities.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
87       scrollActivities.setViewportView(activities);
88       scrollActivities.setPreferredSize(new Dimension(listFieldDimension));
89
90       JPanel pm=new JPanel();
91       Border emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
92       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
93       inb=BorderFactory.createTitledBorder(inb,
94          ResourceManager.getLanguageDependentString("SelectActivityKey"));
95       pm.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
96       pm.setLayout(new BoxLayout(pm,BoxLayout.Y_AXIS));
97       pm.add(scrollActivities);
98       pm.add(activity);
99
100       return pm;
101    }
102
103    /**
104     * Searchs for the activity instance based on it's definition, the state,
105     * and the type of comparing the state.
106     * @param act The activity definition
107     * @param state The state in which activity has to be
108     * @param compareType The type of compare. If it is 0, the state of the
109     * activity has to be as the given one, otherwise it has to start
110     * with the given state string
111     * @return instance of WfActivity
112     */

113    public WfActivity getLastActivityForDefinition (Activity act,String JavaDoc state,int compareType) {
114       if (act==null) return null;
115       try {
116          WfActivityIterator wai=SharkClient.getCommonExpressionBuilder().getActivitiesForDefinitionAndState(myProcess.key(),act.getID(),state,compareType==0);
117
118          wai.goto_end();
119          WfActivity lastActivityForDefinition=null;
120          // searches only for activity that is not in the block
121
while (true) {
122             lastActivityForDefinition=wai.get_previous_object();
123             try {
124                String JavaDoc baId=SharkAdmin.getAdminMiscUtilities().
125                   getBlockActivityId(myProcess.key(),lastActivityForDefinition.key());
126                if (baId==null || baId.length()==0) {
127                   break;
128                }
129             } catch (Exception JavaDoc ex) {
130                break;
131             }
132          }
133          return lastActivityForDefinition;
134       } catch (Exception JavaDoc ex) {
135          return null;
136       }
137    }
138
139    public Activity getSelectedActivity () {
140       return (Activity)activities.getSelectedValue();
141    }
142
143    public WfProcess getProcess () {
144       return myProcess;
145    }
146
147    public void updateListDisplay (Activity act) {
148       activities.getSelectionModel().clearSelection();
149       activities.setSelectedValue(act,true);
150    }
151
152    public void updateProcessView () {
153       processMonitor.getProcessViewer().updateSelection();
154    }
155
156 }
157
Popular Tags