Source Code Cross Referenced for RolManagerModifyFrame.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » usermanager » 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 » Report » jmagallanes 1.0 » com.calipso.reportgenerator.usermanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.calipso.reportgenerator.usermanager;
002:
003:        import com.calipso.reportgenerator.common.ShowExceptionMessageDialog;
004:        import com.calipso.reportgenerator.common.*;
005:
006:        import javax.swing.*;
007:        import java.awt.event.ActionListener;
008:        import java.awt.event.ActionEvent;
009:        import java.awt.*;
010:        import java.util.*;
011:
012:        /**
013:         * frame que se invoca para agregar o modificar un rol
014:         */
015:
016:        public class RolManagerModifyFrame extends JDialog {
017:
018:            private javax.swing.JButton accept;
019:            private javax.swing.JButton cancel;
020:            private javax.swing.JLabel JLabelRolId;
021:            private javax.swing.JButton add;
022:            private javax.swing.JButton del;
023:            private javax.swing.JLabel jLabelUsers;
024:            private javax.swing.JPanel jPanel1;
025:            private javax.swing.JTextField jTextFieldRolId;
026:            private JList listUsers;
027:            private DefaultListModel listModel;
028:            private UserManager userManager;
029:            private Rol rol;
030:
031:            /**
032:             * Constructor para crear un rol nuevo
033:             * @param parent
034:             * @param userManager
035:             */
036:            public RolManagerModifyFrame(JFrame parent, UserManager userManager) {
037:                super (parent, true);
038:                setResizable(false);
039:                this .userManager = userManager;
040:                initComponents();
041:
042:                listModel = new DefaultListModel();
043:
044:                listUsers = new JList(listModel);
045:
046:                listUsers.setVisible(true);
047:                JScrollPane scrollpane = new JScrollPane(listUsers);
048:
049:                jPanel1.add(scrollpane, new AbsoluteConstraints(80, 35, 210,
050:                        225));
051:
052:                accept.addActionListener(new ButtonListener());
053:                add.addActionListener(new ButtonListener());
054:                del.addActionListener(new ButtonListener());
055:            }
056:
057:            /**
058:             * Constructor para modificar un rol ya existente
059:             * @param parent
060:             * @param userManager
061:             * @param rol
062:             */
063:            public RolManagerModifyFrame(JFrame parent,
064:                    UserManager userManager, Rol rol) {
065:                super (parent, true);
066:                setResizable(false);
067:                initComponents();
068:                this .rol = rol;
069:                this .userManager = userManager;
070:                jTextFieldRolId.setText(rol.getId());
071:                jTextFieldRolId.setEditable(false);
072:
073:                getUsers();
074:
075:                listUsers.setVisible(true);
076:                JScrollPane scrollpane = new JScrollPane(listUsers);
077:
078:                jPanel1.add(scrollpane, new AbsoluteConstraints(80, 35, 210,
079:                        225));
080:
081:                add.addActionListener(new ButtonListener());
082:                del.addActionListener(new ButtonListener());
083:                accept.addActionListener(new ButtonListener());
084:            }
085:
086:            /**
087:             * obtiene los usuarios del rol
088:             */
089:
090:            private void getUsers() {
091:                listModel = new DefaultListModel();
092:                java.util.List list;
093:                try {
094:                    list = (java.util.List) userManager.getUsersByRol(rol);
095:                    for (int i = 0; i < list.size(); i++) {
096:                        listModel.addElement(list.get(i));
097:                    }
098:                    listUsers = new JList(listModel);
099:
100:                } catch (Exception e) {
101:                    new ShowExceptionMessageDialog(LanguageTraslator
102:                            .traslate("441"), e);
103:                }
104:            }
105:
106:            /**
107:             *obtiene los usuario disponibles para agregarse  a un rol
108:             * @return ArrayList
109:             */
110:            private ArrayList getUsersAvailable() {
111:                ArrayList list = new ArrayList();
112:                Object[] o;
113:                boolean flag;
114:
115:                try {
116:                    o = userManager.getUsers().toArray();
117:                    if (listModel.size() == 0) {
118:                        list.addAll(userManager.getUsers());
119:                        return list;
120:                    }
121:
122:                    for (int i = 0; i < userManager.getUsers().size(); i++) {
123:                        flag = false;
124:
125:                        for (int j = 0; j < listModel.size(); j++) {
126:                            if (((User) o[i])
127:                                    .compareTo((User) listModel.get(j)) == 0) {
128:                                flag = true;
129:                            }
130:                        }
131:                        if (flag != true) {
132:                            list.add(o[i]);
133:                        }
134:                    }
135:                }
136:
137:                catch (Exception e) {
138:                    new ShowExceptionMessageDialog(LanguageTraslator
139:                            .traslate("433"), e);
140:                }
141:                return list;
142:            }
143:
144:            public void setTitulo(String titulo) {
145:                setTitle(titulo);
146:            }
147:
148:            private void initComponents() {
149:                jPanel1 = new JPanel();
150:                jTextFieldRolId = new JTextField();
151:                JLabelRolId = new JLabel();
152:                jLabelUsers = new JLabel();
153:
154:                add = new JButton();
155:                del = new JButton();
156:                accept = new JButton();
157:                cancel = new JButton();
158:
159:                getContentPane().setLayout(new AbsoluteLayout());
160:
161:                setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
162:                jPanel1.setLayout(new AbsoluteLayout());
163:
164:                jPanel1.add(jTextFieldRolId, new AbsoluteConstraints(80, 10,
165:                        210, -1));
166:
167:                JLabelRolId.setText(LanguageTraslator.traslate("426"));
168:                jPanel1.add(JLabelRolId,
169:                        new AbsoluteConstraints(10, 10, 80, 20));
170:
171:                jLabelUsers.setText(LanguageTraslator.traslate("418"));
172:                jPanel1.add(jLabelUsers,
173:                        new AbsoluteConstraints(10, 35, 80, 20));
174:
175:                add.setText(LanguageTraslator.traslate("130"));
176:
177:                jPanel1.add(add, new AbsoluteConstraints(300, 35, 80, 25));
178:
179:                del.setText(LanguageTraslator.traslate("421"));
180:                jPanel1.add(del, new AbsoluteConstraints(300, 65, 80, 25));
181:
182:                accept.setText(LanguageTraslator.traslate("112"));
183:                jPanel1.add(accept, new AbsoluteConstraints(80, 275, 85, 25));
184:
185:                cancel.setText(LanguageTraslator.traslate("113"));
186:                jPanel1.add(cancel, new AbsoluteConstraints(205, 275, 85, 25));
187:
188:                getContentPane().add(jPanel1,
189:                        new AbsoluteConstraints(0, 0, 390, 310));
190:
191:                Dimension scrn = getToolkit().getScreenSize();
192:
193:                this .setLocation((scrn.width - getWidth()) / 3 + 80,
194:                        (scrn.height - getHeight()) / 3 + 80);
195:
196:                cancel.addActionListener(new ButtonListener());
197:
198:                pack();
199:            }
200:
201:            /**
202:             * agrega o elimina los usuarios de la lista al userManager
203:             */
204:            private void addUsersToRol() throws InfoException {
205:                java.util.List list;
206:                ArrayList repositoryUserAdd = new ArrayList();
207:                ArrayList repositoyUserRemove = new ArrayList();
208:
209:                try {
210:
211:                    list = userManager.getUsersByRol(rol);
212:                } catch (Exception e) {
213:                    throw new InfoException(LanguageTraslator.traslate("441"),
214:                            e);
215:                }
216:
217:                for (int i = 0; i < listModel.size(); i++) {
218:                    if (!list.contains(listModel.getElementAt(i))) {
219:                        //el elemento de la lista, no está en userManager, entonces lo agrego a la lista a agregar
220:                        repositoryUserAdd.add((User) listModel.getElementAt(i));
221:                    }
222:                }
223:
224:                for (int j = 0; j < list.size(); j++) {
225:                    if (!listModel.contains(list.get(j))) {
226:                        //agrega los elementos usuario que no tiene el rol al userManager
227:                        repositoyUserRemove.add((User) list.get(j));
228:                    }
229:                }
230:
231:                for (int i = 0; i < repositoryUserAdd.size(); i++) {
232:                    try {
233:                        userManager.addUsersToCollectionRol(rol,
234:                                (User) repositoryUserAdd.get(i));
235:                    } catch (Exception e) {
236:                        new InfoException(LanguageTraslator.traslate("442")
237:                                + " " + (User) repositoryUserAdd.get(i), e);
238:                    }
239:                }
240:
241:                for (int i = 0; i < repositoyUserRemove.size(); i++) {
242:                    try {
243:                        userManager.removeRolToUser(rol,
244:                                (User) repositoyUserRemove.get(i));
245:                    } catch (Exception e) {
246:                        throw new InfoException(LanguageTraslator
247:                                .traslate("436")
248:                                + " " + (User) repositoyUserRemove.get(i), e);
249:                    }
250:                }
251:            }
252:
253:            /**
254:             * verifica los campo vacios
255:             * @param jLabel
256:             * @param jLabel
257:             * @return
258:             */
259:            private boolean emptyTextField(JTextField jTextField, JLabel jLabel) {
260:                if (jTextField.getText().length() == 0) {
261:                    JOptionPane.showMessageDialog(null, LanguageTraslator
262:                            .traslate("422")
263:                            + " " + jLabel.getText());
264:                    return true;
265:                }
266:                return false;
267:            }
268:
269:            class ButtonListener implements  ActionListener {
270:
271:                public ButtonListener() {
272:                }
273:
274:                public void actionPerformed(ActionEvent e) {
275:
276:                    if (e.getSource() == cancel) {
277:                        setVisible(false);
278:
279:                        //ACEPTA AGREGAR ROL NUEVO
280:                    } else if (e.getSource() == accept && rol == null) {
281:
282:                        acceptNewRol();
283:
284:                        //ACEPTA MODIFICAR ROL
285:                    } else if (e.getSource() == accept && rol != null) {
286:                        try {
287:                            addUsersToRol();
288:                        } catch (InfoException el) {
289:                            new ShowExceptionMessageDialog(LanguageTraslator
290:                                    .traslate("446"), el);
291:                        }
292:                        setVisible(false);
293:
294:                        //AGREGO UN USUARIO A LA LISTA DEL ROL
295:                    } else if (e.getSource() == add) {
296:                        addUserToListRol();
297:
298:                        //ELIMINAR UN USUARIO DE LA LISTA DEL ROL
299:                    } else if (e.getSource() == del
300:                            && listUsers.getSelectedValues().length > 0) {
301:                        delUserToListRol();
302:
303:                    }
304:                }
305:
306:            }
307:
308:            /**
309:             * invoca un AddUsertoRolFrame, frame para agregar usuarios a la lista, del rol
310:             */
311:            private void addUserToListRol() {
312:                if (getUsersAvailable().size() > 0) {
313:
314:                    AddUsertoRolFrame dialog = new AddUsertoRolFrame(this ,
315:                            getUsersAvailable());
316:                    dialog.setTitle(LanguageTraslator.traslate("427"));
317:                    dialog.setVisible(true);
318:
319:                    if (dialog.getUsers() != null) {
320:                        for (int i = 0; i < dialog.getUsers().length; i++) {
321:                            listModel.addElement((User) dialog.getUsers()[i]);
322:                        }
323:                    }
324:                } else {
325:                    JOptionPane.showMessageDialog(null, LanguageTraslator
326:                            .traslate("450"));
327:                }
328:            }
329:
330:            /**
331:             * elimina usuario de la lista del rol
332:             */
333:            private void delUserToListRol() {
334:                while (listUsers.getSelectedValues().length > 0) {
335:                    listModel.removeElement((User) listUsers
336:                            .getSelectedValues()[0]);
337:                }
338:            }
339:
340:            /**
341:             * metodo privado que se invoca cuando el usuario acepta agregar un nuevo rol
342:             */
343:            private void acceptNewRol() {
344:                if (emptyTextField(jTextFieldRolId, JLabelRolId)) {
345:                    return;
346:                }
347:
348:                rol = new Rol(jTextFieldRolId.getText(), jTextFieldRolId
349:                        .getText());
350:
351:                try {
352:                    userManager.addRol(rol);
353:                } catch (Exception e) {
354:                    new ShowExceptionMessageDialog(LanguageTraslator
355:                            .traslate("444"), e);
356:                    rol = null;
357:                    return;
358:                }
359:                addUsersToNewRol();
360:                setVisible(false);
361:            }
362:
363:            /**
364:             * metodo privado para agregar usuarios a la lista del nuevo rol
365:             */
366:            private void addUsersToNewRol() {
367:                int i = 0;
368:                try {
369:                    for (i = 0; i < listModel.size(); i++) {
370:                        userManager.addUsersToCollectionRol(rol,
371:                                (User) listModel.getElementAt(i));
372:                    }
373:                } catch (Exception e) {
374:                    new ShowExceptionMessageDialog(LanguageTraslator
375:                            .traslate("442")
376:                            + " " + (User) listModel.getElementAt(i), e);
377:                }
378:            }
379:
380:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.