Source Code Cross Referenced for TestChooser.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » docXML » common » 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 » salomeTMF_plug.docXML.common 
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 Aurore PENAULT
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package salomeTMF_plug.docXML.common;
025:
026:        import java.awt.BorderLayout;
027:        import java.awt.Container;
028:        import java.awt.Dimension;
029:        import java.awt.Rectangle;
030:        import java.awt.event.ActionEvent;
031:        import java.awt.event.ActionListener;
032:        import java.util.ArrayList;
033:        import java.util.Iterator;
034:
035:        import javax.swing.BorderFactory;
036:        import javax.swing.Box;
037:        import javax.swing.BoxLayout;
038:        import javax.swing.JButton;
039:        import javax.swing.JDialog;
040:        import javax.swing.JOptionPane;
041:        import javax.swing.JPanel;
042:        import javax.swing.JScrollPane;
043:        import javax.swing.JTree;
044:        import javax.swing.event.TreeSelectionEvent;
045:        import javax.swing.event.TreeSelectionListener;
046:        import javax.swing.tree.DefaultMutableTreeNode;
047:        import javax.swing.tree.DefaultTreeModel;
048:        import javax.swing.tree.TreePath;
049:
050:        import org.objectweb.salome_tmf.data.Campaign;
051:        import org.objectweb.salome_tmf.data.DataConstants;
052:        import org.objectweb.salome_tmf.data.Execution;
053:        import org.objectweb.salome_tmf.data.Family;
054:        import org.objectweb.salome_tmf.data.Test;
055:        import org.objectweb.salome_tmf.data.TestList;
056:        import org.objectweb.salome_tmf.ihm.models.TestTreeModel;
057:        import org.objectweb.salome_tmf.ihm.models.TreeRenderer;
058:        import org.objectweb.salome_tmf.ihm.tools.Tools;
059:
060:        import salomeTMF_plug.docXML.languages.Language;
061:
062:        /**
063:         * Classe qui construit la fenêtre permettant de choisir les tests à insérer 
064:         * dans la documentation
065:         * @author vapu8214
066:         */
067:        public class TestChooser extends JDialog implements  DataConstants {
068:            /**
069:             * Modèle de l'arbre des tests
070:             */
071:            protected TestTreeModel testTreeModel;
072:
073:            /**
074:             * Modèle de l'arbre des tests sélectionnés
075:             */
076:            protected TestTreeModel chosenTreeModel;
077:
078:            /**
079:             * l'arbre des tests choisis
080:             */
081:            JTree chosenTree;
082:
083:            /**
084:             * l'arbre des tests
085:             */
086:            JTree testTree;
087:
088:            /**
089:             * Noeud sélectionné dans l'arbre des tests choisis
090:             */
091:            DefaultMutableTreeNode chosenSelectedNode;
092:
093:            /**
094:             * Noeud sélectionné dans l'arbre des tests
095:             */
096:            DefaultMutableTreeNode testSelectedNode;
097:
098:            /**
099:             * Racine de l'arbre temporaire des tests choisis
100:             */
101:            DefaultMutableTreeNode temporaryChosenRootNode;
102:
103:            /**
104:             * Liste des campagnes sélectionnées
105:             */
106:            private ArrayList<Campaign> temporaryCampList;
107:
108:            /**
109:             * Liste des exécutions sélectionnées
110:             */
111:            private ArrayList<Execution> temporaryExecList;
112:
113:            /**
114:             * Liste des tests sélectionnés
115:             */
116:            private ArrayList<Test> temporaryTestList;
117:
118:            /**
119:             * Liste des suites sélectionnées
120:             */
121:            private ArrayList<TestList> temporaryTestListList;
122:
123:            /**
124:             * Liste des familles sélectionnées
125:             */
126:            private ArrayList<Family> temporaryFamilyList;
127:
128:            private ArrayList<DefaultMutableTreeNode> testSelectedNodes;
129:
130:            private ArrayList<DefaultMutableTreeNode> chosenSelectedNodes;
131:
132:            int sourceType;
133:
134:            private String errorMessage = "";
135:            private boolean cancelled = false;
136:
137:            /**
138:             * Constructeur de la fenêtre pour l'ajout de tests à la documentation.
139:             * @param chosenRoot le noeud racine de la liste des tests sélectionnés
140:             * @param model le modèle de données des tests
141:             * @param testRoot la racine de l'arbre des tests 
142:             * @param chosenRoot 
143:             */
144:            public TestChooser(DefaultMutableTreeNode testRoot, JDialog g,
145:                    boolean initSelection, DefaultMutableTreeNode chosenRoot,
146:                    int sourceType) throws Exception {
147:
148:                super (g, true);
149:
150:                this .sourceType = sourceType;
151:
152:                temporaryTestList = new ArrayList<Test>();
153:                temporaryTestListList = new ArrayList<TestList>();
154:                temporaryFamilyList = new ArrayList<Family>();
155:                temporaryCampList = new ArrayList<Campaign>();
156:
157:                chosenSelectedNodes = new ArrayList<DefaultMutableTreeNode>();
158:                testSelectedNodes = new ArrayList<DefaultMutableTreeNode>();
159:
160:                TreeRenderer chosenRenderer = new TreeRenderer();
161:                TreeRenderer testRenderer = new TreeRenderer();
162:
163:                if (initSelection) {
164:                    temporaryChosenRootNode = new DefaultMutableTreeNode(
165:                            chosenRoot.getUserObject());
166:                } else {
167:                    temporaryChosenRootNode = new DefaultMutableTreeNode(
168:                            testRoot.getUserObject());
169:                }
170:
171:                chosenSelectedNode = temporaryChosenRootNode;
172:                chosenTree = new JTree();
173:                chosenTreeModel = new TestTreeModel(temporaryChosenRootNode,
174:                        chosenTree, null);
175:                chosenTree.setModel(chosenTreeModel);
176:
177:                if (initSelection) {
178:                    initTemporaryTree(chosenRoot);
179:                }
180:
181:                chosenTree.setCellRenderer(chosenRenderer);
182:                chosenTree
183:                        .addTreeSelectionListener(new TreeSelectionListener() {
184:                            public void valueChanged(TreeSelectionEvent e) {
185:                                try {
186:                                    chosenSelectedNodes.clear();
187:                                    TreePath[] pathTab = chosenTree
188:                                            .getSelectionPaths();
189:                                    if (pathTab != null) {
190:                                        for (int i = 0; i < pathTab.length; i++) {
191:                                            chosenSelectedNodes
192:                                                    .add((DefaultMutableTreeNode) pathTab[i]
193:                                                            .getLastPathComponent());
194:                                        }
195:                                    }
196:                                } catch (Exception ex) {
197:                                    Tools.ihmExceptionView(ex);
198:                                }
199:                            }
200:                        });
201:
202:                testTree = new JTree();
203:                if (sourceType == CAMPAIGN) {
204:                    DefaultMutableTreeNode testRoot2 = cloneTree(testRoot);
205:                    testTreeModel = new TestTreeModel(testRoot2, testTree, null);
206:                } else {
207:                    testTreeModel = new TestTreeModel(testRoot, testTree, null);
208:                }
209:
210:                testTree.setModel(testTreeModel);
211:                testTree.setCellRenderer(testRenderer);
212:                testTree.addTreeSelectionListener(new TreeSelectionListener() {
213:                    public void valueChanged(TreeSelectionEvent e) {
214:                        try {
215:                            testSelectedNodes.clear();
216:                            TreePath[] pathTab = testTree.getSelectionPaths();
217:                            if (pathTab != null) {
218:                                for (int i = 0; i < pathTab.length; i++) {
219:                                    testSelectedNodes
220:                                            .add((DefaultMutableTreeNode) pathTab[i]
221:                                                    .getLastPathComponent());
222:                                }
223:                            }
224:                        } catch (Exception ex) {
225:                            Tools.ihmExceptionView(ex);
226:                        }
227:                    }
228:                });
229:
230:                JButton addButton = new JButton(">");
231:                addButton.setToolTipText(Language.getInstance().getText(
232:                        "Ajouter_à_la_sélection"));
233:                addButton.addActionListener(new ActionListener() {
234:                    public void actionPerformed(ActionEvent e) {
235:                        try {
236:                            for (int i = 0; i < testSelectedNodes.size(); i++) {
237:                                Object nodeValue = ((DefaultMutableTreeNode) testSelectedNodes
238:                                        .get(i)).getUserObject();
239:                                testSelectedNode = ((DefaultMutableTreeNode) testSelectedNodes
240:                                        .get(i));
241:                                if (TestChooser.this .sourceType == CAMPAIGN) {
242:                                    if (nodeValue instanceof  Campaign) {
243:                                        addNodeToNode(testSelectedNode,
244:                                                temporaryChosenRootNode);
245:                                    } else if (nodeValue instanceof  Execution) {
246:                                        DefaultMutableTreeNode campNode = findCampaignNodeInChosenTree(((Execution) nodeValue)
247:                                                .getCampagneFromModel()
248:                                                .getNameFromModel());
249:                                        if (campNode != null) {
250:                                            addNodeToNode(testSelectedNode,
251:                                                    campNode);
252:                                        } else {
253:                                            DefaultMutableTreeNode newCampNode = addObject(
254:                                                    temporaryChosenRootNode,
255:                                                    ((Execution) nodeValue)
256:                                                            .getCampagneFromModel(),
257:                                                    true);
258:                                            addNodeToNode(testSelectedNode,
259:                                                    newCampNode);
260:                                        }
261:                                    }
262:                                } else {
263:                                    if (nodeValue instanceof  Family) {
264:                                        addNodeToNode(testSelectedNode,
265:                                                temporaryChosenRootNode);
266:                                    } else if (nodeValue instanceof  TestList) {
267:                                        DefaultMutableTreeNode familyNode = findFamilyNodeInChosenTree(((TestList) nodeValue)
268:                                                .getFamilyFromModel()
269:                                                .getNameFromModel());
270:                                        if (familyNode != null) {
271:                                            addNodeToNode(testSelectedNode,
272:                                                    familyNode);
273:                                        } else {
274:                                            DefaultMutableTreeNode newFamilyNode = addObject(
275:                                                    temporaryChosenRootNode,
276:                                                    ((TestList) nodeValue)
277:                                                            .getFamilyFromModel(),
278:                                                    true);
279:                                            addNodeToNode(testSelectedNode,
280:                                                    newFamilyNode);
281:                                        }
282:                                    } else if (nodeValue instanceof  Test) {
283:                                        DefaultMutableTreeNode testListNode = findTestListNodeInChosenTree(
284:                                                ((Test) nodeValue)
285:                                                        .getTestListFromModel()
286:                                                        .getNameFromModel(),
287:                                                ((Test) nodeValue)
288:                                                        .getTestListFromModel()
289:                                                        .getFamilyFromModel()
290:                                                        .getNameFromModel());
291:                                        if (testListNode != null) {
292:                                            addNodeToNode(testSelectedNode,
293:                                                    testListNode);
294:                                        } else {
295:                                            DefaultMutableTreeNode familyNode = findFamilyNodeInChosenTree(((Test) nodeValue)
296:                                                    .getTestListFromModel()
297:                                                    .getFamilyFromModel()
298:                                                    .getNameFromModel());
299:                                            if (familyNode != null) {
300:                                                DefaultMutableTreeNode newListNode = addObject(
301:                                                        familyNode,
302:                                                        ((Test) nodeValue)
303:                                                                .getTestListFromModel(),
304:                                                        true);
305:                                                addNodeToNode(testSelectedNode,
306:                                                        newListNode);
307:                                            } else {
308:                                                DefaultMutableTreeNode newFamilyNode = addObject(
309:                                                        temporaryChosenRootNode,
310:                                                        ((Test) nodeValue)
311:                                                                .getTestListFromModel()
312:                                                                .getFamilyFromModel(),
313:                                                        true);
314:                                                DefaultMutableTreeNode newList = addObject(
315:                                                        newFamilyNode,
316:                                                        ((Test) nodeValue)
317:                                                                .getTestListFromModel(),
318:                                                        true);
319:                                                addNodeToNode(testSelectedNode,
320:                                                        newList);
321:                                            }
322:                                        }
323:                                    }
324:                                }
325:                            }
326:                        } catch (Exception ex) {
327:                            ex.printStackTrace();
328:                            errorMessage += Language.getInstance().getText(
329:                                    "Probleme_lors_de_la_selection_des_tests");
330:                            showErrorMessage();
331:                        }
332:                    }
333:                });
334:
335:                JButton removeButton = new JButton("<");
336:                removeButton.setToolTipText(Language.getInstance().getText(
337:                        "Retirer_de_la_sélection"));
338:                removeButton.addActionListener(new ActionListener() {
339:                    public void actionPerformed(ActionEvent e) {
340:                        try {
341:                            int i = chosenSelectedNodes.size() - 1;
342:                            boolean continu = true;
343:                            while (i >= 0 && continu) {
344:                                Object nodeValue = ((DefaultMutableTreeNode) chosenSelectedNodes
345:                                        .get(i)).getUserObject();
346:                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) chosenSelectedNodes
347:                                        .get(i);
348:                                if (nodeValue instanceof  Campaign
349:                                        || nodeValue instanceof  Execution
350:                                        || nodeValue instanceof  Family
351:                                        || nodeValue instanceof  TestList
352:                                        || nodeValue instanceof  Test) {
353:                                    ((DefaultTreeModel) chosenTree.getModel())
354:                                            .removeNodeFromParent(node);
355:                                    removeFromModel(node);
356:                                    i = chosenSelectedNodes.size() - 1;
357:                                } else {
358:                                    continu = false;
359:                                }
360:                            }
361:                        } catch (Exception ex) {
362:                            ex.printStackTrace();
363:                            errorMessage += Language.getInstance().getText(
364:                                    "Probleme_lors_de_la_selection_des_tests");
365:                            showErrorMessage();
366:                        }
367:                    }
368:                });
369:
370:                JPanel buttonSet = new JPanel();
371:                buttonSet.setLayout(new BoxLayout(buttonSet, BoxLayout.Y_AXIS));
372:                buttonSet.add(addButton);
373:                buttonSet.add(Box.createRigidArea(new Dimension(1, 25)));
374:                buttonSet.add(removeButton);
375:
376:                JScrollPane chosenScrollPane = new JScrollPane(chosenTree);
377:                chosenScrollPane.setBorder(BorderFactory
378:                        .createTitledBorder(Language.getInstance().getText(
379:                                "Sélection")));
380:                chosenScrollPane.setPreferredSize(new Dimension(300, 450));
381:
382:                JScrollPane testScrollPane = new JScrollPane(testTree);
383:                if (sourceType == CAMPAIGN) {
384:                    testScrollPane.setBorder(BorderFactory
385:                            .createTitledBorder(Language.getInstance().getText(
386:                                    "Campagnes")));
387:                } else {
388:                    testScrollPane.setBorder(BorderFactory
389:                            .createTitledBorder(Language.getInstance().getText(
390:                                    "Tests")));
391:                }
392:                testScrollPane.setPreferredSize(new Dimension(300, 450));
393:
394:                JPanel windowPanel = new JPanel();
395:                windowPanel.setLayout(new BoxLayout(windowPanel,
396:                        BoxLayout.X_AXIS));
397:                windowPanel.add(testScrollPane);
398:                windowPanel.add(Box.createRigidArea(new Dimension(20, 50)));
399:                windowPanel.add(buttonSet);
400:                windowPanel.add(Box.createRigidArea(new Dimension(20, 50)));
401:                windowPanel.add(chosenScrollPane);
402:
403:                JButton validate = new JButton(Language.getInstance().getText(
404:                        "Valider"));
405:                validate.setToolTipText(Language.getInstance().getText(
406:                        "Valider"));
407:                validate.addActionListener(new ActionListener() {
408:                    public void actionPerformed(ActionEvent e) {
409:                        try {
410:                            updateList();
411:                            TestChooser.this .dispose();
412:                        } catch (Exception ex) {
413:                            ex.printStackTrace();
414:                            errorMessage += Language.getInstance().getText(
415:                                    "Probleme_lors_de_la_selection_des_tests");
416:                            showErrorMessage();
417:                        }
418:                    }
419:                });
420:
421:                JButton cancel = new JButton(Language.getInstance().getText(
422:                        "Annuler"));
423:                cancel
424:                        .setToolTipText(Language.getInstance().getText(
425:                                "Annuler"));
426:                cancel.addActionListener(new ActionListener() {
427:                    public void actionPerformed(ActionEvent e) {
428:                        cancelled = true;
429:                        try {
430:                            TestChooser.this .dispose();
431:                        } catch (Exception ex) {
432:                            Tools.ihmExceptionView(ex);
433:                        }
434:                    }
435:                });
436:
437:                JPanel secondButtonSet = new JPanel();
438:                secondButtonSet.add(validate);
439:                secondButtonSet.add(cancel);
440:
441:                JPanel center = new JPanel();
442:                center.add(windowPanel);
443:
444:                JPanel page = new JPanel();
445:                page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
446:                page.add(center);
447:                page.add(secondButtonSet);
448:
449:                Container contentPaneFrame = this .getContentPane();
450:                contentPaneFrame.add(page, BorderLayout.CENTER);
451:                if (sourceType == CAMPAIGN) {
452:                    this .setTitle(Language.getInstance().getText(
453:                            "Ajouter_des_campagnes_à_la_sélection"));
454:                } else {
455:                    this .setTitle(Language.getInstance().getText(
456:                            "Ajouter_des_tests_à_la_sélection"));
457:                }
458:                //this.setLocation(300,200);
459:                centerScreen();
460:
461:            } // Fin du constructeur TestChooser
462:
463:            void centerScreen() {
464:                Dimension dim = getToolkit().getScreenSize();
465:                this .pack();
466:                Rectangle abounds = getBounds();
467:                setLocation((dim.width - abounds.width) / 2,
468:                        (dim.height - abounds.height) / 2);
469:                this .setVisible(true);
470:                requestFocus();
471:            }
472:
473:            /**
474:             * Clonage et modification de l'arbre des campagnes pour qu'il contienne les exécutions
475:             * @param testRoot noeud racine de l'arbre
476:             * @return noeud racine de l'arbre cloné et modifié
477:             */
478:            private DefaultMutableTreeNode cloneTree(
479:                    DefaultMutableTreeNode testRoot) throws Exception {
480:                DefaultMutableTreeNode result = (DefaultMutableTreeNode) testRoot
481:                        .clone();
482:                for (int j = 0; j < testRoot.getChildCount(); j++) {
483:                    DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) testRoot
484:                            .getChildAt(j);
485:                    Campaign campaign = (Campaign) childNode.getUserObject();
486:                    addObject(result, campaign, true);
487:                }
488:                for (int j = 0; j < result.getChildCount(); j++) {
489:                    DefaultMutableTreeNode campNode = (DefaultMutableTreeNode) result
490:                            .getChildAt(j);
491:                    if (campNode.getUserObject() instanceof  Campaign) {
492:                        campNode.removeAllChildren();
493:                        Campaign camp = (Campaign) campNode.getUserObject();
494:                        ArrayList<Execution> execList = camp
495:                                .getExecutionListFromModel();
496:                        if (!execList.isEmpty()) {
497:                            Iterator<Execution> it = execList.iterator();
498:                            while (it.hasNext()) {
499:                                Execution exec = it.next();
500:                                addObject(campNode, exec, true);
501:                            }
502:                        }
503:                    }
504:                }
505:                return result;
506:            }
507:
508:            /**
509:             * Méthode Récursive qui ajoute un noeud à un autre noeud. Tous les fils du 
510:             * noeud à ajouter sont aussi ajouter récursivement. 
511:             * @param nodeToBeAdded le noeud à ajouter
512:             * @param nodeToReceive le noeud qui reçoit
513:             */
514:            private void addNodeToNode(DefaultMutableTreeNode nodeToBeAdded,
515:                    DefaultMutableTreeNode nodeToReceive) throws Exception {
516:                DefaultMutableTreeNode newNode = null;
517:                for (int j = 0; j < nodeToReceive.getChildCount(); j++) {
518:                    if (((DefaultMutableTreeNode) nodeToReceive.getChildAt(j))
519:                            .getUserObject().equals(
520:                                    nodeToBeAdded.getUserObject())) {
521:                        newNode = (DefaultMutableTreeNode) nodeToReceive
522:                                .getChildAt(j);
523:                    }
524:                }
525:                if (newNode == null) {
526:                    newNode = new DefaultMutableTreeNode(nodeToBeAdded
527:                            .getUserObject());
528:                    chosenTreeModel.insertNodeInto(newNode, nodeToReceive,
529:                            nodeToReceive.getChildCount());
530:                    chosenTree.scrollPathToVisible(new TreePath(newNode
531:                            .getPath()));
532:                    if (nodeToBeAdded.getUserObject() instanceof  Family) {
533:                        temporaryFamilyList.add((Family) nodeToBeAdded
534:                                .getUserObject());
535:                    } else if (nodeToBeAdded.getUserObject() instanceof  TestList) {
536:                        temporaryTestListList.add((TestList) nodeToBeAdded
537:                                .getUserObject());
538:                    } else if (nodeToBeAdded.getUserObject() instanceof  Test) {
539:                        temporaryTestList.add((Test) nodeToBeAdded
540:                                .getUserObject());
541:                    }
542:                }
543:                for (int i = 0; i < nodeToBeAdded.getChildCount(); i++) {
544:                    addNodeToNode((DefaultMutableTreeNode) nodeToBeAdded
545:                            .getChildAt(i), newNode);
546:                }
547:            } // Fin de la méthode addNodeToNode/2
548:
549:            /**
550:             * Méthode qui retourne le noeud correspondant à une campagne si le nom passé
551:             * en paramètre est le nom d'une campagne présente dans l'arbre des sélections
552:             * @param campName un nom
553:             * @return lengthnoeud correspondant à une campagne si lengthnom passé 
554:             * en paramètre est lengthnom d'une campagne présente dans l'arbre des sélections,
555:             * <code>null</code> sinon.
556:             */
557:            public DefaultMutableTreeNode findCampaignNodeInChosenTree(
558:                    String campName) throws Exception {
559:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
560:                        .getRoot();
561:                for (int j = 0; j < root.getChildCount(); j++) {
562:                    DefaultMutableTreeNode campNode = (DefaultMutableTreeNode) root
563:                            .getChildAt(j);
564:                    if (campNode.getUserObject() instanceof  Campaign
565:                            && ((Campaign) campNode.getUserObject())
566:                                    .getNameFromModel().equals(campName)) {
567:                        return campNode;
568:                    }
569:                }
570:                return null;
571:            } // Fin de la méthode findCampaignNode/1 
572:
573:            /**
574:             * Méthode qui retourne le noeud correspondant à une famille si le nom passé
575:             * en paramètre est le nom d'une famille présente dans l'arbre des sélections 
576:             * @param familyName un nom
577:             * @return le noeud correspondant à une famille si le nom passé
578:             * en paramètre est le nom d'une famille présente dans l'arbre des sélections,
579:             * <code>null</code> sinon.
580:             */
581:            public DefaultMutableTreeNode findFamilyNodeInChosenTree(
582:                    String familyName) throws Exception {
583:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
584:                        .getRoot();
585:                for (int j = 0; j < root.getChildCount(); j++) {
586:                    DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
587:                            .getChildAt(j);
588:                    if (familyNode.getUserObject() instanceof  Family
589:                            && ((Family) familyNode.getUserObject())
590:                                    .getNameFromModel().equals(familyName)) {
591:                        return familyNode;
592:                    }
593:                }
594:                return null;
595:            } // Fin de la méthode findFamilyNode/1
596:
597:            /**
598:             * Méthode qui retourne le noeud correspondant à une suite si le nom passé
599:             * en paramètre est le nom d'une suite présente dans l'arbre des sélections 
600:             * @param testListName un nom
601:             * @return le noeud correspondant à une famille si le nom passé
602:             * en paramètre est le nom d'une famille présente dans l'arbre des sélections,
603:             * <code>null</code> sinon. 
604:             */
605:            public DefaultMutableTreeNode findTestListNodeInChosenTree(
606:                    String testListName, String familyName) throws Exception {
607:                DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
608:                        .getRoot();
609:                for (int j = 0; j < root.getChildCount(); j++) {
610:                    DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
611:                            .getChildAt(j);
612:                    if (familyNode.getUserObject() instanceof  Family
613:                            && ((Family) familyNode.getUserObject())
614:                                    .getNameFromModel().equals(familyName)) {
615:                        for (int k = 0; k < familyNode.getChildCount(); k++) {
616:                            DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
617:                                    .getChildAt(k);
618:                            if (testListNode.getUserObject() instanceof  TestList
619:                                    && ((TestList) testListNode.getUserObject())
620:                                            .getNameFromModel().equals(
621:                                                    testListName)) {
622:                                return testListNode;
623:                            }
624:                        }
625:                    }
626:                }
627:                return null;
628:            } // Fin de la méthode findFamilyNode/1
629:
630:            /**
631:             * Méthode d'ajout d'un noeud dans l'arbre sous le parent.
632:             * @param parent le parent 
633:             * @param child le noeud à ajouter
634:             * @param shouldBeVisible visible ou non
635:             * @return le nouveau noeud de l'arbre
636:             */
637:            public DefaultMutableTreeNode addObject(
638:                    DefaultMutableTreeNode parent, Object child,
639:                    boolean shouldBeVisible) throws Exception {
640:
641:                DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
642:                        child);
643:                if (parent == null) {
644:                    parent = temporaryChosenRootNode;
645:                }
646:
647:                // Insertion du noeud
648:                chosenTreeModel.insertNodeInto(childNode, parent, parent
649:                        .getChildCount());
650:
651:                // on s'assure que le noeud est visible
652:                if (shouldBeVisible) {
653:                    chosenTree.scrollPathToVisible(new TreePath(childNode
654:                            .getPath()));
655:                }
656:                return childNode;
657:            } // Fin de la classe addObject/3
658:
659:            /**
660:             * Supprime du modèle les éléments retirés de la sélection.
661:             * @param node le noeud à partir duquel on retire les éléments
662:             */
663:            private void removeFromModel(DefaultMutableTreeNode node)
664:                    throws Exception {
665:                for (int i = 0; i < node.getChildCount(); i++) {
666:                    removeFromModel((DefaultMutableTreeNode) node.getChildAt(i));
667:                }
668:                if (node.getUserObject() instanceof  Family) {
669:                    temporaryFamilyList.remove(node.getUserObject());
670:                } else if (node.getUserObject() instanceof  TestList) {
671:                    temporaryTestListList.remove(node.getUserObject());
672:                } else if (node.getUserObject() instanceof  Test) {
673:                    temporaryTestList.remove(node.getUserObject());
674:                }
675:            } // Fin de la méthode removeFromModel/1
676:
677:            /**
678:             * Méthode qui initialise l'arbre temporaire à partir de la racine passé
679:             * en paramètre. 
680:             * @param root la racine du nouvel arbre temporaire
681:             */
682:            public void initTemporaryTree(DefaultMutableTreeNode root)
683:                    throws Exception {
684:                for (int i = 0; i < root.getChildCount(); i++) {
685:                    addNodeToNode((DefaultMutableTreeNode) root.getChildAt(i),
686:                            temporaryChosenRootNode);
687:                }
688:            } // Fin de la méthode initTemporaryTree/1
689:
690:            public void updateList() throws Exception {
691:                if (sourceType == CAMPAIGN) {
692:                    temporaryCampList = new ArrayList<Campaign>();
693:                    temporaryExecList = new ArrayList<Execution>();
694:                    temporaryTestList = null;
695:                    temporaryTestListList = null;
696:                    temporaryFamilyList = null;
697:                    DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
698:                            .getRoot();
699:                    for (int j = 0; j < root.getChildCount(); j++) {
700:                        DefaultMutableTreeNode campNode = (DefaultMutableTreeNode) root
701:                                .getChildAt(j);
702:                        if (campNode.getUserObject() instanceof  Campaign) {
703:                            temporaryCampList.add((Campaign) campNode
704:                                    .getUserObject());
705:                            for (int k = 0; k < campNode.getChildCount(); k++) {
706:                                DefaultMutableTreeNode execNode = (DefaultMutableTreeNode) campNode
707:                                        .getChildAt(k);
708:                                if (execNode.getUserObject() instanceof  Execution) {
709:                                    temporaryExecList.add((Execution) execNode
710:                                            .getUserObject());
711:                                }
712:                            }
713:                        }
714:                    }
715:                } else {
716:                    temporaryTestList = new ArrayList<Test>();
717:                    temporaryTestListList = new ArrayList<TestList>();
718:                    temporaryFamilyList = new ArrayList<Family>();
719:                    temporaryCampList = null;
720:                    temporaryExecList = null;
721:                    DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
722:                            .getRoot();
723:                    for (int j = 0; j < root.getChildCount(); j++) {
724:                        DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
725:                                .getChildAt(j);
726:                        if (familyNode.getUserObject() instanceof  Family) {
727:                            temporaryFamilyList.add((Family) familyNode
728:                                    .getUserObject());
729:                            for (int k = 0; k < familyNode.getChildCount(); k++) {
730:                                DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
731:                                        .getChildAt(k);
732:                                if (testListNode.getUserObject() instanceof  TestList) {
733:                                    temporaryTestListList
734:                                            .add((TestList) testListNode
735:                                                    .getUserObject());
736:                                    for (int l = 0; l < testListNode
737:                                            .getChildCount(); l++) {
738:                                        DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) testListNode
739:                                                .getChildAt(l);
740:                                        if (testNode.getUserObject() instanceof  Test) {
741:                                            temporaryTestList
742:                                                    .add((Test) testNode
743:                                                            .getUserObject());
744:                                        }
745:                                    }
746:                                }
747:                            }
748:                        }
749:                    }
750:                }
751:            }
752:
753:            /**
754:             * Méthode qui affiche les messages d'erreur
755:             * @return
756:             */
757:            public void showErrorMessage() {
758:                JOptionPane.showMessageDialog(TestChooser.this , errorMessage,
759:                        Language.getInstance().getText("Erreur_!"),
760:                        JOptionPane.ERROR_MESSAGE);
761:                TestChooser.this .dispose();
762:            }
763:
764:            public ArrayList<Test> getTemporaryTestList() {
765:                return temporaryTestList;
766:            }
767:
768:            public ArrayList<TestList> getTemporaryTestListList() {
769:                return temporaryTestListList;
770:            }
771:
772:            public ArrayList<Family> getTemporaryFamilyList() {
773:                return temporaryFamilyList;
774:            }
775:
776:            public TestTreeModel getChosenTreeModel() {
777:                return chosenTreeModel;
778:            }
779:
780:            public ArrayList<Campaign> getTemporaryCampList() {
781:                return temporaryCampList;
782:            }
783:
784:            public ArrayList<Execution> getTemporaryExecList() {
785:                return temporaryExecList;
786:            }
787:
788:            public boolean isCancelled() {
789:                return cancelled;
790:            }
791:
792:            public void setCancelled(boolean cancelled) {
793:                this .cancelled = cancelled;
794:            }
795:        } // Fin de la classe TestChooser
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.