Source Code Cross Referenced for UserMapping.java in  » Workflow-Engines » shark » org » enhydra » shark » swingclient » workflowadmin » user » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » shark » org.enhydra.shark.swingclient.workflowadmin.user 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.shark.swingclient.workflowadmin.user;
002:
003:        import java.awt.Color;
004:        import java.awt.Component;
005:        import java.awt.Dimension;
006:        import java.util.ArrayList;
007:        import java.util.Collection;
008:        import java.util.Iterator;
009:
010:        import javax.swing.BorderFactory;
011:        import javax.swing.Box;
012:        import javax.swing.BoxLayout;
013:        import javax.swing.DefaultListModel;
014:        import javax.swing.JLabel;
015:        import javax.swing.JList;
016:        import javax.swing.JOptionPane;
017:        import javax.swing.JPanel;
018:        import javax.swing.JScrollPane;
019:        import javax.swing.JTextField;
020:        import javax.swing.ListSelectionModel;
021:        import javax.swing.border.Border;
022:        import javax.swing.event.ListSelectionEvent;
023:        import javax.swing.event.ListSelectionListener;
024:        import javax.transaction.Status;
025:        import javax.transaction.UserTransaction;
026:
027:        import org.enhydra.shark.api.admin.UserGroupManagerAdmin;
028:        import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
029:        import org.enhydra.shark.api.client.wfservice.WMEntity;
030:        import org.enhydra.shark.api.internal.partmappersistence.ParticipantMap;
031:        import org.enhydra.shark.client.utilities.SharkInterfaceWrapper;
032:        import org.enhydra.shark.swingclient.ActionPanel;
033:        import org.enhydra.shark.swingclient.ResourceManager;
034:        import org.enhydra.shark.swingclient.SharkClient;
035:        import org.enhydra.shark.swingclient.workflowadmin.WMEntityView;
036:
037:        /**
038:         * Enables the user to map some participant to the actual user represented by it's account
039:         * username.
040:         * 
041:         * @author Sasa Bojanic
042:         * @version 1.0
043:         */
044:        public class UserMapping extends ActionPanel {
045:
046:            private static Dimension listFieldDimension = new Dimension(300,
047:                    300);
048:
049:            private static Dimension textFieldDimension = new Dimension(300, 20);
050:
051:            private JList participants;
052:
053:            private JList usernames;
054:
055:            private JTextField pkgId = new JTextField();
056:
057:            private JTextField procDefId = new JTextField();
058:
059:            private JTextField participantId = new JTextField();
060:
061:            private JTextField participantName = new JTextField();
062:
063:            private JTextField username = new JTextField();
064:
065:            private JTextField firstname = new JTextField();
066:
067:            private JTextField lastname = new JTextField();
068:
069:            private JTextField email = new JTextField();
070:
071:            private JTextField isGroupUser = new JTextField();
072:
073:            private Collection allParticipants;
074:
075:            private ArrayList users;
076:
077:            private ArrayList groupNames;
078:
079:            private UserMappingManagement umm;
080:
081:            public UserMapping(UserMappingManagement umm,
082:                    Collection allParticipants, ArrayList users,
083:                    ArrayList groupNames) {
084:                this .umm = umm;
085:                this .allParticipants = allParticipants;
086:                this .users = users;
087:                this .groupNames = groupNames;
088:
089:                init();
090:                initDialog(
091:                        umm.getWindow(),
092:                        ResourceManager
093:                                .getLanguageDependentString("DialogCreateParticipantToUserMapping"),
094:                        true, true);
095:                dialogOKButton.setText(ResourceManager
096:                        .getLanguageDependentString("ApplyKey"));
097:                dialogCancelButton.setText(ResourceManager
098:                        .getLanguageDependentString("CloseKey"));
099:            }
100:
101:            protected void createActions() {
102:            }
103:
104:            protected Component createCenterComponent() {
105:                pkgId.setEditable(false);
106:                procDefId.setEditable(false);
107:                participantId.setEditable(false);
108:                participantName.setEditable(false);
109:                username.setEditable(false);
110:                firstname.setEditable(false);
111:                lastname.setEditable(false);
112:                email.setEditable(false);
113:                isGroupUser.setEditable(false);
114:
115:                JScrollPane scrollParam = new JScrollPane();
116:                java.util.List allPViews = WMEntityView
117:                        .toWMEntityViewList(allParticipants);
118:
119:                participants = new JList(allPViews.toArray());
120:                participants
121:                        .addListSelectionListener(new ListSelectionListener() {
122:                            public void valueChanged(ListSelectionEvent e) {
123:                                if (e.getValueIsAdjusting()) {
124:                                    return;
125:                                }
126:
127:                                JList theList = (JList) e.getSource();
128:                                if (theList.isSelectionEmpty()) {
129:                                    pkgId.setText("");
130:                                    procDefId.setText("");
131:                                    participantId.setText("");
132:                                    participantName.setText("");
133:                                } else {
134:                                    WMEntity p = ((WMEntityView) theList
135:                                            .getSelectedValue()).getElement();
136:
137:                                    pkgId.setText(p.getPkgId());
138:                                    if (p.getWpId() != null) {
139:                                        procDefId.setText(p.getWpId());
140:                                    } else {
141:                                        procDefId.setText("");
142:                                    }
143:                                    participantId.setText(p.getId());
144:                                    participantName.setText(p.getName());
145:                                }
146:                            }
147:                        });
148:
149:                participants
150:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
151:                scrollParam.setViewportView(participants);
152:                scrollParam.setPreferredSize(new Dimension(listFieldDimension));
153:
154:                JPanel pp = new JPanel();
155:                Border emptyb = BorderFactory.createEmptyBorder(10, 10, 10, 10);
156:                Border inb = BorderFactory.createMatteBorder(1, 1, 1, 1,
157:                        Color.darkGray);
158:                inb = BorderFactory.createTitledBorder(inb, ResourceManager
159:                        .getLanguageDependentString("SelectParticipantKey"));
160:                pp.setBorder(BorderFactory.createCompoundBorder(emptyb, inb));
161:                pp.setLayout(new BoxLayout(pp, BoxLayout.Y_AXIS));
162:                pp.add(scrollParam);
163:
164:                JPanel pp1 = new JPanel();
165:                pp1.setLayout(new BoxLayout(pp1, BoxLayout.X_AXIS));
166:                pp1.add(Box.createHorizontalGlue());
167:                pp1.add(new JLabel(ResourceManager
168:                        .getLanguageDependentString("PackageIdKey")
169:                        + ": "));
170:                pkgId.setMinimumSize(new Dimension(textFieldDimension));
171:                pkgId.setMaximumSize(new Dimension(textFieldDimension));
172:                pkgId.setPreferredSize(new Dimension(textFieldDimension));
173:                pp1.add(pkgId);
174:                pp.add(pp1);
175:
176:                pp1 = new JPanel();
177:                pp1.setLayout(new BoxLayout(pp1, BoxLayout.X_AXIS));
178:                pp1.add(Box.createHorizontalGlue());
179:                pp1.add(new JLabel(ResourceManager
180:                        .getLanguageDependentString("ProcessDefinitionIdKey")
181:                        + ": "));
182:                procDefId.setMinimumSize(new Dimension(textFieldDimension));
183:                procDefId.setMaximumSize(new Dimension(textFieldDimension));
184:                procDefId.setPreferredSize(new Dimension(textFieldDimension));
185:                pp1.add(procDefId);
186:                pp.add(pp1);
187:
188:                pp1 = new JPanel();
189:                pp1.setLayout(new BoxLayout(pp1, BoxLayout.X_AXIS));
190:                pp1.add(Box.createHorizontalGlue());
191:                pp1.add(new JLabel(ResourceManager
192:                        .getLanguageDependentString("ParticipantIdKey")
193:                        + ": "));
194:                participantId.setMinimumSize(new Dimension(textFieldDimension));
195:                participantId.setMaximumSize(new Dimension(textFieldDimension));
196:                participantId
197:                        .setPreferredSize(new Dimension(textFieldDimension));
198:                pp1.add(participantId);
199:                pp.add(pp1);
200:
201:                pp1 = new JPanel();
202:                pp1.setLayout(new BoxLayout(pp1, BoxLayout.X_AXIS));
203:                pp1.add(Box.createHorizontalGlue());
204:                pp1.add(new JLabel(ResourceManager
205:                        .getLanguageDependentString("ParticipantNameKey")
206:                        + ": "));
207:                participantName
208:                        .setMinimumSize(new Dimension(textFieldDimension));
209:                participantName
210:                        .setMaximumSize(new Dimension(textFieldDimension));
211:                participantName.setPreferredSize(new Dimension(
212:                        textFieldDimension));
213:                pp1.add(participantName);
214:                pp.add(pp1);
215:
216:                DefaultListModel listModel = new DefaultListModel();
217:                // fills list of users
218:                Iterator it = users.iterator();
219:                final UserGroupManagerAdmin uga = SharkInterfaceWrapper
220:                        .getUserGroupAdmin();
221:                // add users
222:                WMSessionHandle shandle = null;
223:                try {
224:                    shandle = SharkClient.getSessionHandle();
225:                } catch (Exception ex) {
226:                }
227:                while (it.hasNext()) {
228:                    String uname = (String) it.next();
229:                    try {
230:                        uname = uname + " - "
231:                                + uga.getUserRealName(shandle, uname);
232:                    } catch (Throwable ex) {
233:                        // ex.printStackTrace();
234:                    }
235:                    try {
236:                        listModel.addElement(uname);
237:                    } catch (Exception ex) {
238:                    }
239:                }
240:                // add user group
241:                it = groupNames.iterator();
242:                while (it.hasNext()) {
243:                    String uname = (String) it.next();
244:                    try {
245:                        listModel.addElement(uname);
246:                    } catch (Exception ex) {
247:                    }
248:                }
249:                scrollParam = new JScrollPane();
250:                usernames = new JList(listModel);
251:                usernames.addListSelectionListener(new ListSelectionListener() {
252:                    public void valueChanged(ListSelectionEvent e) {
253:                        if (e.getValueIsAdjusting()) {
254:                            return;
255:                        }
256:                        UserTransaction ut = null;
257:                        try {
258:                            ut = SharkInterfaceWrapper.getUserTransaction();
259:                            ut.begin();
260:                            WMSessionHandle shandle = SharkClient
261:                                    .getSessionHandle();
262:                            JList theList = (JList) e.getSource();
263:                            if (theList.isSelectionEmpty()) {
264:                                username.setText("");
265:                                firstname.setText("");
266:                                lastname.setText("");
267:                                email.setText("");
268:                                isGroupUser.setText("");
269:                            } else {
270:                                int usersSize = users.size();
271:                                int selectedIndex = theList.getSelectedIndex();
272:                                // user is selected
273:                                if (!(selectedIndex + 1 > usersSize)) {
274:                                    String uname = (String) users.get(theList
275:                                            .getSelectedIndex());
276:                                    try {
277:                                        username.setText(uname);
278:                                    } catch (Exception ex) {
279:                                        username.setText("");
280:                                    }
281:                                    try {
282:                                        firstname.setText(uga.getUserFirstName(
283:                                                shandle, uname));
284:                                    } catch (Exception ex) {
285:                                        firstname.setText("");
286:                                    }
287:                                    try {
288:                                        lastname.setText(uga.getUserLastName(
289:                                                shandle, uname));
290:                                    } catch (Exception ex) {
291:                                        lastname.setText("");
292:                                    }
293:                                    try {
294:                                        email.setText(uga.getUserEMailAddress(
295:                                                shandle, uname));
296:                                    } catch (Exception ex) {
297:                                        email.setText("");
298:                                    }
299:                                    try {
300:                                        isGroupUser
301:                                                .setText(ResourceManager
302:                                                        .getLanguageDependentString("IsGroupUserFALSEKey"));
303:                                    } catch (Exception ex) {
304:                                        isGroupUser.setText("");
305:                                    }
306:                                }
307:                                // group is selected
308:                                else {
309:                                    int dec = usersSize == 0 ? usersSize
310:                                            : usersSize;
311:                                    int selIndex = theList.getSelectedIndex() == 0 ? theList
312:                                            .getSelectedIndex()
313:                                            : theList.getSelectedIndex();
314:                                    int index = selIndex - dec;
315:                                    if (index > -1) {
316:                                        String uname = (String) groupNames
317:                                                .get(index);
318:                                        try {
319:                                            username.setText(uname);
320:                                        } catch (Exception ex) {
321:                                            username.setText("");
322:                                        }
323:                                    }
324:                                    try {
325:                                        isGroupUser
326:                                                .setText(ResourceManager
327:                                                        .getLanguageDependentString("IsGroupUserTRUEKey"));
328:                                    } catch (Exception ex) {
329:                                        isGroupUser.setText("");
330:                                    }
331:                                    // reset fields
332:                                    firstname.setText("");
333:                                    lastname.setText("");
334:                                    email.setText("");
335:                                }
336:                            }
337:                            ut.commit();
338:                        } catch (Exception ex) {
339:                            ex.printStackTrace();
340:                            try {
341:                                if (ut.getStatus() != Status.STATUS_NO_TRANSACTION) {
342:                                    ut.rollback();
343:                                }
344:                            } catch (Exception _) {
345:                            }
346:                            // System.out.println("ERROR IN AddUserMapping.actionPerformed()");
347:                            // ex.printStackTrace();
348:                        }
349:                    }
350:                });
351:                usernames.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
352:                scrollParam.setViewportView(usernames);
353:                scrollParam.setPreferredSize(new Dimension(listFieldDimension));
354:
355:                JPanel up = new JPanel();
356:                emptyb = BorderFactory.createEmptyBorder(10, 10, 10, 10);
357:                inb = BorderFactory.createMatteBorder(1, 1, 1, 1,
358:                        Color.darkGray);
359:                inb = BorderFactory.createTitledBorder(inb, ResourceManager
360:                        .getLanguageDependentString("SelectUserKey"));
361:                up.setBorder(BorderFactory.createCompoundBorder(emptyb, inb));
362:                up.setLayout(new BoxLayout(up, BoxLayout.Y_AXIS));
363:                up.add(scrollParam);
364:                up.add(Box.createVerticalGlue());
365:
366:                JPanel up1 = new JPanel();
367:                up1.setLayout(new BoxLayout(up1, BoxLayout.X_AXIS));
368:                up1.add(Box.createHorizontalGlue());
369:                up1.add(new JLabel(ResourceManager
370:                        .getLanguageDependentString("UsernameKey")
371:                        + ": "));
372:                username.setMinimumSize(new Dimension(textFieldDimension));
373:                username.setMaximumSize(new Dimension(textFieldDimension));
374:                username.setPreferredSize(new Dimension(textFieldDimension));
375:                up1.add(username);
376:                up.add(up1);
377:
378:                up1 = new JPanel();
379:                up1.setLayout(new BoxLayout(up1, BoxLayout.X_AXIS));
380:                up1.add(Box.createHorizontalGlue());
381:                up1.add(new JLabel(ResourceManager
382:                        .getLanguageDependentString("FirstNameKey")
383:                        + ": "));
384:                firstname.setMinimumSize(new Dimension(textFieldDimension));
385:                firstname.setMaximumSize(new Dimension(textFieldDimension));
386:                firstname.setPreferredSize(new Dimension(textFieldDimension));
387:                up1.add(firstname);
388:                up.add(up1);
389:
390:                up1 = new JPanel();
391:                up1.setLayout(new BoxLayout(up1, BoxLayout.X_AXIS));
392:                up1.add(Box.createHorizontalGlue());
393:                up1.add(new JLabel(ResourceManager
394:                        .getLanguageDependentString("LastNameKey")
395:                        + ": "));
396:                lastname.setMinimumSize(new Dimension(textFieldDimension));
397:                lastname.setMaximumSize(new Dimension(textFieldDimension));
398:                lastname.setPreferredSize(new Dimension(textFieldDimension));
399:                up1.add(lastname);
400:                up.add(up1);
401:
402:                up1 = new JPanel();
403:                up1.setLayout(new BoxLayout(up1, BoxLayout.X_AXIS));
404:                up1.add(Box.createHorizontalGlue());
405:                up1.add(new JLabel(ResourceManager
406:                        .getLanguageDependentString("EmailAddressKey")
407:                        + ": "));
408:                email.setMinimumSize(new Dimension(textFieldDimension));
409:                email.setMaximumSize(new Dimension(textFieldDimension));
410:                email.setPreferredSize(new Dimension(textFieldDimension));
411:                up1.add(email);
412:                up.add(up1);
413:
414:                up1 = new JPanel();
415:                up1.setLayout(new BoxLayout(up1, BoxLayout.X_AXIS));
416:                up1.add(Box.createHorizontalGlue());
417:                up1.add(new JLabel(ResourceManager
418:                        .getLanguageDependentString("IsGroupUserKey")
419:                        + ": "));
420:                isGroupUser.setMinimumSize(new Dimension(textFieldDimension));
421:                isGroupUser.setMaximumSize(new Dimension(textFieldDimension));
422:                isGroupUser.setPreferredSize(new Dimension(textFieldDimension));
423:                up1.add(isGroupUser);
424:                up.add(up1);
425:
426:                JPanel mp = new JPanel();
427:                mp.setBorder(BorderFactory.createEtchedBorder());
428:                mp.setLayout(new BoxLayout(mp, BoxLayout.X_AXIS));
429:
430:                mp.add(pp);
431:                mp.add(up);
432:
433:                return mp;
434:            }
435:
436:            protected void applyChanges() {
437:
438:                if (participants.isSelectionEmpty()
439:                        || usernames.isSelectionEmpty())
440:                    return;
441:
442:                UserTransaction ut = null;
443:                try {
444:                    ut = SharkInterfaceWrapper.getUserTransaction();
445:                    ut.begin();
446:
447:                    ParticipantMap pm = SharkInterfaceWrapper
448:                            .getParticipantMappingsAdmin()
449:                            .createParticipantMap();
450:                    pm.setPackageId(pkgId.getText());
451:                    pm.setProcessDefinitionId(procDefId.getText());
452:                    pm.setParticipantId(participantId.getText());
453:                    pm.setUsername(username.getText());
454:                    if (ResourceManager.getLanguageDependentString(
455:                            "IsGroupUserTRUEKey").equalsIgnoreCase(
456:                            isGroupUser.getText().trim()))
457:                        pm.setIsGroupUser(true);
458:                    else
459:                        pm.setIsGroupUser(false);
460:                    SharkInterfaceWrapper.getParticipantMappingsAdmin()
461:                            .saveParticipantMapping(pm);
462:
463:                    umm.refresh(true);
464:                    ut.commit();
465:                } catch (Exception ex) {
466:                    try {
467:                        ut.rollback();
468:                    } catch (Exception _) {
469:                    }
470:                    JOptionPane
471:                            .showMessageDialog(
472:                                    umm.getWindow(),
473:                                    ResourceManager
474:                                            .getLanguageDependentString("MessageMappingAlreadyExistsOrCannotBeAddedAtTheMoment"),
475:                                    ResourceManager
476:                                            .getLanguageDependentString("WorkflowAdminTitle"),
477:                                    JOptionPane.INFORMATION_MESSAGE);
478:                }
479:            }
480:
481:            protected void cancelChanges() {
482:                myDialog.dispose();
483:            }
484:
485:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.