Source Code Cross Referenced for GroupAccess.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » ihm » 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 » Test Coverage » salome tmf » org.objectweb.salome_tmf.ihm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.ihm;
025:
026:        import java.awt.Color;
027:        import java.awt.Component;
028:        import java.awt.Container;
029:        import java.awt.Dimension;
030:        import java.awt.FlowLayout;
031:        import java.awt.Frame;
032:        import java.awt.event.ActionEvent;
033:        import java.awt.event.ActionListener;
034:        import java.awt.event.MouseAdapter;
035:        import java.awt.event.MouseEvent;
036:        import java.awt.event.WindowEvent;
037:        import java.awt.event.WindowListener;
038:        import java.util.EventObject;
039:
040:        import javax.swing.BoxLayout;
041:        import javax.swing.JButton;
042:        import javax.swing.JCheckBox;
043:        import javax.swing.JDialog;
044:        import javax.swing.JPanel;
045:        import javax.swing.JScrollPane;
046:        import javax.swing.JTabbedPane;
047:        import javax.swing.JTree;
048:        import javax.swing.event.CellEditorListener;
049:        import javax.swing.tree.DefaultMutableTreeNode;
050:        import javax.swing.tree.DefaultTreeModel;
051:        import javax.swing.tree.TreeCellEditor;
052:        import javax.swing.tree.TreeCellRenderer;
053:
054:        import org.objectweb.salome_tmf.data.Group;
055:        import org.objectweb.salome_tmf.ihm.languages.Language;
056:
057:        /**
058:         * Classe qui permet de cr?er une fen?tre peremttant de g?rer les droits des
059:         * groupes.
060:
061:         */
062:        public class GroupAccess extends JDialog {
063:
064:            /**
065:             * Le noeud s?lectionn?
066:             */
067:            DefaultMutableTreeNode selectedNode;
068:
069:            //Tests
070:            /**
071:             * La check box racine de l'arbre des tests
072:             */
073:            JCheckBox testCheckroot;
074:
075:            /**
076:             * la racine de l'arbre pour les tests
077:             */
078:            DefaultMutableTreeNode testRootNode;
079:
080:            /**
081:             * Mod?le de l'arbre pour les tests
082:             */
083:            DefaultTreeModel testModel;
084:
085:            /**
086:             * Arbre pour les tests
087:             */
088:            JTree testTree;
089:
090:            // Campagne
091:            /**
092:             * La checkBox racine de l'arbre des campagnes
093:             */
094:            JCheckBox campagneCheckroot;
095:
096:            /**
097:             * La racine de l'arbre des campagnes
098:             */
099:            DefaultMutableTreeNode campagneRootNode;
100:
101:            /**
102:             * Mod?le de donn?es pour l'arbre des campagnes
103:             */
104:            DefaultTreeModel campagneModel;
105:
106:            /**
107:             * L'arbre des campagnes
108:             */
109:            JTree campagneTree;
110:
111:            //Admin
112:            /**
113:             * La checkBox racine de l'arbre de l'admin
114:             */
115:            JCheckBox adminCheckroot;
116:
117:            /**
118:             * La racine de l'arbre d'administration
119:             */
120:            DefaultMutableTreeNode adminRootNode;
121:
122:            /**
123:             * Le mod?le de donn?es de l'arbre d'administration
124:             */
125:            DefaultTreeModel adminModel;
126:
127:            /**
128:             * Arbre d'administration
129:             */
130:            JTree adminTree;
131:
132:            /**
133:             * Tableau des permissions pour les suites de tests
134:             */
135:            boolean[] permissionsOfTest;
136:
137:            /**
138:             * Tableau pour les permissions pour les campagnes
139:             */
140:            boolean[] permissionsOfCampaign;
141:
142:            /**
143:             * Groupe courant
144:             */
145:            Group observedGroup;
146:
147:            /******************************************************************************/
148:            /** 							CONSTRUCTEUR								***/
149:            /******************************************************************************/
150:
151:            /**
152:             * Le constructeur de la vue sur les droits des groupes
153:             */
154:            public GroupAccess(boolean modify, Group group, Frame owner,
155:                    boolean canBeModified) {
156:
157:                super (owner, true);
158:                testCheckroot = new JCheckBox(Language.getInstance().getText(
159:                        "Toutes_les_permissions"));
160:                testRootNode = new DefaultMutableTreeNode(testCheckroot);
161:                testModel = new DefaultTreeModel(testRootNode);
162:                testTree = new JTree(testModel);
163:                campagneCheckroot = new JCheckBox(Language.getInstance()
164:                        .getText("Toutes_les_permissions"));
165:                campagneRootNode = new DefaultMutableTreeNode(campagneCheckroot);
166:                campagneModel = new DefaultTreeModel(campagneRootNode);
167:                campagneTree = new JTree(campagneModel);
168:                //		adminCheckroot = new JCheckBox("Toutes les permissions");
169:                //		adminRootNode = new DefaultMutableTreeNode(adminCheckroot);
170:                //		adminModel = new DefaultTreeModel(adminRootNode);
171:                //		adminTree = new JTree(adminModel);
172:                JTabbedPane tabs = new JTabbedPane();
173:                JPanel tests = new JPanel();
174:                tests.setLayout(new BoxLayout(tests, BoxLayout.Y_AXIS));
175:                JPanel campagne = new JPanel();
176:                campagne.setLayout(new BoxLayout(campagne, BoxLayout.Y_AXIS));
177:                JPanel admin = new JPanel();
178:                admin.setLayout(new BoxLayout(admin, BoxLayout.Y_AXIS));
179:                permissionsOfTest = new boolean[3];
180:                permissionsOfCampaign = new boolean[4];
181:
182:                // Onglets
183:                tabs.addTab(Language.getInstance().getText("Suites_de_test"),
184:                        tests);
185:                tabs.addTab(Language.getInstance().getText("Campagne_de_test"),
186:                        campagne);
187:                //	tabs.addTab("Administration",	admin);
188:                tabs.setPreferredSize(new Dimension(500, 350));
189:
190:                JPanel buttonPanel = new JPanel(new FlowLayout(
191:                        FlowLayout.CENTER));
192:
193:                //tests.add(principalListPanel1,BorderLayout.WEST);
194:                if (canBeModified) {
195:                    JButton validateButton = new JButton(Language.getInstance()
196:                            .getText("Valider"));
197:                    validateButton.setToolTipText(Language.getInstance()
198:                            .getText("Valider"));
199:                    validateButton.addActionListener(new ActionListener() {
200:                        public void actionPerformed(ActionEvent e) {
201:                            for (int i = 0; i < testRootNode.getChildCount(); i++) {
202:                                JCheckBox box = (JCheckBox) ((DefaultMutableTreeNode) testRootNode
203:                                        .getChildAt(i)).getUserObject();
204:                                observedGroup.changeTestPermission(i, box
205:                                        .isSelected());
206:                            }
207:                            for (int i = 0; i < campagneRootNode
208:                                    .getChildCount(); i++) {
209:                                JCheckBox box = (JCheckBox) ((DefaultMutableTreeNode) campagneRootNode
210:                                        .getChildAt(i)).getUserObject();
211:                                observedGroup.changeCampaignPermission(i, box
212:                                        .isSelected());
213:                            }
214:                            GroupAccess.this .dispose();
215:                        }
216:                    });
217:                    buttonPanel.add(validateButton);
218:                }
219:
220:                JButton cancelButton = new JButton();
221:                if (canBeModified) {
222:                    cancelButton.setText(Language.getInstance().getText(
223:                            "Annuler"));
224:                    cancelButton.setToolTipText(Language.getInstance().getText(
225:                            "Annuler"));
226:                } else {
227:                    cancelButton.setText(Language.getInstance().getText(
228:                            "Fermer"));
229:                    cancelButton.setToolTipText(Language.getInstance().getText(
230:                            "Fermer_la_fenêtre"));
231:                }
232:
233:                cancelButton.addActionListener(new ActionListener() {
234:                    public void actionPerformed(ActionEvent e) {
235:                        observedGroup = null;
236:                        GroupAccess.this .dispose();
237:                    }
238:                });
239:
240:                buttonPanel.add(cancelButton);
241:
242:                // Arbre pour les permissions des tests
243:
244:                CheckBoxRenderer testRenderer = new CheckBoxRenderer();
245:                CheckBoxCellEditor testEditor = new CheckBoxCellEditor();
246:                createTestsTree(testRootNode);
247:
248:                testTree.setCellRenderer(testRenderer);
249:                testTree.setCellEditor(testEditor);
250:                if (modify) {
251:                    testTree.setEditable(true);
252:                } else {
253:                    testTree.setEditable(false);
254:                }
255:
256:                testTree.setRootVisible(true);
257:                testCheckroot.addMouseListener(new checkBoxMouseListener(
258:                        testTree));
259:                JScrollPane testTreeScrollPane = new JScrollPane(testTree);
260:
261:                tests.add(testTreeScrollPane);
262:
263:                // Arbre pour les permissions des campagnes
264:
265:                CheckBoxRenderer campagneRenderer = new CheckBoxRenderer();
266:                CheckBoxCellEditor campagneEditor = new CheckBoxCellEditor();
267:                createCampagneTree(campagneRootNode);
268:
269:                campagneTree.setCellRenderer(campagneRenderer);
270:                campagneTree.setCellEditor(campagneEditor);
271:                if (modify) {
272:                    campagneTree.setEditable(true);
273:                } else {
274:                    campagneTree.setEditable(false);
275:                }
276:
277:                campagneTree.setRootVisible(true);
278:                campagneCheckroot.addMouseListener(new checkBoxMouseListener(
279:                        campagneTree));
280:                JScrollPane campagneTreeScrollPane = new JScrollPane(
281:                        campagneTree);
282:
283:                campagne.add(campagneTreeScrollPane);
284:
285:                this .addWindowListener(new WindowListener() {
286:                    public void windowClosing(WindowEvent e) {
287:                        observedGroup = null;
288:                    }
289:
290:                    public void windowDeiconified(WindowEvent e) {
291:                    }
292:
293:                    public void windowOpened(WindowEvent e) {
294:                    }
295:
296:                    public void windowActivated(WindowEvent e) {
297:                    }
298:
299:                    public void windowDeactivated(WindowEvent e) {
300:                    }
301:
302:                    public void windowClosed(WindowEvent e) {
303:                    }
304:
305:                    public void windowIconified(WindowEvent e) {
306:                    }
307:                });
308:
309:                // Initialisation des donn?es
310:                initData(group);
311:
312:                // Affichage
313:                Container contentPaneFrame = this .getContentPane();
314:                contentPaneFrame.setLayout(new BoxLayout(contentPaneFrame,
315:                        BoxLayout.Y_AXIS));
316:                contentPaneFrame.add(tabs);
317:                contentPaneFrame.add(buttonPanel);
318:                this .setTitle(Language.getInstance().getText("Permissions"));
319:                this .setLocation(400, 300);
320:                this .pack();
321:                this .setVisible(true);
322:
323:            } // Fin du constructeur GroupAccess/0
324:
325:            /******************************************************************************/
326:            /** 							METHODES PUBLIQUES							***/
327:            /******************************************************************************/
328:
329:            /**
330:             * Cr?ation de l'arbre des tests
331:             * @param root la racine de l'arbre
332:             */
333:            private void createTestsTree(DefaultMutableTreeNode root) {
334:                String[] mainNodes = {
335:                        Language.getInstance().getText("Ajouter"),
336:                        Language.getInstance().getText("Modifier"),
337:                        Language.getInstance().getText("Supprimer") };
338:
339:                //		String[] listTestsModification = {"Nom de la suite", "Attachements", "Description", "Famille de tests", "Ordre de la suite"};
340:                //		String[] testsModification = {"Nom du test"};
341:                for (int i = 0; i < mainNodes.length; i++) {
342:                    JCheckBox box = new JCheckBox(mainNodes[i]);
343:                    box.addMouseListener(new checkBoxMouseListener(testTree));
344:                    DefaultMutableTreeNode node = new DefaultMutableTreeNode(
345:                            box, true);
346:                    root.add(node);
347:                    //
348:                }
349:                testModel.setRoot(root);
350:            } // Fin de la m?thode createTestsTree/1
351:
352:            /**
353:             * Cr?ation de l'arbre des campagnes
354:             * @param root la racine de l'arbre
355:             */
356:            private void createCampagneTree(DefaultMutableTreeNode root) {
357:                String[] mainNodes = {
358:                        Language.getInstance().getText("Ajouter"),
359:                        Language.getInstance().getText("Modifier"),
360:                        Language.getInstance().getText("Supprimer"),
361:                        Language.getInstance().getText("Exécuter") };
362:
363:                //		String[] listTestsModification = {"Nom de la suite", "Attachements", "Description", "Famille de tests", "Ordre de la suite"};
364:                //		String[] testsModification = {"Nom du test"};
365:                for (int i = 0; i < mainNodes.length; i++) {
366:                    JCheckBox box = new JCheckBox(mainNodes[i]);
367:                    box
368:                            .addMouseListener(new checkBoxMouseListener(
369:                                    campagneTree));
370:                    DefaultMutableTreeNode node = new DefaultMutableTreeNode(
371:                            box, true);
372:                    root.add(node);
373:                    //
374:                }
375:                campagneModel.setRoot(root);
376:            } // Fin de la m?thode createCampagneTree/1
377:
378:            /**
379:             * Cr?ation de l'arbre de l'administration
380:             * @param root la racine de l'arbre
381:             */
382:            /*private void createAdminTree(DefaultMutableTreeNode root) {
383:                String[] mainNodes = {"Ajouter un utilisateur", "Suprimer un utilisateur",
384:                "Ajouter un groupe", "Supprimer un groupe"};
385:                
386:                for (int i = 0; i < mainNodes.length; i ++) {
387:                    JCheckBox box = new JCheckBox(mainNodes[i]);
388:                    box.addMouseListener(new checkBoxMouseListener(adminTree));
389:                    
390:                    DefaultMutableTreeNode node = new DefaultMutableTreeNode(new JCheckBox(mainNodes[i]), true);
391:                    root.add(node);
392:                }
393:                adminModel.setRoot(root);
394:            } // Fin de la m?thode createAdminTree/1
395:             */
396:
397:            /**
398:             * Classe interne d?finissant le renderer de l'arbre (pour prendre en compte
399:             * les checkBox)
400:             * @author teaml039
401:             * @version : 0.1
402:             */
403:            class CheckBoxRenderer implements  TreeCellRenderer {
404:                /**
405:                 * Surcharge de la m?thode qui calcule le renderer des noeuds de
406:                 * l'arbre
407:                 */
408:                public Component getTreeCellRendererComponent(JTree tree,
409:                        Object obj, boolean selected, boolean expanded,
410:                        boolean leaf, int row, boolean hasFocus) {
411:
412:                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) obj;
413:
414:                    JCheckBox box = (JCheckBox) node.getUserObject();
415:                    box.setBackground(new Color(255, 255, 255));
416:                    return box;
417:                } // Fin de la m?thode getTreeCellRendererComponent/7
418:            } // Fin de la classe CheckBoxRenderer
419:
420:            /**
421:             * Classe interne qui d?finit un listener de la souris qui permet de
422:             * g?rer la s?lection des checkbox
423:             * @author teaml039
424:             * @version : 0.1
425:             */
426:            class checkBoxMouseListener extends MouseAdapter {
427:
428:                /**
429:                 * l'arbre de checkbox
430:                 */
431:                JTree _tree;
432:
433:                /**
434:                 * Constructeur du listener
435:                 * @param tree l'arbre sur lequel on place le listener
436:                 */
437:                public checkBoxMouseListener(JTree tree) {
438:                    _tree = tree;
439:                } // Fin du constructeur checkBoxMouseListener/1
440:
441:                /**
442:                 *  Appel?e lorsque l'on appuie sur un bouton de la souris
443:                 * @param e un ?v?nement relatif ? la souris
444:                 */
445:                public void mousePressed(MouseEvent e) {
446:                    maybeShowPopup(e);
447:                } // Fin de la m?thode mousePressed/1
448:
449:                /**
450:                 * Appel?e lorsque l'on relache un bouton de la souris
451:                 * @param e un ?v?nement relatif ? la souris
452:                 */
453:                public void mouseReleased(MouseEvent e) {
454:                    maybeShowPopup(e);
455:                } // Fin de la m?thode mouseReleased/1
456:
457:                /**
458:                 * Traite les diff?rents clics de la souris
459:                 * @param e un ?v?nement relatif ? la souris
460:                 */
461:                private void maybeShowPopup(MouseEvent e) {
462:                    DefaultMutableTreeNode node_actif = (DefaultMutableTreeNode) _tree
463:                            .getLastSelectedPathComponent();
464:                    if (e.getButton() == MouseEvent.BUTTON1) {
465:                        JCheckBox box = (JCheckBox) node_actif.getUserObject();
466:                        if (node_actif.getChildCount() > 0) {
467:                            changeCheckBoxValuesDown(node_actif);
468:                            ((DefaultTreeModel) _tree.getModel())
469:                                    .nodeChanged(node_actif);
470:                        }
471:                        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node_actif
472:                                .getParent();
473:
474:                        if (((JCheckBox) node_actif.getUserObject()).getText()
475:                                .equals(
476:                                        Language.getInstance().getText(
477:                                                "Supprimer"))) {
478:                            boolean value = ((JCheckBox) node_actif
479:                                    .getUserObject()).isSelected();
480:                            if (value) {
481:                                DefaultMutableTreeNode brother = node_actif
482:                                        .getPreviousNode();
483:                                ((JCheckBox) brother.getUserObject())
484:                                        .setSelected(value);
485:                                brother = brother.getPreviousNode();
486:                                ((JCheckBox) brother.getUserObject())
487:                                        .setSelected(value);
488:                            }
489:                        } else if (((JCheckBox) node_actif.getUserObject())
490:                                .getText().equals(
491:                                        Language.getInstance().getText(
492:                                                "Ajouter"))) {
493:                            boolean value = ((JCheckBox) node_actif
494:                                    .getUserObject()).isSelected();
495:                            if (value) {
496:                                DefaultMutableTreeNode brother = node_actif
497:                                        .getNextNode();
498:                                ((JCheckBox) brother.getUserObject())
499:                                        .setSelected(value);
500:                            } else {
501:                                DefaultMutableTreeNode brother = node_actif
502:                                        .getNextNode().getNextNode();
503:                                ((JCheckBox) brother.getUserObject())
504:                                        .setSelected(value);
505:                            }
506:                        } else if (((JCheckBox) node_actif.getUserObject())
507:                                .getText().equals(
508:                                        Language.getInstance().getText(
509:                                                "Modifier"))) {
510:                            boolean value = ((JCheckBox) node_actif
511:                                    .getUserObject()).isSelected();
512:                            if (!value) {
513:                                DefaultMutableTreeNode brother = node_actif
514:                                        .getPreviousNode();
515:                                ((JCheckBox) brother.getUserObject())
516:                                        .setSelected(value);
517:                                brother = node_actif.getNextNode();
518:                                ((JCheckBox) brother.getUserObject())
519:                                        .setSelected(value);
520:                            }
521:                        }
522:
523:                        if (!box.isSelected()) {
524:                            if (parent != null) {
525:                                //((JCheckBox)parent.getUserObject()).setSelected(false);
526:                                changeValueUp(parent);
527:                                ((DefaultTreeModel) _tree.getModel())
528:                                        .nodeChanged((DefaultMutableTreeNode) _tree
529:                                                .getModel().getRoot());
530:                            }
531:                        } else {
532:                            DefaultMutableTreeNode upNode = changeCheckBoxValuesUp(parent);
533:                            if (upNode != null) {
534:                                ((DefaultTreeModel) _tree.getModel())
535:                                        .nodeChanged(upNode);
536:                            } else {
537:                                ((DefaultTreeModel) _tree.getModel())
538:                                        .nodeChanged((DefaultMutableTreeNode) _tree
539:                                                .getModel().getRoot());
540:                            }
541:                        }
542:                    }
543:                } // Fin de la m?thode maybeShowPopup/1
544:
545:                /**
546:                 * M?thode qui permet de changer r?cursivement les valeurs des checkbox
547:                 * d'un noeud vers ses fils.
548:                 * @param node un noeud dont on change la valeur
549:                 */
550:                public void changeCheckBoxValuesDown(DefaultMutableTreeNode node) {
551:                    for (int i = 0; i < node.getChildCount(); i++) {
552:                        boolean value = ((JCheckBox) node.getUserObject())
553:                                .isSelected();
554:                        ((JCheckBox) ((DefaultMutableTreeNode) node
555:                                .getChildAt(i)).getUserObject())
556:                                .setSelected(value);
557:                        changeCheckBoxValuesDown((DefaultMutableTreeNode) node
558:                                .getChildAt(i));
559:                    }
560:                } // Fin de la m?thode changeCheckBoxValuesDown/1
561:
562:                /**
563:                 * Changement des valeurs des checkbox vers les parents lorsque l'on
564:                 * passe la valeur ? vrai
565:                 * @param parent le noeud
566:                 * @return le dernier noeud dans la remont?e
567:                 */
568:                public DefaultMutableTreeNode changeCheckBoxValuesUp(
569:                        DefaultMutableTreeNode parent) {
570:                    if (parent != null) {
571:                        int nb = 0;
572:                        for (int i = 0; i < parent.getChildCount(); i++) {
573:                            if (((JCheckBox) ((DefaultMutableTreeNode) parent
574:                                    .getChildAt(i)).getUserObject())
575:                                    .isSelected()) {
576:                                nb++;
577:                            }
578:                        }
579:                        if (nb == parent.getChildCount()) {
580:                            ((JCheckBox) parent.getUserObject())
581:                                    .setSelected(true);
582:                        }
583:                        return changeCheckBoxValuesUp((DefaultMutableTreeNode) parent
584:                                .getParent());
585:                    } else {
586:                        return null;
587:                    }
588:                } // Fin de la m?thode changeCheckBoxValuesUp/1
589:
590:                /**
591:                 * Changement des valeurs des checkbox vers les parents lorsque l'on
592:                 * passe la valeur ? faux
593:                 * @param parent un noeud
594:                 */
595:                public void changeValueUp(DefaultMutableTreeNode parent) {
596:                    ((JCheckBox) parent.getUserObject()).setSelected(false);
597:                    if (parent.getParent() != null) {
598:                        changeValueUp((DefaultMutableTreeNode) parent
599:                                .getParent());
600:                    }
601:                } // Fin de la m?thode changeValueUp/1
602:
603:            }// Fin de la classe checkBoxMouseListener
604:
605:            /**
606:             * Classe interne d?finissant un nouvel ?diteur pour l'arbre des checkbox
607:             * @author teaml039
608:             * @version : 0.1
609:             */
610:            class CheckBoxCellEditor implements  TreeCellEditor {
611:
612:                public void addCellEditorListener(CellEditorListener l) {
613:                }
614:
615:                public void cancelCellEditing() {
616:                }
617:
618:                /**
619:                 * Retourne la valeur contenue dans l'?diteur
620:                 * @return la valeur contenue dans l'?diteur
621:                 */
622:                public Object getCellEditorValue() {
623:                    return this ;
624:                } // Fin de la m?thode getCellEditorValue/0
625:
626:                /**
627:                 * Demande ? l'?diteur s'il peut commencer ? ?diter en utilisant un
628:                 * ?v?nement. On rend vrai, si on d?tecte un clic de souris, faux
629:                 * sinon.
630:                 * @param evt un ?v?nement
631:                 * @return vrai si on d?tecte un clic de souris, faux sinon.
632:                 */
633:                public boolean isCellEditable(EventObject evt) {
634:                    if (evt instanceof  MouseEvent) {
635:                        MouseEvent mevt = (MouseEvent) evt;
636:                        if (mevt.getClickCount() == 1) {
637:                            return true;
638:                        }
639:                    }
640:                    return false;
641:                } // Fin de la m?thode isCellEditable/1
642:
643:                public void removeCellEditorListener(CellEditorListener l) {
644:                }
645:
646:                /**
647:                 * Retourne vrai : la cellule doit toujours ?tre s?lectionn?e.
648:                 * @param anEvent un ?v?nement
649:                 * @return toujours vrai
650:                 */
651:                public boolean shouldSelectCell(EventObject anEvent) {
652:                    return true;
653:                } // Fin de la m?thode shouldSelectCell/1
654:
655:                /**
656:                 * Retourne faux : on ne peut pas emp?cher l'?dition
657:                 * @return toujours faux
658:                 */
659:                public boolean stopCellEditing() {
660:                    return false;
661:                } // Fin de la m?thode stopCellEditing/0
662:
663:                /**
664:                 * Donne une nouvelle valeur ? l'?diteur. Retourne le composant
665:                 * (checkbox) qui va ?tre ajout? dans l'arbre.
666:                 * @param	tree l'arbre des checkbox;
667:                 * @param	obj objet de la cellule devant ?tre ?diter
668:                 * @param	isSelected	vrai si la cellule est s?lectionn?e
669:                 * @param	expanded	vrai si le noeud est d?ploy?
670:                 * @param	leaf		vrai si le noeud est une feuille
671:                 * @param	row		l'indice de la ligne en cours d'?dition
672:                 */
673:                public Component getTreeCellEditorComponent(JTree tree,
674:                        Object obj, boolean isSelected, boolean expanded,
675:                        boolean leaf, int row) {
676:                    DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) obj;
677:                    JCheckBox box = (JCheckBox) dmtn.getUserObject();
678:                    box.setEnabled(true);
679:                    return box;
680:                } // Fin de la m?thode getTreeCellEditorComponent/7
681:            } // Fin de la classe CheckBoxCellEditor
682:
683:            /**
684:             * @return
685:             */
686:            public boolean[] getPermissionsOfCampaign() {
687:                return permissionsOfCampaign;
688:            }
689:
690:            /**
691:             * @return
692:             */
693:            public boolean[] getPermissionsOfTest() {
694:                return permissionsOfTest;
695:            }
696:
697:            private void initData(Group group) {
698:                observedGroup = group;
699:                boolean oneFalse = false;
700:                for (int i = 0; i < group.getTestsPermissions().length; i++) {
701:                    ((JCheckBox) ((DefaultMutableTreeNode) testRootNode
702:                            .getChildAt(i)).getUserObject()).setSelected(group
703:                            .getTestsPermissions()[i]);
704:                    if (!group.getTestsPermissions()[i]) {
705:                        oneFalse = true;
706:                    }
707:                }
708:                if (!oneFalse) {
709:                    ((JCheckBox) (testRootNode).getUserObject())
710:                            .setSelected(true);
711:                }
712:                for (int i = 0; i < group.getCampaignPermissions().length; i++) {
713:                    ((JCheckBox) ((DefaultMutableTreeNode) campagneRootNode
714:                            .getChildAt(i)).getUserObject()).setSelected(group
715:                            .getCampaignPermissions()[i]);
716:                    if (!group.getCampaignPermissions()[i]) {
717:                        oneFalse = true;
718:                    }
719:                }
720:                if (!oneFalse) {
721:                    ((JCheckBox) (campagneRootNode).getUserObject())
722:                            .setSelected(true);
723:                }
724:
725:            }
726:
727:            /**
728:             * @return
729:             */
730:            public Group getObservedGroup() {
731:                return observedGroup;
732:            }
733:
734:        } // Fin de la classe GroupAccess
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.