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