Source Code Cross Referenced for RequirementTestPanel.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 Marche Mikael
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.Dimension;
028:        import java.awt.FontMetrics;
029:        import java.awt.GridLayout;
030:        import java.awt.event.ActionEvent;
031:        import java.awt.event.ActionListener;
032:        import java.util.Enumeration;
033:        import java.util.Hashtable;
034:        import java.util.Observable;
035:        import java.util.Observer;
036:        import java.util.Vector;
037:
038:        import javax.swing.BorderFactory;
039:        import javax.swing.JButton;
040:        import javax.swing.JOptionPane;
041:        import javax.swing.JPanel;
042:        import javax.swing.JScrollPane;
043:        import javax.swing.JTabbedPane;
044:        import javax.swing.JTable;
045:        import javax.swing.JTree;
046:        import javax.swing.ListSelectionModel;
047:        import javax.swing.event.ChangeEvent;
048:        import javax.swing.event.ChangeListener;
049:        import javax.swing.event.ListSelectionEvent;
050:        import javax.swing.event.ListSelectionListener;
051:        import javax.swing.event.TreeSelectionEvent;
052:        import javax.swing.event.TreeSelectionListener;
053:        import javax.swing.tree.DefaultMutableTreeNode;
054:        import javax.swing.tree.TreePath;
055:
056:        import org.objectweb.salome_tmf.data.AutomaticTest;
057:        import org.objectweb.salome_tmf.data.ManualTest;
058:        import org.objectweb.salome_tmf.data.Test;
059:        import org.objectweb.salome_tmf.ihm.languages.Language;
060:        import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
061:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
062:        import org.objectweb.salome_tmf.ihm.models.DynamicTree;
063:        import org.objectweb.salome_tmf.ihm.tools.Tools;
064:
065:        import salomeTMF_plug.requirements.ReqPlugin;
066:        import salomeTMF_plug.requirements.data.ReqLeaf;
067:        import salomeTMF_plug.requirements.data.Requirement;
068:        import salomeTMF_plug.requirements.sqlWrapper.ReqWrapper;
069:        import salomeTMF_plug.requirements.sqlWrapper.SQLWrapper;
070:
071:        public class RequirementTestPanel extends JPanel implements 
072:                ActionListener, ListSelectionListener, Observer {
073:
074:            JButton viewReqButton;
075:
076:            JButton delReqButton;
077:
078:            JButton addReqButton;
079:
080:            JTable reqTable;
081:
082:            JPanel buttonsPanel;
083:            JScrollPane tablePane;
084:            JTabbedPane salomeParent;
085:            JTree salomeDynamicTree;
086:
087:            RequirementTree pReqTree;
088:            RequirementCampPanel pRequirementCampPanel;
089:            //JTree reqTree;
090:
091:            Test pCurrentTest;
092:            Vector reqCovered;
093:            Vector filtredreqCovered;
094:
095:            int type; /* 0 for Manual Test 1 for AutomatedTest */
096:            FiltrePanel pFiltrePanel;
097:
098:            public RequirementTestPanel(int _type, RequirementTree _pReqTree,
099:                    RequirementCampPanel _RequirementCampPanel) {
100:                type = _type;
101:                pReqTree = _pReqTree;
102:                pRequirementCampPanel = _RequirementCampPanel;
103:                initComponent();
104:            }
105:
106:            void initComponent() {
107:                reqCovered = new Vector();
108:                filtredreqCovered = new Vector();
109:                viewReqButton = new JButton(Language.getInstance().getText(
110:                        "Visualiser"));
111:                addReqButton = new JButton(Language.getInstance().getText(
112:                        "Utiliser"));
113:                delReqButton = new JButton(Language.getInstance().getText(
114:                        "Supprimer"));
115:
116:                viewReqButton.addActionListener(this );
117:                addReqButton.addActionListener(this );
118:                delReqButton.addActionListener(this );
119:
120:                viewReqButton.setEnabled(false);
121:                addReqButton.setEnabled(true);
122:                delReqButton.setEnabled(false);
123:
124:                buttonsPanel = new JPanel(new GridLayout(1, 3));
125:                buttonsPanel.add(addReqButton);
126:                buttonsPanel.add(delReqButton);
127:                buttonsPanel.add(viewReqButton);
128:
129:                SimpleTableModel model = new SimpleTableModel();
130:
131:                reqTable = new JTable(model);
132:                try {
133:                    //reqTable.setDefaultRenderer(Class.forName( "java.lang.Object" ), new PriorityTableCellRenderer(reqCovered));
134:                    reqTable.setDefaultRenderer(Class
135:                            .forName("java.lang.Object"),
136:                            new PriorityTableCellRenderer(filtredreqCovered));
137:                } catch (Exception e) {
138:                    e.printStackTrace();
139:                }
140:                model.addColumn("id");
141:                model.addColumn(Language.getInstance().getText("Nom"));
142:                model.addColumn(Language.getInstance().getText("Categorie"));
143:                model.addColumn(Language.getInstance().getText("Complexite"));
144:                model.addColumn(Language.getInstance().getText("Etat"));
145:
146:                //model.addColumn(Language.getInstance().getText("Description"));
147:
148:                reqTable.setPreferredScrollableViewportSize(new Dimension(600,
149:                        200));
150:                reqTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
151:
152:                /*for (int i = 0; i < 5; i++) {
153:                	column = reqTable.getColumnModel().getColumn(i);
154:                	column.sizeWidthToFit();
155:                }*/
156:
157:                ListSelectionModel rowSM = reqTable.getSelectionModel();
158:                rowSM.addListSelectionListener(this );
159:
160:                tablePane = new JScrollPane(reqTable);
161:                tablePane.setBorder(BorderFactory.createRaisedBevelBorder());
162:
163:                pFiltrePanel = new FiltrePanel(null, this );
164:
165:                setLayout(new BorderLayout());
166:                add(buttonsPanel, BorderLayout.NORTH);
167:                add(tablePane, BorderLayout.CENTER);
168:                add(pFiltrePanel, BorderLayout.SOUTH);
169:                //addFocusListener(new requirementTestFocusListener());
170:            }
171:
172:            public void setParent(JTabbedPane _salomeParent) {
173:                if (salomeParent != null) {
174:                    return;
175:                } else {
176:                    salomeParent = _salomeParent;
177:                    salomeParent.addChangeListener(new ChangeListener() {
178:                        public void stateChanged(ChangeEvent e) {
179:                            if (((JTabbedPane) e.getSource())
180:                                    .getSelectedComponent().equals(
181:                                            RequirementTestPanel.this )) {
182:                                System.out.println("Update Requiment for test");
183:                                InitData(DataModel.getCurrentTest());
184:                            }
185:                        }
186:                    });
187:                }
188:            }
189:
190:            public void setTestTree(DynamicTree pDynamicTree) {
191:                if (salomeDynamicTree == null) {
192:                    salomeDynamicTree = pDynamicTree.getTree();
193:                    salomeDynamicTree
194:                            .addTreeSelectionListener(new TreeSelectionListener() {
195:                                public void valueChanged(TreeSelectionEvent e) {
196:                                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) salomeDynamicTree
197:                                            .getLastSelectedPathComponent();
198:
199:                                    if (node == null)
200:                                        return;
201:
202:                                    Object nodeInfo = node.getUserObject();
203:                                    /* React to the node selection. */
204:                                    if ((nodeInfo instanceof  ManualTest)
205:                                            && type == 0) {
206:                                        if (salomeParent
207:                                                .getSelectedComponent()
208:                                                .equals(
209:                                                        RequirementTestPanel.this )) {
210:                                            InitData((Test) nodeInfo);
211:                                        }
212:                                    } else if ((nodeInfo instanceof  AutomaticTest)
213:                                            && type == 1) {
214:                                        if (salomeParent
215:                                                .getSelectedComponent()
216:                                                .equals(
217:                                                        RequirementTestPanel.this )) {
218:                                            InitData((Test) nodeInfo);
219:                                        }
220:                                    }
221:                                }
222:                            });
223:                }
224:            }
225:
226:            public void InitData(Test pTest) {
227:
228:                if (pTest == pCurrentTest || pTest == null) {
229:                    return;
230:                }
231:                pCurrentTest = pTest;
232:                Vector reqCoveredWrapper;
233:                reqCovered.clear();
234:
235:                try {
236:                    reqCoveredWrapper = Requirement
237:                            .getReqWrapperCoveredByTest(pTest.getIdBdd());
238:                    int size = reqCoveredWrapper.size();
239:                    for (int i = 0; i < size; i++) {
240:                        ReqWrapper pReqWrapper = (ReqWrapper) reqCoveredWrapper
241:                                .elementAt(i);
242:                        DefaultMutableTreeNode node = pReqTree
243:                                .findRequirementFromParent(pReqWrapper);
244:                        Requirement pReq = null;
245:                        if (node != null) {
246:                            pReq = (Requirement) node.getUserObject();
247:                            reqCovered.add(pReq);
248:                        } else {
249:                            pReqTree.reload();
250:                            node = pReqTree
251:                                    .findRequirementFromParent(pReqWrapper);
252:                            if (node != null) {
253:                                pReq = (Requirement) node.getUserObject();
254:                                reqCovered.add(pReq);
255:                            } else {
256:                                //Hum Data corruption !!!
257:                                Tools
258:                                        .ihmExceptionView(new Exception(
259:                                                "Hum ??, it seem that data integrity are corrupted"));
260:
261:                            }
262:                        }
263:                    }
264:                    // Init table data
265:                    //updateReqUse(reqCovered, false);
266:                    updateTable(reqCovered);
267:                } catch (Exception e) {
268:                    Tools.ihmExceptionView(e);
269:                }
270:            }
271:
272:            void updateReqUse(Vector reqCovered, boolean onBDD) {
273:                int transNumber = -1;
274:                try {
275:                    int reqSize = reqCovered.size();
276:                    if (onBDD) {
277:                        transNumber = SQLWrapper.beginTransaction();
278:                        Requirement.deleteAllCoverForTest(pCurrentTest
279:                                .getIdBdd());
280:                    }
281:                    //IHM
282:                    //((SimpleTableModel)reqTable.getModel()).clearTable();
283:
284:                    for (int i = 0; i < reqSize; i++) {
285:                        Requirement pReq = (Requirement) reqCovered
286:                                .elementAt(i);
287:
288:                        if (onBDD) {
289:                            // Bdd
290:                            pReq.addTestCoverInDB(pCurrentTest.getIdBdd(),
291:                                    false);
292:                        }
293:
294:                        // IHM
295:                        /*Vector data = new Vector();
296:                        data.add(pReq.getNameFromModel());
297:                        if (pReq.getDescriptionFromModel().length()> 60){
298:                        	data.add(pReq.getDescriptionFromModel().substring(0, 59)+"...");
299:                        } else {
300:                        	data.add(pReq.getDescriptionFromModel());
301:                        }
302:                        ((SimpleTableModel)reqTable.getModel()).insertRow(i,data);
303:                         */
304:
305:                    }
306:                    if (onBDD) {
307:                        SQLWrapper.commitTrans(transNumber);
308:                    }
309:                    // ihm
310:                    updateTable(reqCovered);
311:                } catch (Exception e) {
312:                    try {
313:                        if (onBDD) {
314:                            SQLWrapper.rollBackTrans(transNumber);
315:                        }
316:                    } catch (Exception e2) {
317:                    }
318:                }
319:
320:            }
321:
322:            void updateTable(Vector reqCovered) {
323:                filtredreqCovered.clear();
324:                int filtre = pFiltrePanel.getFiltre();
325:                int reqSize = reqCovered.size();
326:                ((SimpleTableModel) reqTable.getModel()).clearTable();
327:                int compteur = 0;
328:                for (int i = 0; i < reqSize; i++) {
329:                    Requirement pReq = (Requirement) reqCovered.elementAt(i);
330:
331:                    if (pReq instanceof  ReqLeaf) {
332:                        if (!filtredreqCovered.contains(pReq)) {
333:                            int reqP = ((ReqLeaf) pReq).getPriorityFromModel();
334:                            if ((reqP | filtre) == filtre) {
335:                                filtredreqCovered.add(pReq);
336:                                Vector data = new Vector();
337:                                data.add("" + pReq.getIdBdd());
338:                                data.add(pReq.getLongName());
339:                                /*if (pReq.getDescriptionFromModel().length()> 60){
340:                                	data.add(pReq.getDescriptionFromModel().substring(0, 59)+"...");
341:                                } else {
342:                                	data.add(pReq.getDescriptionFromModel());
343:                                }*/
344:                                data.add(ReqWrapper
345:                                        .getCatString(((ReqLeaf) pReq)
346:                                                .getCatFromModel()));
347:                                data.add(ReqWrapper
348:                                        .getComplexString(((ReqLeaf) pReq)
349:                                                .getComplexeFromModel()));
350:                                data.add(ReqWrapper
351:                                        .getStateString(((ReqLeaf) pReq)
352:                                                .getStateFromModel()));
353:
354:                                ((SimpleTableModel) reqTable.getModel())
355:                                        .insertRow(compteur, data);
356:                                compteur++;
357:                            }
358:                        }
359:                    }
360:                }
361:                setColumnSize(reqTable);
362:            }
363:
364:            public void actionPerformed(ActionEvent e) {
365:                if (e.getSource().equals(addReqButton)) {
366:                    if (addReqPerformed(e)) {
367:                        pReqTree.refreshCurrent();
368:                        if (pRequirementCampPanel != null) {
369:                            pRequirementCampPanel.refreshCurrentCover(false);
370:                        }
371:                    }
372:                } else if (e.getSource().equals(delReqButton)) {
373:                    if (deleteConfirme(Language.getInstance().getText(
374:                            "Couverture"))) {
375:                        delReqPerformed(e);
376:                        pReqTree.refreshCurrent();
377:                        if (pRequirementCampPanel != null) {
378:                            pRequirementCampPanel.refreshCurrentCover(false);
379:                        }
380:                    }
381:                } else if (e.getSource().equals(viewReqButton)) {
382:                    viewReqPerformed(e);
383:                }
384:            }
385:
386:            boolean deleteConfirme(String quoi) {
387:                Object[] options = {
388:                        org.objectweb.salome_tmf.ihm.languages.Language
389:                                .getInstance().getText("Oui"),
390:                        org.objectweb.salome_tmf.ihm.languages.Language
391:                                .getInstance().getText("Non") };
392:                int choice = -1;
393:
394:                choice = SalomeTMFContext.getInstance().askQuestion(
395:                        org.objectweb.salome_tmf.ihm.languages.Language
396:                                .getInstance().getText(
397:                                        "confimation_suppression2")
398:                                + " " + quoi + " ?",
399:                        org.objectweb.salome_tmf.ihm.languages.Language
400:                                .getInstance().getText("Attention_!"),
401:                        JOptionPane.WARNING_MESSAGE, options);
402:
403:                if (choice == JOptionPane.YES_OPTION) {
404:                    return true;
405:                } else {
406:                    return false;
407:                }
408:            }
409:
410:            boolean addReqPerformed(ActionEvent e) {
411:                SelectRequirement pSelectRequirement = new SelectRequirement(
412:                        pReqTree.getCopy(true), Language.getInstance().getText(
413:                                "Selection"), reqCovered, true, null);
414:                Hashtable selected = pSelectRequirement.getSelection();
415:                if (selected != null) {
416:                    reqCovered.clear();
417:                    Enumeration enumE = selected.elements();
418:                    while (enumE.hasMoreElements()) {
419:                        reqCovered.add(enumE.nextElement());
420:                    }
421:                    updateReqUse(reqCovered, true);
422:                    return true;
423:                }
424:                return false;
425:            }
426:
427:            void delReqPerformed(ActionEvent e) {
428:                int selectedRow = reqTable.getSelectedRow();
429:                if (selectedRow > -1) {
430:                    //if (reqCovered != null) {
431:                    if (filtredreqCovered != null) {
432:                        //Requirement pReq = (Requirement)reqCovered.elementAt(selectedRow);
433:                        Requirement pReq = (Requirement) filtredreqCovered
434:                                .elementAt(selectedRow);
435:                        try {
436:                            // Bdd
437:                            pReq.deleteCoverForTest(pCurrentTest.getIdBdd());
438:
439:                            //IHM
440:                            reqCovered.remove(selectedRow);
441:                            //updateReqUse(reqCovered, false);
442:                            updateTable(reqCovered);
443:                        } catch (Exception ex) {
444:
445:                        }
446:                    }
447:                }
448:            }
449:
450:            void viewReqPerformed(ActionEvent e) {
451:                int selectedRow = reqTable.getSelectedRow();
452:
453:                if (selectedRow > -1) {
454:                    //if (reqCovered != null) {
455:                    if (filtredreqCovered != null) {
456:                        //Requirement pReq = (Requirement)reqCovered.elementAt(selectedRow);
457:                        Requirement pReq = (Requirement) filtredreqCovered
458:                                .elementAt(selectedRow);
459:                        DefaultMutableTreeNode node = pReqTree
460:                                .findRequirementFromParent(pReq);
461:                        if (node != null) {
462:                            //pReqTree.refreshNode(node);
463:                            ReqPlugin.selectReqTab();
464:                            pReqTree.setSelectionPath(new TreePath(node
465:                                    .getPath()));
466:
467:                        }
468:                    }
469:                }
470:            }
471:
472:            public void valueChanged(ListSelectionEvent e) {
473:                //Ignore extra messages.
474:                if (e.getValueIsAdjusting()) {
475:                    return;
476:                }
477:
478:                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
479:                if (lsm.isSelectionEmpty()) {
480:                    //no rows are selected
481:                    delReqButton.setEnabled(false);
482:                    viewReqButton.setEnabled(false);
483:                } else {
484:                    //int selectedRow = lsm.getMinSelectionIndex();
485:                    delReqButton.setEnabled(true);
486:                    viewReqButton.setEnabled(true);
487:                    //selectedRow is selected
488:                }
489:            }
490:
491:            /**
492:             * redefine size of table columns
493:             */
494:            public void setColumnSize(JTable table) {
495:                FontMetrics fm = table.getFontMetrics(table.getFont());
496:                for (int i = 0; i < table.getColumnCount(); i++) {
497:                    int max = 0;
498:                    for (int j = 0; j < table.getRowCount(); j++) {
499:                        int taille = fm.stringWidth((String) table.getValueAt(
500:                                j, i));
501:                        if (taille > max)
502:                            max = taille;
503:                    }
504:                    String nom = (String) table.getColumnModel().getColumn(i)
505:                            .getIdentifier();
506:                    int taille = fm.stringWidth(nom);
507:                    if (taille > max)
508:                        max = taille;
509:                    table.getColumnModel().getColumn(i).setPreferredWidth(
510:                            max + 10);
511:                }
512:            }
513:
514:            /********************************* Observer  *************************/
515:
516:            public void update(Observable o, Object arg) {
517:                if (arg instanceof  ReqEvent) {
518:                    ReqEvent event = (ReqEvent) arg;
519:                    if (event.code == ReqEvent.FILTRE_REQ_CHANGE) {
520:                        //refreshCurrent(false);
521:                        updateTable(reqCovered);
522:                    }
523:                }
524:            }
525:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.