KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > worklist > WorklistManagement


1 package org.enhydra.shark.swingclient.workflowadmin.worklist;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6
7 import javax.swing.*;
8
9
10
11 import org.enhydra.shark.api.client.wfmodel.*;
12 import org.enhydra.shark.swingclient.*;
13 import org.enhydra.shark.swingclient.workflowadmin.*;
14 import org.enhydra.shark.swingclient.workflowadmin.user.*;
15 import org.enhydra.shark.swingclient.workflowadmin.worklist.actions.*;
16 import org.enhydra.shark.swingclient.worklist.*;
17
18 /**
19  * Implements the user interface and program logic to manage the
20  * worklists of different users.
21  *
22  * @author Sasa Bojanic
23  * @version 1.0
24  */

25 public class WorklistManagement extends ActionPanel {
26    private static Dimension comboFieldDimension=new Dimension(200,20);
27
28    private SharkAdmin workflowAdmin;
29    private Worklist worklist;
30    private JComboBox users;
31    private JLabel isLogged=new JLabel();
32    // action taken upon the selection change within the users combo
33
private ActionListener usersAL;
34
35    private ArrayList existingUsers=new ArrayList();
36
37    public WorklistManagement (SharkAdmin wa) {
38       super();
39       // It is important to set workflowAdmin before initing
40
this.workflowAdmin=wa;
41
42       super.init();
43
44       add(createControlPanel(),BorderLayout.NORTH,0);
45    }
46
47    protected void createActions () {
48       defaultActions=new Action[] {
49          new ReassignWorkitem(this)
50       };
51    }
52
53    protected Component createCenterComponent () {
54       worklist=new Worklist(workflowAdmin,false);
55       return worklist;
56    }
57
58    public SharkAdmin getWorkflowAdmin () {
59       return workflowAdmin;
60    }
61
62    public Worklist getWorklist () {
63       return worklist;
64    }
65
66    private Component createControlPanel () {
67       JPanel p=new JPanel();
68       p.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
69       p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
70
71       p.add(new JLabel(ResourceManager.getLanguageDependentString("SelectUserKey")+": "));
72
73       users=new JComboBox();
74       users.setMinimumSize(new Dimension(comboFieldDimension));
75       users.setMaximumSize(new Dimension(comboFieldDimension));
76       users.setPreferredSize(new Dimension(comboFieldDimension));
77       usersAL=new ActionListener() {
78          public void actionPerformed(ActionEvent ae) {
79             WfResource choosen=getResource(users.getSelectedItem());
80             worklist.setResource(choosen);
81             /*try {
82                boolean currentUser=choosen.resource_key().equals(workflowAdmin.getService().getResourceObject().resource_key());
83
84                if (currentUser) {
85                   worklist.setButtonPanelEnabled(true);
86                } else {
87                   worklist.setButtonPanelEnabled(false);
88                }
89             } catch (Exception ex) {
90                worklist.setButtonPanelEnabled(false);
91              }*/

92             if (choosen==null) {
93                isLogged.setText("");
94             } else {
95                LoggedUsersManagement lum=workflowAdmin.
96                   getUserManagement().getLoggedUsersManagement();
97                String JavaDoc uname=null;
98                try {
99                   uname=choosen.resource_key();
100                } catch (Exception JavaDoc ex) {}
101                if (lum.isLogged(uname)) {
102                   isLogged.setText(" ---> "+
103                      ResourceManager.getLanguageDependentString("LoggedKey"));
104                } else {
105                   isLogged.setText(" ---> "+
106                      ResourceManager.getLanguageDependentString("NotLoggedKey"));
107                }
108             }
109          }
110       };
111       users.addActionListener(usersAL);
112       p.add(users);
113
114       p.add(isLogged);
115
116       JButton reassign=(JButton)BarFactory.
117          createButton(Utils.getUnqualifiedClassName(ReassignWorkitem.class),commands,true);
118       JPanel bp=new JPanel();
119       bp.setLayout(new BorderLayout());
120       bp.add(reassign,BorderLayout.EAST);
121
122       p.add(bp);
123
124       return p;
125    }
126
127    public void clear () {
128       existingUsers.clear();
129       users.removeActionListener(usersAL);
130       users.removeAllItems();
131       users.addActionListener(usersAL);
132       isLogged.setText("");
133       worklist.clear();
134    }
135
136    public synchronized void refresh (boolean mandatoryRefreshing) {
137       if (!(mandatoryRefreshing || isShowing())) return;
138       ArrayList oldEU=new ArrayList(existingUsers);
139       existingUsers.clear();
140       try {
141          existingUsers=new ArrayList(Arrays.asList(SharkAdmin.getExecAmin().get_sequence_resource(0)));
142       } catch (Exception JavaDoc ex) {
143          ex.printStackTrace();
144       }
145
146       ArrayList toAdd=new ArrayList(existingUsers);
147       toAdd.removeAll(oldEU);
148       ArrayList toRemove=new ArrayList(oldEU);
149       toRemove.removeAll(existingUsers);
150
151       if (toAdd.size()>0 || toRemove.size()>0) {
152          // remember previously selected resource
153
String JavaDoc toSelectId=null;
154          try {
155             toSelectId=worklist.getResource().resource_key();
156          } catch (Exception JavaDoc ex) {}
157
158          // remove combo listener
159
users.removeActionListener(usersAL);
160          // add newly added resources to the table
161
users.removeAllItems();
162          Iterator it=existingUsers.iterator();
163          while (it.hasNext()) {
164             WfResource res=(WfResource)it.next();
165             try {
166                users.addItem(res.resource_key());
167             } catch (Exception JavaDoc ex) {}
168          }
169          users.setSelectedItem(toSelectId);
170          Object JavaDoc selItem=users.getSelectedItem();
171          if ((selItem!=null) && (!selItem.equals(toSelectId))) {
172             worklist.setResource(getResource(selItem));
173          } else {
174             worklist.refresh();
175          }
176          /*try {
177             if (worklist.getResource().resource_key().equals(workflowAdmin.getService().getResourceObject().resource_key())) {
178                worklist.setButtonPanelEnabled(true);
179             } else {
180                worklist.setButtonPanelEnabled(false);
181             }
182          } catch (Exception ex) {
183             worklist.setButtonPanelEnabled(false);
184           }*/

185          // add back combo listener
186
users.addActionListener(usersAL);
187       } else {
188          worklist.refresh();
189       }
190    }
191
192    private WfResource getResource (Object JavaDoc key) {
193       if (key==null) return null;
194       String JavaDoc un=(String JavaDoc)key;
195       Iterator it=existingUsers.iterator();
196       while (it.hasNext()) {
197          WfResource res=(WfResource)it.next();
198          try {
199             if (res.resource_key().equals(un)) {
200                return res;
201             }
202          } catch (Exception JavaDoc ex) {}
203       }
204       return null;
205    }
206
207 }
208
Popular Tags