KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > workflowadmin > user > UserMapping


1 package org.enhydra.shark.corbaclient.workflowadmin.user;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6
7 import javax.swing.*;
8 import javax.swing.border.*;
9 import javax.swing.event.*;
10
11 import org.omg.WfBase.*;
12 import org.omg.WorkflowModel.*;
13 import org.enhydra.jawe.xml.elements.*;
14 import org.enhydra.shark.corbaclient.*;
15 import org.enhydra.shark.corbaclient.workflowadmin.*;
16 import org.enhydra.shark.corba.WorkflowService.*;
17
18 /**
19  * Enables the user to map some participant to the actual user
20  * represented by it's account username.
21  *
22  * @author Sasa Bojanic
23  * @version 1.0
24  */

25 public class UserMapping extends ActionPanel {
26
27    private static Dimension listFieldDimension=new Dimension(300,300);
28    private static Dimension textFieldDimension=new Dimension(300,20);
29
30    private JList participants;
31    private JList usernames;
32    private JTextField pkgId=new JTextField();
33    private JTextField procDefId=new JTextField();
34    private JTextField participantId=new JTextField();
35    private JTextField participantName=new JTextField();
36    private JTextField username=new JTextField();
37    private JTextField firstname=new JTextField();
38    private JTextField lastname=new JTextField();
39    private JTextField email=new JTextField();
40    private JTextField isGroupUser=new JTextField();
41
42    private Collection allParticipants;
43    private ArrayList users;
44    private ArrayList groupNames;
45
46    private UserMappingManagement umm;
47
48    public UserMapping(
49       UserMappingManagement umm,
50       Collection allParticipants,
51       ArrayList users,
52       ArrayList groupNames) {
53       this.umm=umm;
54       this.allParticipants=allParticipants;
55       this.users=users;
56       this.groupNames = groupNames;
57
58       init();
59       initDialog(umm.getWindow(),ResourceManager.
60                     getLanguageDependentString("DialogCreateParticipantToUserMapping"),true,true);
61       dialogOKButton.setText(ResourceManager.getLanguageDependentString("ApplyKey"));
62       dialogCancelButton.setText(ResourceManager.getLanguageDependentString("CloseKey"));
63    }
64
65    protected void createActions () {}
66
67    protected Component createCenterComponent (){
68       pkgId.setEditable(false);
69       procDefId.setEditable(false);
70       participantId.setEditable(false);
71       participantName.setEditable(false);
72       username.setEditable(false);
73       firstname.setEditable(false);
74       lastname.setEditable(false);
75       email.setEditable(false);
76       isGroupUser.setEditable(false);
77
78       JScrollPane scrollParam=new JScrollPane();
79       participants=new JList(allParticipants.toArray());
80       participants.addListSelectionListener(new ListSelectionListener() {
81                public void valueChanged(ListSelectionEvent e) {
82                   if (e.getValueIsAdjusting()) {
83                      return;
84                   }
85
86                   JList theList = (JList)e.getSource();
87                   if (theList.isSelectionEmpty()) {
88                      pkgId.setText("");
89                      procDefId.setText("");
90                      participantId.setText("");
91                      participantName.setText("");
92                   } else {
93                      Participant p = (Participant)theList.getSelectedValue();
94
95
96                      pkgId.setText(p.getPackage().get("Id").toString());
97                      if (p.getCollection().getOwner() instanceof WorkflowProcess) {
98                         procDefId.setText(((WorkflowProcess)p.getCollection().getOwner()).getID());
99                      } else {
100                         procDefId.setText("");
101                      }
102                      participantId.setText(p.getID());
103                      participantName.setText(p.get("Name").toString());
104                   }
105                }
106             });
107
108       participants.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
109       scrollParam.setViewportView(participants);
110       scrollParam.setPreferredSize(new Dimension(listFieldDimension));
111
112       JPanel pp=new JPanel();
113       Border emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
114       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
115       inb=BorderFactory.createTitledBorder(inb,
116                                            ResourceManager.getLanguageDependentString("SelectParticipantKey"));
117       pp.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
118       pp.setLayout(new BoxLayout(pp,BoxLayout.Y_AXIS));
119       pp.add(scrollParam);
120
121       JPanel pp1=new JPanel();
122       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
123       pp1.add(Box.createHorizontalGlue());
124       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("PackageIdKey")+": "));
125       pkgId.setMinimumSize(new Dimension(textFieldDimension));
126       pkgId.setMaximumSize(new Dimension(textFieldDimension));
127       pkgId.setPreferredSize(new Dimension(textFieldDimension));
128       pp1.add(pkgId);
129       pp.add(pp1);
130
131       pp1=new JPanel();
132       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
133       pp1.add(Box.createHorizontalGlue());
134       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("ProcessDefinitionIdKey")+": "));
135       procDefId.setMinimumSize(new Dimension(textFieldDimension));
136       procDefId.setMaximumSize(new Dimension(textFieldDimension));
137       procDefId.setPreferredSize(new Dimension(textFieldDimension));
138       pp1.add(procDefId);
139       pp.add(pp1);
140
141       pp1=new JPanel();
142       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
143       pp1.add(Box.createHorizontalGlue());
144       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("ParticipantIdKey")+": "));
145       participantId.setMinimumSize(new Dimension(textFieldDimension));
146       participantId.setMaximumSize(new Dimension(textFieldDimension));
147       participantId.setPreferredSize(new Dimension(textFieldDimension));
148       pp1.add(participantId);
149       pp.add(pp1);
150
151       pp1=new JPanel();
152       pp1.setLayout(new BoxLayout(pp1,BoxLayout.X_AXIS));
153       pp1.add(Box.createHorizontalGlue());
154       pp1.add(new JLabel(ResourceManager.getLanguageDependentString("ParticipantNameKey")+": "));
155       participantName.setMinimumSize(new Dimension(textFieldDimension));
156       participantName.setMaximumSize(new Dimension(textFieldDimension));
157       participantName.setPreferredSize(new Dimension(textFieldDimension));
158       pp1.add(participantName);
159       pp.add(pp1);
160
161       DefaultListModel listModel=new DefaultListModel();
162       // fills list of users
163
Iterator it=users.iterator();
164       final UserGroupAdministration uga=SharkAdmin.getUserGroupAmin();
165       //add users
166
while (it.hasNext()) {
167          String JavaDoc uname=(String JavaDoc)it.next();
168          try {
169             uname=uname+" - "+uga.getUserRealName(uname);
170          } catch (Throwable JavaDoc ex) {
171             //ex.printStackTrace();
172
}
173          try {
174             listModel.addElement(uname);
175          } catch (Exception JavaDoc ex) {}
176       }
177       //add user group
178
it = groupNames.iterator();
179       while (it.hasNext()) {
180          String JavaDoc uname=(String JavaDoc)it.next();
181          try {
182             listModel.addElement(uname);
183          } catch (Exception JavaDoc ex) {}
184       }
185       scrollParam=new JScrollPane();
186       usernames=new JList(listModel);
187       usernames.addListSelectionListener(new ListSelectionListener() {
188                public void valueChanged(ListSelectionEvent e) {
189                   if (e.getValueIsAdjusting()) {
190                      return;
191                   }
192
193                   JList theList = (JList)e.getSource();
194
195                   if (theList.isSelectionEmpty()) {
196                      username.setText("");
197                      firstname.setText("");
198                      lastname.setText("");
199                      email.setText("");
200                      isGroupUser.setText("");
201                   } else {
202                      int usersSize = users.size();
203                      int selectedIndex = theList.getSelectedIndex();
204                      //user is selected
205
if( !(selectedIndex+1 > usersSize) ) {
206                         String JavaDoc uname=(String JavaDoc)users.get(theList.getSelectedIndex());
207                         try {
208                            username.setText(uname);
209                         } catch (Exception JavaDoc ex) {
210                            username.setText("");
211                         }
212                         try {
213                            firstname.setText(uga.getUserFirstName(uname));
214                         } catch (Exception JavaDoc ex) {
215                            firstname.setText("");
216                         }
217                         try {
218                            lastname.setText(uga.getUserLastName(uname));
219                         } catch (Exception JavaDoc ex) {
220                            lastname.setText("");
221                         }
222                         try {
223                            email.setText(uga.getUserEMailAddress(uname));
224                         } catch (Exception JavaDoc ex) {
225                            email.setText("");
226                         }
227                         try {
228                            isGroupUser.setText(ResourceManager.
229                                                   getLanguageDependentString("IsGroupUserFALSEKey"));
230                         } catch (Exception JavaDoc ex) {
231                            isGroupUser.setText("");
232                         }
233                      }
234                         //group is selected
235
else {
236                         int dec = usersSize==0 ? usersSize : usersSize;
237                         int selIndex = theList.getSelectedIndex()==0 ? theList.getSelectedIndex() : theList.getSelectedIndex();
238                         int index = selIndex-dec;
239                         if( index > -1 ) {
240                            String JavaDoc uname=(String JavaDoc)groupNames.get( index );
241                            try {
242                               username.setText(uname);
243                            } catch (Exception JavaDoc ex) {
244                               username.setText("");
245                            }
246                         }
247                         try {
248                            isGroupUser.setText(ResourceManager.
249                                                   getLanguageDependentString("IsGroupUserTRUEKey"));
250                         } catch (Exception JavaDoc ex) {
251                            isGroupUser.setText("");
252                         }
253                         //reset fields
254
firstname.setText("");
255                         lastname.setText("");
256                         email.setText("");
257                      }
258                   }
259                }
260             });
261       usernames.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
262       scrollParam.setViewportView(usernames);
263       scrollParam.setPreferredSize(new Dimension(listFieldDimension));
264
265       JPanel up=new JPanel();
266       emptyb=BorderFactory.createEmptyBorder(10,10,10,10);
267       inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
268       inb=BorderFactory.createTitledBorder(inb,
269                                            ResourceManager.getLanguageDependentString("SelectUserKey"));
270       up.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
271       up.setLayout(new BoxLayout(up,BoxLayout.Y_AXIS));
272       up.add(scrollParam);
273       up.add(Box.createVerticalGlue());
274
275       JPanel up1=new JPanel();
276       up1.setLayout(new BoxLayout(up1,BoxLayout.X_AXIS));
277       up1.add(Box.createHorizontalGlue());
278       up1.add(new JLabel(ResourceManager.getLanguageDependentString("UsernameKey")+": "));
279       username.setMinimumSize(new Dimension(textFieldDimension));
280       username.setMaximumSize(new Dimension(textFieldDimension));
281       username.setPreferredSize(new Dimension(textFieldDimension));
282       up1.add(username);
283       up.add(up1);
284
285       up1=new JPanel();
286       up1.setLayout(new BoxLayout(up1,BoxLayout.X_AXIS));
287       up1.add(Box.createHorizontalGlue());
288       up1.add(new JLabel(ResourceManager.getLanguageDependentString("FirstNameKey")+": "));
289       firstname.setMinimumSize(new Dimension(textFieldDimension));
290       firstname.setMaximumSize(new Dimension(textFieldDimension));
291       firstname.setPreferredSize(new Dimension(textFieldDimension));
292       up1.add(firstname);
293       up.add(up1);
294
295       up1=new JPanel();
296       up1.setLayout(new BoxLayout(up1,BoxLayout.X_AXIS));
297       up1.add(Box.createHorizontalGlue());
298       up1.add(new JLabel(ResourceManager.getLanguageDependentString("LastNameKey")+": "));
299       lastname.setMinimumSize(new Dimension(textFieldDimension));
300       lastname.setMaximumSize(new Dimension(textFieldDimension));
301       lastname.setPreferredSize(new Dimension(textFieldDimension));
302       up1.add(lastname);
303       up.add(up1);
304
305       up1=new JPanel();
306       up1.setLayout(new BoxLayout(up1,BoxLayout.X_AXIS));
307       up1.add(Box.createHorizontalGlue());
308       up1.add(new JLabel(ResourceManager.getLanguageDependentString("EmailAddressKey")+": "));
309       email.setMinimumSize(new Dimension(textFieldDimension));
310       email.setMaximumSize(new Dimension(textFieldDimension));
311       email.setPreferredSize(new Dimension(textFieldDimension));
312       up1.add(email);
313       up.add(up1);
314
315       up1=new JPanel();
316       up1.setLayout(new BoxLayout(up1,BoxLayout.X_AXIS));
317       up1.add(Box.createHorizontalGlue());
318       up1.add(new JLabel(ResourceManager.getLanguageDependentString("IsGroupUserKey")+": "));
319       isGroupUser.setMinimumSize(new Dimension(textFieldDimension));
320       isGroupUser.setMaximumSize(new Dimension(textFieldDimension));
321       isGroupUser.setPreferredSize(new Dimension(textFieldDimension));
322       up1.add(isGroupUser);
323       up.add(up1);
324
325       JPanel mp=new JPanel();
326       mp.setBorder(BorderFactory.createEtchedBorder());
327       mp.setLayout(new BoxLayout(mp,BoxLayout.X_AXIS));
328
329       mp.add(pp);
330       mp.add(up);
331
332       return mp;
333    }
334
335    protected void applyChanges () {
336       if (participants.isSelectionEmpty() || usernames.isSelectionEmpty()) return;
337
338       MappingAdministration mm=null;
339       try {
340          mm=SharkAdmin.getMappingAdmin();
341          ParticipantMap pm=mm.createParticipantMap();
342          pm.setPackageId(pkgId.getText());
343          pm.setProcessDefinitionId(procDefId.getText());
344          pm.setParticipantId(participantId.getText());
345          pm.setUsername(username.getText());
346          if( ResourceManager.getLanguageDependentString("IsGroupUserTRUEKey").equalsIgnoreCase(isGroupUser.getText().trim()))
347             pm.setIsGroupUser( true );
348          else
349             pm.setIsGroupUser( false);
350          mm.addParticipantMapping(pm);
351       } catch (Exception JavaDoc ex) {
352          JOptionPane.showMessageDialog(umm.getWindow(),
353                                        ResourceManager.getLanguageDependentString("MessageMappingAlreadyExistsOrCannotBeAddedAtTheMoment"),
354                                        ResourceManager.getLanguageDependentString("WorkflowAdminTitle"),
355                                        JOptionPane.INFORMATION_MESSAGE);
356       }
357       umm.refresh(true);
358    }
359
360    protected void cancelChanges () {
361       myDialog.dispose();
362    }
363
364 }
365
366
Popular Tags