Source Code Cross Referenced for SelectReqTree.java in  » Test-Coverage » salome-tmf » salomeTMF_plug » requirements » 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 » salomeTMF_plug.requirements.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 Jean-Marie Hallouët
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package salomeTMF_plug.requirements.ihm;
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.awt.event.WindowEvent;
033:        import java.awt.event.WindowListener;
034:        import java.util.ArrayList;
035:        import java.util.Hashtable;
036:        import java.util.Vector;
037:
038:        import javax.swing.BorderFactory;
039:        import javax.swing.Box;
040:        import javax.swing.BoxLayout;
041:        import javax.swing.JButton;
042:        import javax.swing.JDialog;
043:        import javax.swing.JOptionPane;
044:        import javax.swing.JPanel;
045:        import javax.swing.JScrollPane;
046:        import javax.swing.JTree;
047:        import javax.swing.tree.DefaultMutableTreeNode;
048:        import javax.swing.tree.DefaultTreeModel;
049:        import javax.swing.tree.TreePath;
050:
051:        import org.objectweb.salome_tmf.api.Util;
052:        import org.objectweb.salome_tmf.data.DataConstants;
053:        import org.objectweb.salome_tmf.data.Family;
054:        import org.objectweb.salome_tmf.data.SimpleData;
055:        import org.objectweb.salome_tmf.data.Test;
056:        import org.objectweb.salome_tmf.data.TestList;
057:        import org.objectweb.salome_tmf.data.User;
058:        import org.objectweb.salome_tmf.ihm.languages.Language;
059:        import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
060:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
061:        import org.objectweb.salome_tmf.ihm.models.DynamicTree;
062:        import org.objectweb.salome_tmf.plugins.UICompCst;
063:
064:        import salomeTMF_plug.requirements.ReqPlugin;
065:        import salomeTMF_plug.requirements.data.GenTestTools;
066:        import salomeTMF_plug.requirements.data.ReqFamily;
067:        import salomeTMF_plug.requirements.data.ReqLeaf;
068:        import salomeTMF_plug.requirements.data.Requirement;
069:
070:        /**
071:         * 
072:         * @author Jean-Marie HALLOUËT
073:         *
074:         */
075:        public class SelectReqTree extends JDialog implements  ActionListener,
076:                DataConstants, WindowListener {
077:
078:            /* JDialog buttons */
079:            JButton removeButton;
080:            JButton addButton;
081:            JButton validateButton;
082:            JButton cancelButton;
083:
084:            /* Test tree */
085:            SimpleDynamicTestTree dynTestTree;
086:            DynamicTree pDynamicTree;
087:            Hashtable simpleDataCache = new Hashtable();
088:
089:            /* Original requirement trees */
090:            RequirementTree globalReqTree;
091:
092:            /* Jtrees used by the selection window  */
093:            JTree usedReqTree;
094:            JTree usedDynTestTree;
095:
096:            /* List of simpleData to remove from model */
097:            Vector simpleDataRemoved;
098:
099:            /**
100:             * Constructor
101:             * @param _reqTree the original requirement tree
102:             * @param title Window tiltle
103:             */
104:            public SelectReqTree(RequirementTree _reqTree, String title) {
105:                super (SalomeTMFContext.getInstance().getSalomeFrame());
106:                setResizable(false);
107:                setModal(true);
108:                Util.log("[requirements] -> SelectReqTree : start constructor");
109:                setDefaultCloseOperation(DISPOSE_ON_CLOSE);
110:                addWindowListener(this );
111:                /* Initialize list */
112:                simpleDataRemoved = new Vector();
113:
114:                /* Refresh DataModel */
115:                DataModel.reloadFromBase(true);
116:
117:                /* Load Requirement tree without links */
118:                usedReqTree = _reqTree.getCopy(true);
119:
120:                /* Keep requirement tree to check existence in base */
121:                globalReqTree = _reqTree;
122:                // TODO externaliser
123:                dynTestTree = new SimpleDynamicTestTree(Language.getInstance()
124:                        .getText("Plan_de_tests"), DataConstants.FAMILY);
125:                pDynamicTree = (DynamicTree) SalomeTMFContext.getInstance()
126:                        .getUIComponent(UICompCst.TEST_DYNAMIC_TREE);
127:                GenTestTools.initTools(_reqTree, pDynamicTree);
128:
129:                /* initialize trees */
130:                initTrees(false); // ADD By MM
131:
132:                usedDynTestTree = dynTestTree.getTree();
133:                initComponent(title);
134:
135:                Util.log("[requirements] -> SelectReqTree : end constructor");
136:            }
137:
138:            /**
139:             *  GUI initialization  
140:             * @param title Window title
141:             */
142:            void initComponent(String title) {
143:                Util
144:                        .log("[requirements] -> SelectReqTree : start initComponent");
145:                Util.log("[requirements] -> SelectReqTree : title : " + title);
146:                setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
147:                removeButton = new JButton("<");
148:                removeButton.addActionListener(this );
149:
150:                addButton = new JButton(">");
151:                addButton.addActionListener(this );
152:
153:                JPanel buttonSet = new JPanel();
154:                buttonSet.setLayout(new BoxLayout(buttonSet, BoxLayout.Y_AXIS));
155:                buttonSet.add(addButton);
156:                buttonSet.add(Box.createRigidArea(new Dimension(1, 25)));
157:                buttonSet.add(removeButton);
158:
159:                JScrollPane reqScrollPane = new JScrollPane(usedReqTree);
160:                reqScrollPane.setBorder(BorderFactory
161:                        .createTitledBorder(Language.getInstance().getText(
162:                                "Exigence_disponible")));
163:                reqScrollPane.setPreferredSize(new Dimension(300, 450));
164:
165:                JScrollPane selectedScrollPane = new JScrollPane(
166:                        usedDynTestTree);
167:                selectedScrollPane.setBorder(BorderFactory
168:                        .createTitledBorder("Test Plan"));
169:                selectedScrollPane.setPreferredSize(new Dimension(300, 450));
170:                selectedScrollPane.getViewport().setView(usedDynTestTree);
171:
172:                JPanel windowPanel = new JPanel();
173:                windowPanel.setLayout(new BoxLayout(windowPanel,
174:                        BoxLayout.X_AXIS));
175:                windowPanel.add(reqScrollPane);
176:                windowPanel.add(Box.createRigidArea(new Dimension(20, 50)));
177:                windowPanel.add(buttonSet);
178:                windowPanel.add(Box.createRigidArea(new Dimension(20, 50)));
179:                windowPanel.add(selectedScrollPane);
180:
181:                validateButton = new JButton(Language.getInstance().getText(
182:                        "Valider"));
183:                validateButton.addActionListener(this );
184:
185:                cancelButton = new JButton(Language.getInstance().getText(
186:                        "Annuler"));
187:                cancelButton.addActionListener(this );
188:
189:                JPanel secondButtonSet = new JPanel();
190:                secondButtonSet.add(validateButton);
191:                secondButtonSet.add(cancelButton);
192:                JPanel center = new JPanel();
193:                center.add(windowPanel);
194:                JPanel page = new JPanel();
195:                page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
196:                page.add(center);
197:                page.add(secondButtonSet);
198:                Container contentPaneFrame = this .getContentPane();
199:                contentPaneFrame.add(page, BorderLayout.CENTER);
200:
201:                this .setTitle(title);
202:                //this.setLocation(300,200);
203:                /*this.setLocationRelativeTo(this.getParent()); 
204:                this.pack();
205:                this.setVisible(true);
206:                 */
207:                centerScreen();
208:                Util.log("[requirements] -> SelectReqTree : end initComponent");
209:            }
210:
211:            void centerScreen() {
212:                Dimension dim = getToolkit().getScreenSize();
213:                this .pack();
214:                Rectangle abounds = getBounds();
215:                setLocation((dim.width - abounds.width) / 2,
216:                        (dim.height - abounds.height) / 2);
217:
218:                this .setVisible(true);
219:                requestFocus();
220:            }
221:
222:            /**
223:             * Build trees
224:             * @param reinit reinitialize tree if true
225:             */
226:            void initTrees(boolean reinit) {
227:                Util.log("[requirements] -> SelectReqTree : start initTrees("
228:                        + reinit + ") start");
229:                if (reinit) {
230:                    reInitReqTree();
231:                }
232:                DefaultMutableTreeNode pTempNode = globalReqTree
233:                        .getParentNode();
234:                dynTestTree.clear();
235:                GenTestTools.getBijectiveSimpleDataTree(pTempNode, dynTestTree);
236:                dynTestTree.getModel();
237:                ((DefaultTreeModel) dynTestTree.getModel()).reload();
238:
239:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((DefaultTreeModel) usedReqTree
240:                        .getModel()).getRoot();
241:                GenTestTools.removeReqBijectiveLinked(
242:                        (DefaultTreeModel) usedReqTree.getModel(), node);
243:
244:                expandAll(dynTestTree.getTree()); //ADD by MM
245:                expandAll(usedReqTree); //ADD by MM
246:                Util.log("[requirements] -> SelectReqTree : start initTrees("
247:                        + reinit + ") end");
248:            }
249:
250:            /**
251:             * Rebuild trees after nodes modifications
252:             *
253:             */
254:            void reInitReqTree() {
255:                Util
256:                        .log("[requirements] -> SelectReqTree : start reInitReqTree ");
257:                DefaultMutableTreeNode copyRootNode = (DefaultMutableTreeNode) ((DefaultTreeModel) usedReqTree
258:                        .getModel()).getRoot();
259:                copyRootNode.removeAllChildren();
260:
261:                DefaultMutableTreeNode refereceRootNode = (DefaultMutableTreeNode) globalReqTree
262:                        .getCopy(false).getModel().getRoot();
263:                int nbChild = refereceRootNode.getChildCount();
264:                for (int i = 0; i < nbChild; i++) {
265:                    DefaultMutableTreeNode nodeToCopy = (DefaultMutableTreeNode) refereceRootNode
266:                            .getChildAt(i);
267:                    copyRootNode.add(getCopy(nodeToCopy));
268:                }
269:                ((DefaultTreeModel) usedReqTree.getModel()).reload();
270:                Util
271:                        .log("[requirements] -> SelectReqTree : end reInitReqTree ");
272:            }
273:
274:            /**
275:             * get a copy of a tree
276:             * @param node
277:             * @return the parent node
278:             */
279:            private DefaultMutableTreeNode getCopy(DefaultMutableTreeNode node) {
280:                Util.log("[requirements] -> SelectReqTree : start getCopy("
281:                        + node.toString() + ") start");
282:                DefaultMutableTreeNode copy_node = new DefaultMutableTreeNode(
283:                        node.getUserObject());
284:                int nbChild = node.getChildCount();
285:                if (nbChild == 0) {
286:                    return copy_node;
287:                } else {
288:                    int i = 0;
289:                    while (i < nbChild) {
290:                        DefaultMutableTreeNode child_copy = getCopy((DefaultMutableTreeNode) node
291:                                .getChildAt(i));
292:                        copy_node.insert(child_copy, i);
293:                        i++;
294:                    }
295:                }
296:                Util.log("[requirements] -> SelectReqTree :  getCopy("
297:                        + node.toString() + ") return " + copy_node.toString());
298:                Util.log("[requirements] -> SelectReqTree :  getCopy("
299:                        + node.toString() + ") end");
300:                return copy_node;
301:            }
302:
303:            public void actionPerformed(ActionEvent e) {
304:                if (e.getSource().equals(removeButton)) {
305:                    removePerformed(e);
306:                } else if (e.getSource().equals(addButton)) {
307:                    addPerformed(e);
308:                } else if (e.getSource().equals(validateButton)) {
309:                    validatePerformed(e);
310:                } else if (e.getSource().equals(cancelButton)) {
311:                    cancelPerformed(e);
312:                }
313:            }
314:
315:            /**
316:             * Remove links from the Test Plan
317:             * @param e  corresponding to the '<' button click
318:             */
319:            void removePerformed(ActionEvent e) {
320:                Util
321:                        .log("[requirements] -> SelectReqTree -> removePerformed : start ");
322:                /* if test tree is not empty */
323:                if (dynTestTree.getTree() != null) {
324:                    TreePath[] pathTab = dynTestTree.getTree()
325:                            .getSelectionPaths();
326:                    if (pathTab != null) {
327:                        /* get All selected simpledata =(family | testList | test ) */
328:                        for (int i = 0; i < pathTab.length; i++) {
329:                            Util
330:                                    .log("[requirements] -> SelectReqTree -> removePerformed : pathTab["
331:                                            + i + "] =" + pathTab[i].toString());
332:                            Util
333:                                    .log("[requirements] -> SelectReqTree -> removePerformed : lastComponent de pathTab["
334:                                            + i
335:                                            + "] = "
336:                                            + pathTab[i].getLastPathComponent()
337:                                                    .toString());
338:
339:                            /*  for each selected simpledata get its type (family, testList, test)*/
340:                            DefaultMutableTreeNode simpleDataNode = (DefaultMutableTreeNode) pathTab[i]
341:                                    .getLastPathComponent();
342:                            int level = simpleDataNode.getLevel();
343:
344:                            if (level != 0 && simpleDataNode != null) {
345:                                SimpleData simpleData = (SimpleData) simpleDataNode
346:                                        .getUserObject();
347:                                //GenTestTools2.getRequirment(simpleData);
348:                                GenTestTools
349:                                        .removeSimpleDataToDynamicTestTree(simpleData);
350:                                SimpleData pSimpleDataOrg = getSalomeModelSimpleData(simpleData);
351:                                if (pSimpleDataOrg != null) {
352:                                    simpleData = pSimpleDataOrg;
353:                                }
354:                                addSimpleDataToRemoveLink(simpleData);
355:                            }
356:                        }
357:                    }
358:                }
359:                initTrees(true);
360:                Util
361:                        .log("[requirements] -> SelectReqTree -> removePerformed : end ");
362:            }
363:
364:            /**
365:             * remove requirement links from one simpleData
366:             * @param simpleData
367:             */
368:            void addSimpleDataToRemoveLink(SimpleData simpleData) {
369:                Util
370:                        .log("[requirements] -> SelectReqTree : start addSimpleDataToRemoveLink("
371:                                + simpleData.toString() + ") start");
372:                if (simpleData instanceof  Test) {
373:                    if (!simpleDataRemoved.contains(simpleData)) {
374:                        simpleDataRemoved.add(simpleData);
375:                    }
376:                } else if (simpleData instanceof  TestList) {
377:                    TestList pTestList = (TestList) simpleData;
378:                    ArrayList lestOfTest = pTestList.getTestListFromModel();
379:                    int size = lestOfTest.size();
380:                    for (int i = 0; i < size; i++) {
381:                        Test pTest = (Test) lestOfTest.get(i);
382:                        addSimpleDataToRemoveLink(pTest);
383:                    }
384:                } else if (simpleData instanceof  Family) {
385:                    Family pFamily = (Family) simpleData;
386:                    ArrayList lestOfSuite = pFamily.getSuiteListFromModel();
387:                    int size = lestOfSuite.size();
388:                    for (int i = 0; i < size; i++) {
389:                        TestList pTestList = (TestList) lestOfSuite.get(i);
390:                        addSimpleDataToRemoveLink(pTestList);
391:                    }
392:                }
393:                Util
394:                        .log("[requirements] -> SelectReqTree : end addSimpleDataToRemoveLink("
395:                                + simpleData.toString() + ") end");
396:            }
397:
398:            /**
399:             *  Generate requirement structures to test structures
400:             *  @param e corresponding to the '>' button click
401:             */
402:            void addPerformed(ActionEvent e) {
403:                Util
404:                        .log("[requirements] -> SelectReqTree -> addPerformed start");
405:                TreePath[] pathTab = usedReqTree.getSelectionPaths();
406:                if (pathTab != null) {
407:                    /* get All selected requirements */
408:                    for (int i = 0; i < pathTab.length; i++) {
409:                        Util.log("[requirements] -> SelectReqTree : pathTab["
410:                                + i + "] =" + pathTab[i].toString());
411:                        /*  for each selected requirement */
412:                        DefaultMutableTreeNode reqNode = (DefaultMutableTreeNode) pathTab[i]
413:                                .getLastPathComponent();
414:                        addTestTreeFromReqNode(reqNode);
415:                    }
416:                }
417:                initTrees(true);
418:                Util.log("[requirements] -> SelectReqTree -> addPerformed end");
419:            }// end addPerformed
420:
421:            /**
422:             * validate in base the test generation and/or remove test<->requirement links
423:             * @param e corresponding to the 'Validate' button click
424:             */
425:            void validatePerformed(ActionEvent e) {
426:                Util
427:                        .log("[requirements] -> SelectReqTree -> validatedPerformed start");
428:                valideTemplateModel();
429:                /* Refresh DataModel */
430:                DataModel.reloadFromBase(true);
431:                dispose();
432:                Util
433:                        .log("[requirements] -> SelectReqTree -> validatedPerformed end");
434:            }
435:
436:            /**
437:             * Cancel the transformation and close the dialog window
438:             * @param e corresponding to 'Cancel' button
439:             */
440:            void cancelPerformed(ActionEvent e) {
441:                Util
442:                        .log("[requirements] -> SelectReqTree -> cancelPerformed start");
443:                clearTemplateModel();
444:                dispose();
445:                Util
446:                        .log("[requirements] -> SelectReqTree -> cancelPerformed end");
447:            }
448:
449:            /**
450:             * 
451:             * clear all simpleData that have been temporarly used during the selection
452:             */
453:            void clearTemplateModel() {
454:                Util
455:                        .log("[requirements] -> SelectReqTree -> clearTemplateModel() start");
456:                DefaultMutableTreeNode rootNode = dynTestTree.getRoot();
457:                int nbChild = rootNode.getChildCount();
458:                for (int i = 0; i < nbChild; i++) {
459:                    clearTemplateModel((DefaultMutableTreeNode) rootNode
460:                            .getChildAt(i));
461:                }
462:                Util
463:                        .log("[requirements] -> SelectReqTree -> clearTemplateModel() end");
464:            }
465:
466:            /**
467:             *  Validate all dynTestTree simpledata (test,testList,family) in bdd
468:             *
469:             */
470:            void valideTemplateModel() {
471:                Util
472:                        .log("[requirements] -> SelectReqTree -> valideTemplateModel start");
473:                DefaultMutableTreeNode rootNode = dynTestTree.getRoot();
474:                int nbChild = rootNode.getChildCount();
475:                for (int i = 0; i < nbChild; i++) {
476:                    valideTemplateModel((DefaultMutableTreeNode) rootNode
477:                            .getChildAt(i));
478:                }
479:                int nbLinkToRemove = simpleDataRemoved.size();
480:                for (int i = 0; i < nbLinkToRemove; i++) {
481:                    SimpleData pSimpleData = (SimpleData) simpleDataRemoved
482:                            .elementAt(i);
483:                    if (pSimpleData instanceof  Test) {
484:                        Test pTest = (Test) pSimpleData;
485:                        Requirement bijectiveReq = GenTestTools
486:                                .getRequirement(pTest);
487:                        if (GenTestTools.isReqDefaultCovered(bijectiveReq,
488:                                pTest.getNameFromModel())) {
489:                            try {
490:                                ((ReqLeaf) bijectiveReq)
491:                                        .deleteCoverForTest(pTest.getIdBdd());
492:                            } catch (Exception e) {
493:                                e.printStackTrace();
494:                            }
495:                        }
496:                    }
497:                }
498:                Util
499:                        .log("[requirements] -> SelectReqTree -> valideTemplateModel end");
500:            }
501:
502:            /**
503:             * Clear a simpleData from the model
504:             * @param node
505:             */
506:            void clearTemplateModel(DefaultMutableTreeNode node) {
507:                Util
508:                        .log("[requirements] -> SelectReqTree -> clearTemplateModel("
509:                                + node.toString() + ") start");
510:                Util
511:                        .log("[requirements] -> SelectReqTree -> clearTemplateModel node to clearTemplateModel "
512:                                + node.getUserObject());
513:                SimpleData pSimplData = (SimpleData) node.getUserObject();
514:                if (!pSimplData.isInBase()) {
515:                    if (pSimplData instanceof  Family) {
516:
517:                    } else if (pSimplData instanceof  TestList) {
518:                        TestList pTestList = (TestList) pSimplData;
519:                        Family pFamily = pTestList.getFamilyFromModel();
520:                        if (pFamily != null) {
521:                            pFamily.deleteTestListInModel(pTestList);
522:                        }
523:                    } else if (pSimplData instanceof  Test) {
524:                        Test pTest = (Test) pSimplData;
525:                        TestList pTestList = pTest.getTestListFromModel();
526:                        if (pTestList != null) {
527:                            pTestList.deleteTestInModel(pTest);
528:                        }
529:                    }
530:                }
531:                int nbChild = node.getChildCount();
532:                if (nbChild == 0) {
533:                    return;
534:                } else {
535:                    int i = 0;
536:                    while (i < nbChild) {
537:                        clearTemplateModel((DefaultMutableTreeNode) node
538:                                .getChildAt(i));
539:                        i++;
540:                    }
541:                }
542:                Util
543:                        .log("[requirements] -> SelectReqTree -> clearTemplateModel("
544:                                + node.toString() + ") end");
545:            }
546:
547:            /**
548:             * get the simpleData from the Salome model
549:             * @param pSimplData
550:             * @return
551:             */
552:            SimpleData getSalomeModelSimpleData(SimpleData pSimplData) {
553:                Util
554:                        .log("[requirements] -> SelectReqTree -> getSalomeModelSimpleData("
555:                                + pSimplData.toString() + ") start");
556:                SimpleData dataInSalome = null;
557:
558:                if (pSimplData != null) {
559:                    dataInSalome = (SimpleData) simpleDataCache.get(pSimplData);
560:                    if (dataInSalome != null) {
561:                        return dataInSalome;
562:                    }
563:                    if (pSimplData instanceof  Family) {
564:                        Family pFamily = (Family) pSimplData;
565:                        DefaultMutableTreeNode pSimpleDataNode = pDynamicTree
566:                                .findRemoveFamilyNode(pFamily
567:                                        .getNameFromModel(), false);
568:                        if (pSimpleDataNode != null) {
569:                            dataInSalome = (SimpleData) pSimpleDataNode
570:                                    .getUserObject();
571:                            simpleDataCache.put(pSimplData, dataInSalome);
572:                        }
573:                    } else if (pSimplData instanceof  TestList) {
574:                        TestList pTestList = (TestList) pSimplData;
575:                        Family pFamily = pTestList.getFamilyFromModel();
576:                        DefaultMutableTreeNode pSimpleDataNode = pDynamicTree
577:                                .findRemoveTestListNode(pTestList
578:                                        .getNameFromModel(), pFamily
579:                                        .getNameFromModel(), false);
580:                        if (pSimpleDataNode != null) {
581:                            dataInSalome = (SimpleData) pSimpleDataNode
582:                                    .getUserObject();
583:                            simpleDataCache.put(pSimplData, dataInSalome);
584:                        }
585:                    } else if (pSimplData instanceof  Test) {
586:                        Test pTest = (Test) pSimplData;
587:                        TestList pTestList = pTest.getTestListFromModel();
588:                        Family pFamily = pTestList.getFamilyFromModel();
589:                        DefaultMutableTreeNode pSimpleDataNode = pDynamicTree
590:                                .findRemoveTestNode(pTest.getNameFromModel(),
591:                                        pTestList.getNameFromModel(), pFamily
592:                                                .getNameFromModel(), false);
593:                        if (pSimpleDataNode != null) {
594:                            dataInSalome = (SimpleData) pSimpleDataNode
595:                                    .getUserObject();
596:                            simpleDataCache.put(pSimplData, dataInSalome);
597:                        }
598:                    }
599:                }
600:
601:                Util
602:                        .log("[requirements] -> SelectReqTree -> getSalomeModelSimpleData("
603:                                + pSimplData.toString() + ") end");
604:                return dataInSalome;
605:            }
606:
607:            /**
608:             * Add simpledata template in bdd
609:             * @param node
610:             */
611:            void valideTemplateModel(DefaultMutableTreeNode node) {
612:                Util
613:                        .log("[requirements] -> SelectReqTree -> valideTemplateModel("
614:                                + node.toString() + ") start");
615:                SimpleData pSimplData = (SimpleData) node.getUserObject();
616:                SimpleData pSimplData2 = getSalomeModelSimpleData(pSimplData);
617:                if (pSimplData2 != null) {
618:                    pSimplData = pSimplData2;
619:                }
620:
621:                if (!pSimplData.isInBase()) {
622:                    // Ajout en base et model
623:                    if (pSimplData instanceof  Family) {
624:                        Family pFamily = (Family) pSimplData;
625:                        try {
626:                            DataModel.getCurrentProject()
627:                                    .addFamilyInDBAndModel(pFamily);
628:                        } catch (Exception e) {
629:                            e.printStackTrace();
630:                        }
631:                    } else if (pSimplData instanceof  TestList) {
632:                        TestList pTestList = (TestList) pSimplData;
633:                        Family pFamily = pTestList.getFamilyFromModel();
634:                        try {
635:                            pFamily.addTestListInDB(pTestList);
636:                        } catch (Exception e) {
637:                            e.printStackTrace();
638:                        }
639:                    } else if (pSimplData instanceof  Test) {
640:                        Test pTest = (Test) pSimplData;
641:                        User currentUser = DataModel.getCurrentUser();
642:                        Util
643:                                .log("[requirements] -> SelectReqTree -> valideTemplateModel : Conceptor login = "
644:                                        + currentUser.getLoginFromModel());
645:                        pTest.setConceptorLoginInModel(currentUser
646:                                .getLoginFromModel());
647:                        pTest.setConceptorInModel(currentUser
648:                                .getFirstNameFromModel()
649:                                + " " + currentUser.getLastNameFromModel());
650:                        TestList pTestList = pTest.getTestListFromModel();
651:                        try {
652:                            pTestList.addTestInDB(pTest);
653:                            Requirement bijectiveReq = GenTestTools
654:                                    .getRequirement(pTest);
655:                            if (bijectiveReq != null
656:                                    && bijectiveReq instanceof  ReqLeaf) {
657:                                ((ReqLeaf) bijectiveReq).addTestCoverInDB(pTest
658:                                        .getIdBdd(), true);
659:                            }
660:
661:                        } catch (Exception e) {
662:                            e.printStackTrace();
663:                        }
664:
665:                    }
666:                } else {
667:                    if (pSimplData instanceof  Test) {
668:                        //Ajout du lien si non existant
669:                        Test pTest = (Test) pSimplData;
670:                        try {
671:                            Requirement bijectiveReq = GenTestTools
672:                                    .getRequirement(pTest);
673:                            if (bijectiveReq != null
674:                                    && bijectiveReq instanceof  ReqLeaf) {
675:                                if (!GenTestTools.isReqDefaultCovered(
676:                                        bijectiveReq, pTest.getNameFromModel())) {
677:                                    ((ReqLeaf) bijectiveReq).addTestCoverInDB(
678:                                            pTest.getIdBdd(), true);
679:                                }
680:                            }
681:                        } catch (Exception e) {
682:                            e.printStackTrace();
683:                        }
684:
685:                    }
686:                }
687:                int nbChild = node.getChildCount();
688:                if (nbChild == 0) {
689:                    return;
690:                } else {
691:                    int i = 0;
692:                    while (i < nbChild) {
693:                        valideTemplateModel((DefaultMutableTreeNode) node
694:                                .getChildAt(i));
695:                        i++;
696:                    }
697:                }
698:                Util
699:                        .log("[requirements] -> SelectReqTree -> valideTemplateModel("
700:                                + node.toString() + ") end");
701:            }
702:
703:            /**
704:             * Add test and its family and testList to the dynTestTree
705:             * @param reqNode
706:             */
707:            public void addTestTreeFromReqNode(DefaultMutableTreeNode reqNode) {
708:                Util
709:                        .log("[requirements] -> SelectReqTree -> addTestTreeFromReqNode("
710:                                + reqNode.toString() + ") start");
711:                if (reqNode != null && !reqNode.isRoot()) {
712:                    Requirement pReq = (Requirement) reqNode.getUserObject();
713:                    if (pReq instanceof  ReqLeaf) {
714:                        //Cette methode cree le simple data (si besoin) et l'ajoute dans l'arbre de tests de référence de GenTestTools2
715:                        SimpleData pSimpleData = GenTestTools.getSimpleData(
716:                                pReq, new Vector(), true);
717:                        if (pSimpleData instanceof  Test) {
718:                            checkAndAddTest((Test) pSimpleData);
719:                        }
720:                    } else {
721:                        //Ajouter tous les reqLeaf depuis la reqfamily
722:                        ReqFamily pReqFamily = (ReqFamily) reqNode
723:                                .getUserObject();
724:                        Vector allLeafReq = pReqFamily.getAllLeaf();
725:                        for (int j = 0; j < allLeafReq.size(); j++) {
726:                            ReqLeaf reqLeaf = (ReqLeaf) allLeafReq.elementAt(j);
727:                            SimpleData pSimpleData = GenTestTools
728:                                    .getSimpleData(reqLeaf, new Vector(), true);
729:                            checkAndAddTest((Test) pSimpleData);
730:                        }
731:
732:                    }
733:                }
734:                Util
735:                        .log("[requirements] -> SelectReqTree -> addTestTreeFromReqNode("
736:                                + reqNode.toString() + ") end");
737:            }
738:
739:            /**
740:             *  Check if test name < 255 char and if is not already in the model
741:             * @param pTest
742:             */
743:            private void checkAndAddTest(Test pTest) {
744:                Util.log("[requirements] -> SelectReqTree -> checkAndAddTest("
745:                        + pTest.toString() + ") start");
746:                if (pTest != null) {
747:                    if (pTest.getNameFromModel().length() > 255) {//TODO à externaliser
748:                        JOptionPane.showMessageDialog(SalomeTMFContext
749:                                .getInstance().getSalomeFrame(), Language
750:                                .getInstance().getText("erreur_longueur_param")
751:                                + pTest.getNameFromModel().length() + ". \n",
752:                                Language.getInstance().getText("Erreur_!"),
753:                                JOptionPane.ERROR_MESSAGE);
754:                    } else {
755:                        Test pSimpleDataOrg = (Test) getSalomeModelSimpleData(pTest);
756:                        if (pSimpleDataOrg != null) {
757:                            pTest = pSimpleDataOrg;
758:                        }
759:                        if (simpleDataRemoved.contains(pTest)) {
760:                            simpleDataRemoved.remove(pTest);
761:                        }
762:                    }
763:                }
764:                Util.log("[requirements] -> SelectReqTree -> checkAndAddTest("
765:                        + pTest.toString() + ") end");
766:            }
767:
768:            /*************************** TreeTools ********************/
769:
770:            /**
771:             * Expand all tree nodes 
772:             * @param tree JTree to expand
773:             */
774:            static void expandAll(JTree tree) {
775:                Util.log("[requirements] -> SelectReqTree -> expandAll start");
776:                int row = 0;
777:                while (row < tree.getRowCount()) {
778:                    tree.expandRow(row);
779:                    row++;
780:                }
781:                Util.log("[requirements] -> SelectReqTree -> expandAll end");
782:            }
783:
784:            /**
785:             * Collapse all tree nodes
786:             * @param tree JTree to collapse
787:             */
788:            public void collapseAll(JTree tree) {
789:                Util
790:                        .log("[requirements] -> SelectReqTree -> collapseAll start");
791:                int row = tree.getRowCount() - 1;
792:                while (row >= 0) {
793:                    tree.collapseRow(row);
794:                    row--;
795:                }
796:                Util.log("[requirements] -> SelectReqTree -> collapseAll end");
797:            }
798:
799:            public void windowClosing(WindowEvent e) {
800:                cancelPerformed(null);
801:            }
802:
803:            public void windowDeiconified(WindowEvent e) {
804:            }
805:
806:            public void windowOpened(WindowEvent e) {
807:            }
808:
809:            public void windowActivated(WindowEvent e) {
810:            }
811:
812:            public void windowDeactivated(WindowEvent e) {
813:            }
814:
815:            public void windowClosed(WindowEvent e) {
816:            }
817:
818:            public void windowIconified(WindowEvent e) {
819:            }
820:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.