Source Code Cross Referenced for EnvironmentView.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » ihm » main » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » salome tmf » org.objectweb.salome_tmf.ihm.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * SalomeTMF is a Test Management Framework
0003:         * Copyright (C) 2005 France Telecom R&D
0004:         *
0005:         * This library is free software; you can redistribute it and/or
0006:         * modify it under the terms of the GNU Lesser General Public
0007:         * License as published by the Free Software Foundation; either
0008:         * version 2 of the License, or (at your option) any later version.
0009:         *
0010:         * This library is distributed in the hope that it will be useful,
0011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013:         * Lesser General Public License for more details.
0014:         *
0015:         * You should have received a copy of the GNU Lesser General Public
0016:         * License along with this library; if not, write to the Free Software
0017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018:         *
0019:         * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
0020:         *
0021:         * Contact: mikael.marche@rd.francetelecom.com
0022:         */
0023:
0024:        package org.objectweb.salome_tmf.ihm.main;
0025:
0026:        import java.awt.BorderLayout;
0027:        import java.awt.Color;
0028:        import java.awt.Cursor;
0029:        import java.awt.Dimension;
0030:        import java.awt.Frame;
0031:        import java.awt.GridLayout;
0032:        import java.awt.event.ActionEvent;
0033:        import java.awt.event.ActionListener;
0034:        import java.awt.event.MouseAdapter;
0035:        import java.awt.event.MouseEvent;
0036:        import java.io.File;
0037:        import java.io.FileNotFoundException;
0038:        import java.sql.Date;
0039:        import java.text.DateFormat;
0040:        import java.text.SimpleDateFormat;
0041:        import java.util.ArrayList;
0042:        import java.util.Enumeration;
0043:        import java.util.HashMap;
0044:        import java.util.Hashtable;
0045:        import java.util.Iterator;
0046:        import java.util.Locale;
0047:        import java.util.Set;
0048:        import java.util.Vector;
0049:
0050:        import javax.swing.BorderFactory;
0051:        import javax.swing.JButton;
0052:        import javax.swing.JDialog;
0053:        import javax.swing.JLabel;
0054:        import javax.swing.JMenu;
0055:        import javax.swing.JMenuBar;
0056:        import javax.swing.JMenuItem;
0057:        import javax.swing.JOptionPane;
0058:        import javax.swing.JPanel;
0059:        import javax.swing.JScrollPane;
0060:        import javax.swing.JTable;
0061:        import javax.swing.ListSelectionModel;
0062:        import javax.swing.event.ListSelectionEvent;
0063:        import javax.swing.event.ListSelectionListener;
0064:
0065:        import org.java.plugin.Extension;
0066:        import org.jfree.chart.ChartFactory;
0067:        import org.jfree.chart.ChartPanel;
0068:        import org.jfree.chart.JFreeChart;
0069:        import org.jfree.chart.axis.DateAxis;
0070:        import org.jfree.chart.axis.ValueAxis;
0071:        import org.jfree.chart.plot.XYPlot;
0072:        import org.jfree.chart.renderer.xy.XYItemRenderer;
0073:        import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
0074:        import org.jfree.data.time.Second;
0075:        import org.jfree.data.time.TimeSeries;
0076:        import org.jfree.data.time.TimeSeriesCollection;
0077:        import org.jfree.data.time.TimeSeriesDataItem;
0078:        import org.objectweb.salome_tmf.api.Api;
0079:        import org.objectweb.salome_tmf.api.ApiConstants;
0080:        import org.objectweb.salome_tmf.api.Permission;
0081:        import org.objectweb.salome_tmf.api.Util;
0082:        import org.objectweb.salome_tmf.api.sql.ISQLConfig;
0083:        import org.objectweb.salome_tmf.data.Attachment;
0084:        import org.objectweb.salome_tmf.data.Campaign;
0085:        import org.objectweb.salome_tmf.data.Environment;
0086:        import org.objectweb.salome_tmf.data.Execution;
0087:        import org.objectweb.salome_tmf.data.Parameter;
0088:        import org.objectweb.salome_tmf.data.Script;
0089:        import org.objectweb.salome_tmf.ihm.IHMConstants;
0090:        import org.objectweb.salome_tmf.ihm.languages.Language;
0091:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
0092:        import org.objectweb.salome_tmf.ihm.models.MyTableModel;
0093:        import org.objectweb.salome_tmf.ihm.models.TableSorter;
0094:        import org.objectweb.salome_tmf.ihm.tools.Tools;
0095:        import org.objectweb.salome_tmf.plugins.UICompCst;
0096:        import org.objectweb.salome_tmf.plugins.core.BugTracker;
0097:        import org.objectweb.salome_tmf.plugins.core.ScriptEngine;
0098:
0099:        /**
0100:         * Classe qui d?finit la vue pour g?rer les environnements
0101:         * @author teaml039
0102:         * @version : 0.1
0103:         */
0104:        public class EnvironmentView extends JPanel implements  IHMConstants,
0105:                ActionListener {
0106:
0107:            static JButton refreshButton;
0108:
0109:            /**
0110:             * Bouton pour ajouter un environnement
0111:             */
0112:            static JButton addButton;
0113:
0114:            /**
0115:             * Bouton pour supprimer un environnement
0116:             */
0117:            static JButton deleteButton;
0118:
0119:            /**
0120:             * Bouton pour modifier un environnement
0121:             */
0122:            static JButton modifyButton;
0123:
0124:            /**
0125:             * Bouton pour visualiser des bugs
0126:             */
0127:            //JButton showBugButton;
0128:            /**
0129:             * Mod?le de la table des environnement
0130:             */
0131:            MyTableModel environmentTableModel;
0132:            TableSorter sorter;
0133:            /**
0134:             * Table des environnements
0135:             */
0136:            JTable environmentTable;
0137:
0138:            /**
0139:             * Mod?le de s?lection pour la table des environnements
0140:             */
0141:            ListSelectionModel rowSM;
0142:
0143:            //static JButton modifyScriptButton;
0144:            //static JButton commitButton;
0145:
0146:            static JMenuBar scriptMenuBar;
0147:            static JMenu scriptMenu;
0148:            static JMenuItem modifyScriptItem;
0149:            static JMenuItem actualItem;
0150:            static JMenuItem setUpEngineItem;
0151:
0152:            JMenu bugTrackMenu;
0153:            JPanel buttonsPanel;
0154:
0155:            File importFile;
0156:
0157:            HashMap modifyScriptList;
0158:
0159:            /**************************************************************************/
0160:            /**							CONSTRUCTEUR								***/
0161:            /**************************************************************************/
0162:
0163:            /**
0164:             * Constructeur de la vue
0165:             */
0166:            public EnvironmentView() {
0167:                refreshButton = new JButton(Language.getInstance().getText(
0168:                        "Rafraichir"));
0169:                addButton = new JButton(Language.getInstance().getText(
0170:                        "Ajouter"));
0171:                deleteButton = new JButton(Language.getInstance().getText(
0172:                        "Supprimer"));
0173:                modifyButton = new JButton(Language.getInstance().getText(
0174:                        "Modifier"));
0175:
0176:                environmentTable = new JTable();
0177:                environmentTableModel = new MyTableModel();
0178:                DataModel.setEnvironmentTableModel(environmentTableModel);
0179:
0180:                refreshButton.addActionListener(this );
0181:
0182:                addButton.setToolTipText(Language.getInstance().getText(
0183:                        "Ajouter_un_nouvel_environnement"));
0184:                addButton.addActionListener(this );
0185:
0186:                modifyButton.setToolTipText(Language.getInstance().getText(
0187:                        "Modifier_un_environnement"));
0188:                modifyButton.setEnabled(false);
0189:                modifyButton.addActionListener(this );
0190:
0191:                deleteButton.setToolTipText(Language.getInstance().getText(
0192:                        "Supprimer_un_environnement"));
0193:                deleteButton.setEnabled(false);
0194:                deleteButton.addActionListener(this );
0195:
0196:                scriptMenu = new JMenu(Language.getInstance().getText("Script"));
0197:                modifyScriptItem = new JMenuItem(Language.getInstance()
0198:                        .getText("Modifier_le_Script"));
0199:                modifyScriptItem.addActionListener(this );
0200:                modifyScriptItem.setEnabled(false);
0201:
0202:                bugTrackMenu = new JMenu(Language.getInstance().getText(
0203:                        "Bug_tracking"));
0204:                bugTrackMenu.setEnabled(false);
0205:
0206:                actualItem = new JMenuItem(Language.getInstance().getText(
0207:                        "Actualiser_le_Script"));
0208:                actualItem.addActionListener(this );
0209:                actualItem.setEnabled(false);
0210:
0211:                setUpEngineItem = new JMenuItem("SetUp Script Engine");
0212:                setUpEngineItem.addActionListener(this );
0213:                setUpEngineItem.setEnabled(false);
0214:
0215:                scriptMenu.add(modifyScriptItem);
0216:                scriptMenu.add(actualItem);
0217:                scriptMenu.add(setUpEngineItem);
0218:                scriptMenuBar = new JMenuBar();
0219:                scriptMenuBar.add(scriptMenu);
0220:
0221:                // Construction de la table
0222:                environmentTableModel.addColumnNameAndColumn(Language
0223:                        .getInstance().getText("Nom"));
0224:                environmentTableModel.addColumnNameAndColumn(Language
0225:                        .getInstance().getText("Script"));
0226:                environmentTableModel.addColumnNameAndColumn(Language
0227:                        .getInstance().getText("Paramètres"));
0228:                environmentTableModel.addColumnNameAndColumn(Language
0229:                        .getInstance().getText("Description"));
0230:
0231:                sorter = new TableSorter(environmentTableModel);
0232:                environmentTable.setModel(sorter);
0233:                sorter.setTableHeader(environmentTable.getTableHeader());
0234:
0235:                environmentTable
0236:                        .setPreferredScrollableViewportSize(new Dimension(700,
0237:                                350));
0238:                environmentTable
0239:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0240:
0241:                // Gestion des s?lection dans la table
0242:                rowSM = environmentTable.getSelectionModel();
0243:                rowSM.addListSelectionListener(new ListSelectionListener() {
0244:                    public void valueChanged(ListSelectionEvent e) {
0245:                        if (e.getValueIsAdjusting())
0246:                            return;
0247:
0248:                        int nbOfSelectedRows = environmentTable
0249:                                .getSelectedRowCount();
0250:                        int selectedRow = environmentTable.getSelectedRow();
0251:                        if (selectedRow != -1) {
0252:                            if (nbOfSelectedRows != 1) {
0253:                                if (Permission.canExecutCamp())
0254:                                    deleteButton.setEnabled(true);
0255:                                modifyButton.setEnabled(false);
0256:                                /*
0257:                                 modifyScriptButton.setEnabled(false);
0258:                                commitButton.setEnabled(false);
0259:                                 */
0260:                                actualItem.setEnabled(false);
0261:                                modifyScriptItem.setEnabled(false);
0262:                                setUpEngineItem.setEnabled(false);
0263:                                bugTrackMenu.setEnabled(false);
0264:                            } else {
0265:                                //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0266:                                Environment env = DataModel.getCurrentProject()
0267:                                        .getEnvironmentFromModel(
0268:                                                (String) sorter.getValueAt(
0269:                                                        selectedRow, 0));
0270:                                if (Permission.canUpdateCamp()
0271:                                        || Permission.canExecutCamp())
0272:                                    modifyButton.setEnabled(true);
0273:                                if (Permission.canExecutCamp())
0274:                                    deleteButton.setEnabled(true);
0275:                                if ((Permission.canUpdateCamp() || Permission
0276:                                        .canExecutCamp())
0277:                                        && env.getInitScriptFromModel() != null) {
0278:                                    //modifyScriptButton.setEnabled(true);
0279:                                    modifyScriptItem.setEnabled(true);
0280:                                    setUpEngineItem.setEnabled(true);
0281:                                } else {
0282:                                    //modifyScriptButton.setEnabled(false);
0283:                                    modifyScriptItem.setEnabled(false);
0284:                                    setUpEngineItem.setEnabled(false);
0285:                                }
0286:
0287:                                if (Api.isConnected()
0288:                                        && Permission.canUpdateCamp()
0289:                                        && isCommitable((String) sorter
0290:                                                .getValueAt(selectedRow, 0))) {
0291:                                    //commitButton.setEnabled(true);
0292:                                    actualItem.setEnabled(true);
0293:
0294:                                } else {
0295:                                    //commitButton.setEnabled(false);
0296:                                    actualItem.setEnabled(false);
0297:
0298:                                }
0299:                                bugTrackMenu.setEnabled(true);
0300:                            }
0301:
0302:                        } else {
0303:                            //showBugButton.setEnabled(false);
0304:                            deleteButton.setEnabled(false);
0305:                            modifyButton.setEnabled(false);
0306:                            //modifyScriptButton.setEnabled(false);
0307:                            //commitButton.setEnabled(false);
0308:
0309:                            actualItem.setEnabled(false);
0310:                            modifyScriptItem.setEnabled(false);
0311:                            setUpEngineItem.setEnabled(false);
0312:                            bugTrackMenu.setEnabled(false);
0313:                        }
0314:                        scriptMenu.setEnabled(actualItem.isEnabled()
0315:                                || setUpEngineItem.isEnabled()
0316:                                || modifyScriptItem.isEnabled());
0317:                    }
0318:                });
0319:
0320:                // Mapping entre objets graphiques et constantes
0321:                SalomeTMFContext.getInstance().addToUIComponentsMap(
0322:                        UICompCst.DATA_MANAGEMENT_ENV_TABLE, environmentTable);
0323:                // Add this component as static component
0324:                UICompCst.staticUIComps
0325:                        .add(UICompCst.DATA_MANAGEMENT_ENV_TABLE);
0326:
0327:                JScrollPane environmentTableScrollPane = new JScrollPane(
0328:                        environmentTable);
0329:
0330:                //JPanel buttonsPanel = new JPanel();
0331:                buttonsPanel = new JPanel(new GridLayout(1, 5));
0332:                buttonsPanel.add(refreshButton);
0333:                buttonsPanel.add(addButton);
0334:                buttonsPanel.add(modifyButton);
0335:                buttonsPanel.add(deleteButton);
0336:
0337:                buttonsPanel.add(scriptMenuBar);
0338:                //buttonsPanel.add(modifyScriptButton);
0339:                //buttonsPanel.add(commitButton);
0340:                //buttonsPanel.add(showBugButton);
0341:
0342:                // Mapping entre objets graphiques et constantes
0343:                SalomeTMFContext.getInstance().addToUIComponentsMap(
0344:                        UICompCst.DATA_MANAGEMENT_ENV_BUTTONS_PANEL,
0345:                        buttonsPanel);
0346:                // Add this component as static component
0347:                UICompCst.staticUIComps
0348:                        .add(UICompCst.DATA_MANAGEMENT_ENV_BUTTONS_PANEL);
0349:
0350:                buttonsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
0351:
0352:                environmentTable.addMouseListener(new MouseAdapter() {
0353:                    public void mousePressed(MouseEvent e) {
0354:                        if (e.getClickCount() > 1) {
0355:                            if (Permission.canCreateCamp()
0356:                                    || Permission.canExecutCamp())
0357:                                modifyEnvironment();
0358:                        }
0359:                    }
0360:                });
0361:
0362:                initData();
0363:
0364:                this .setLayout(new BorderLayout());
0365:                this .add(BorderLayout.NORTH, buttonsPanel);
0366:                this .add(BorderLayout.CENTER, environmentTableScrollPane);
0367:
0368:            } // Fin du constructeur EnvironmentView/0
0369:
0370:            /**************************************************************************/
0371:            /**							METHODES PUBLIQUES							***/
0372:            /**************************************************************************/
0373:
0374:            /**
0375:             * M?thode permettant de modifier les environnements
0376:             */
0377:            private void modifyEnvironment() {
0378:                int selectedRow = environmentTable.getSelectedRow();
0379:                if (selectedRow != -1) {
0380:                    //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0381:                    Environment env = DataModel.getCurrentProject()
0382:                            .getEnvironmentFromModel(
0383:                                    (String) sorter.getValueAt(selectedRow, 0));
0384:                    String oldEnvName = env.getNameFromModel();
0385:                    Script oldInitScript = env.getInitScriptFromModel();
0386:                    String oldDescription = env.getDescriptionFromModel();
0387:
0388:                    HashMap oldAttachMap = env
0389:                            .getCopyOfAttachmentMapFromModel();
0390:                    Hashtable oldParameter = env
0391:                            .getCopyOfParameterHashTableFromModel();
0392:
0393:                    AskNewEnvironment askNewEnvironment = new AskNewEnvironment(
0394:                            env);
0395:                    if (askNewEnvironment.getEnvironment() != null) {
0396:                        int transNumber = -1;
0397:                        try {
0398:                            transNumber = Api.beginTransaction(11,
0399:                                    ApiConstants.UPDATE_ENVIRONMENT);
0400:                            Environment environment = askNewEnvironment
0401:                                    .getEnvironment();
0402:                            String newName = environment.getNameFromModel();
0403:                            environment.updateInModel(oldEnvName, environment
0404:                                    .getDescriptionFromModel());
0405:                            environment.updateInDBAndModel(newName, environment
0406:                                    .getDescriptionFromModel());
0407:                            if (environment.getInitScriptFromModel() != null) {
0408:                                if (!environment.getInitScriptFromModel()
0409:                                        .equals(oldInitScript)) {
0410:                                    if (oldInitScript != null) {
0411:                                        //askNewEnvironment.getEnvironment().deleteScriptFromDB(oldInitScript.getNameFromModel());
0412:                                        environment.deleteScriptInDB();
0413:                                    }
0414:                                    Script script = environment
0415:                                            .getInitScriptFromModel();
0416:                                    //environment.addScript2DB(script, askNewEnvironment.getScriptFile());
0417:                                    environment.addScriptInDBAndModel(script,
0418:                                            askNewEnvironment.getScriptFile());
0419:                                }
0420:                            } else if (oldInitScript != null) {
0421:                                //askNewEnvironment.getEnvironment().deleteScriptInDB(oldInitScript.getNameFromModel());
0422:                                environment.deleteScriptInDB();
0423:                            }
0424:
0425:                            /* Les Paramtres */
0426:                            Hashtable newParameter = environment
0427:                                    .getParametersHashTableFromModel();
0428:                            Set keysSet = newParameter.keySet();
0429:                            for (Iterator iter = keysSet.iterator(); iter
0430:                                    .hasNext();) {
0431:                                Parameter param = (Parameter) iter.next();
0432:                                String Value = (String) oldParameter.get(param);
0433:                                String newValue = (String) newParameter
0434:                                        .get(param);
0435:                                if (Value == null) {
0436:                                    environment.addParameterValueInDB(param,
0437:                                            newValue);
0438:                                } else {
0439:                                    /* Update */
0440:                                    environment.updateParamValueInDB(param,
0441:                                            newValue);
0442:                                }
0443:                            }
0444:
0445:                            keysSet = oldParameter.keySet();
0446:                            for (Iterator iter = keysSet.iterator(); iter
0447:                                    .hasNext();) {
0448:                                Parameter param = (Parameter) iter.next();
0449:                                String Value = (String) newParameter.get(param);
0450:                                if (Value == null) {
0451:                                    environment.deleteDefParamInDB(param
0452:                                            .getIdBdd());
0453:                                }
0454:                            }
0455:                            /* ATTACHEMENTS */
0456:                            environment.updateAttachement(oldAttachMap);
0457:
0458:                            Api.commitTrans(transNumber);
0459:
0460:                        } catch (Exception exception) {
0461:                            Api.forceRollBackTrans(transNumber);
0462:                            env.updateInModel(oldEnvName, oldDescription);
0463:                            env.addScriptInModel(oldInitScript);
0464:                            // env.setParametersHashTableInModel(oldParamTable);
0465:                            env.setParametersHashTableInModel(oldParameter);
0466:                            env.setAttachmentMapInModel(oldAttachMap);
0467:                            Tools.ihmExceptionView(exception);
0468:                        }
0469:
0470:                    } else {
0471:                        env.addScriptInModel(oldInitScript);
0472:                        //env.setParametersHashTableInModel(oldParamTable);
0473:                        env.setParametersHashTableInModel(oldParameter);
0474:                        env.updateInModel(oldEnvName, oldDescription);
0475:                        env.setAttachmentMapInModel(oldAttachMap);
0476:                    }
0477:                    //environmentTableModel.setValueAt(env.getName(), selectedRow, 0);
0478:                    sorter.setValueAt(env.getNameFromModel(), selectedRow, 0);
0479:                    if (env.getInitScriptFromModel() == null) {
0480:                        //environmentTableModel.setValueAt("", selectedRow, 1);
0481:                        sorter.setValueAt("", selectedRow, 1);
0482:                    } else {
0483:                        sorter.setValueAt(env.getInitScriptFromModel()
0484:                                .getNameFromModel(), selectedRow, 1);
0485:                        modifyScriptItem.setEnabled(true);
0486:                        setUpEngineItem.setEnabled(true);
0487:                        modifyScriptList.put(env, new Boolean(true));
0488:
0489:                    }
0490:                    sorter.setValueAt(env.getParametersHashTableFromModel(),
0491:                            selectedRow, 2);
0492:                    sorter.setValueAt(env.getDescriptionFromModel(),
0493:                            selectedRow, 3);
0494:
0495:                }
0496:                scriptMenu.setEnabled(actualItem.isEnabled()
0497:                        || setUpEngineItem.isEnabled()
0498:                        || modifyScriptItem.isEnabled());
0499:            } // Fin de la m?thode
0500:
0501:            private void initData() {
0502:                modifyScriptList = new HashMap();
0503:                for (int i = 0; i < environmentTableModel.getRowCount(); i++) {
0504:                    //modifyScriptList.put(environmentTableModel.getValueAt(i,0), new Boolean(false));
0505:                    modifyScriptList.put(sorter.getValueAt(i, 0), new Boolean(
0506:                            false));
0507:                }
0508:            }
0509:
0510:            private boolean isCommitable(String envName) {
0511:                Environment env = DataModel.getCurrentProject()
0512:                        .getEnvironmentFromModel(envName);
0513:                Boolean bool = (Boolean) modifyScriptList.get(env);
0514:                if (bool == null) {
0515:                    return false;
0516:                }
0517:                return bool.booleanValue();
0518:            }
0519:
0520:            /**
0521:             * M?thode qui g?re les permissions sur la vue
0522:             */
0523:            public static void giveAccessToIhmEnvironmentView() {
0524:                if (!Permission.canExecutCamp()) {
0525:                    deleteButton.setEnabled(false);
0526:                }
0527:                if (!Permission.canCreateCamp() && !Permission.canExecutCamp()) {
0528:                    addButton.setEnabled(false);
0529:                }
0530:                if (!Permission.canUpdateCamp() && !Permission.canExecutCamp()) {
0531:                    modifyButton.setEnabled(false);
0532:                    //modifyScriptButton.setEnabled(false);
0533:                    //commitButton.setEnabled(false);
0534:
0535:                    actualItem.setEnabled(false);
0536:                    modifyScriptItem.setEnabled(false);
0537:                    setUpEngineItem.setEnabled(true);
0538:                }
0539:                scriptMenu.setEnabled(actualItem.isEnabled()
0540:                        || setUpEngineItem.isEnabled()
0541:                        || modifyScriptItem.isEnabled());
0542:            } // Fin de la m?thode giveAccessToIhmEnvironmentView/0
0543:
0544:            public void actionPerformed(ActionEvent e) {
0545:                Object source = e.getSource();
0546:                if (source.equals(addButton)) {
0547:                    addPerformed(e);
0548:                } else if (source.equals(modifyButton)) {
0549:                    modifyPerformed(e);
0550:                } else if (source.equals(deleteButton)) {
0551:                    deletePerformed(e);
0552:                } else if (source.equals(actualItem)) {
0553:                    commitScriptPerformed(e);
0554:                } else if (source.equals(modifyScriptItem)) {
0555:                    modifyScriptPerformed(e);
0556:                } else if (source.equals(setUpEngineItem)) {
0557:                    setUpEnginePerformed(e);
0558:                } else if (source.equals(refreshButton)) {
0559:                    refreshPerformed();
0560:                }
0561:            }
0562:
0563:            void refreshPerformed() {
0564:                try {
0565:                    DataModel.reloadParameters();
0566:                    DataModel.reloadEnvironnements();
0567:                } catch (Exception e) {
0568:                    // TODO: handle exception
0569:                }
0570:            }
0571:
0572:            public void setUpEnginePerformed(ActionEvent e) {
0573:                int selectedRow = environmentTable.getSelectedRow();
0574:                if (selectedRow != -1) {
0575:                    //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0576:                    Environment env = DataModel.getCurrentProject()
0577:                            .getEnvironmentFromModel(
0578:                                    (String) sorter.getValueAt(selectedRow, 0));
0579:                    if (env == null) {
0580:                        JOptionPane
0581:                                .showMessageDialog(
0582:                                        EnvironmentView.this ,
0583:                                        Language
0584:                                                .getInstance()
0585:                                                .getText(
0586:                                                        "Impossible_de_récupérer_l'environement_sélectionné."),
0587:                                        Language.getInstance().getText(
0588:                                                "Erreur_!"),
0589:                                        JOptionPane.ERROR_MESSAGE);
0590:                        return;
0591:                    }
0592:
0593:                    try {
0594:                        Script pScript = null;
0595:                        //int plugScriptType;
0596:                        pScript = env.getInitScriptFromModel();
0597:                        if (pScript == null) {
0598:                            JOptionPane
0599:                                    .showMessageDialog(
0600:                                            EnvironmentView.this ,
0601:                                            Language
0602:                                                    .getInstance()
0603:                                                    .getText(
0604:                                                            "Impossible_de_récupérer_le_fichier_depuis_la_base."),
0605:                                            Language.getInstance().getText(
0606:                                                    "Erreur_!"),
0607:                                            JOptionPane.ERROR_MESSAGE);
0608:                            return;
0609:                        }
0610:                        //plugScriptType = ScriptEngine.ENV_SCRIPT;
0611:                        ScriptEngine pEngine = pScript
0612:                                .getScriptEngine(
0613:                                        (Extension) SalomeTMFContext
0614:                                                .getInstance().associatedExtension
0615:                                                .get(pScript
0616:                                                        .getScriptExtensionFromModel()),
0617:                                        SalomeTMFContext.getInstance().urlSalome,
0618:                                        SalomeTMFContext.getInstance().jpf);
0619:                        if (pEngine != null) {
0620:                            String oldplugArg = pScript.getPlugArgFromModel();
0621:                            String plugArg = pEngine
0622:                                    .modifyEngineAgument(pScript);
0623:
0624:                            if (oldplugArg.equals(plugArg)) {
0625:                                return;
0626:                            }
0627:                            try {
0628:                                pScript.updatePlugArgInDB(plugArg);
0629:                                pScript.updatePlugArgInModel(plugArg);
0630:                                JOptionPane
0631:                                        .showMessageDialog(
0632:                                                EnvironmentView.this ,
0633:                                                Language
0634:                                                        .getInstance()
0635:                                                        .getText(
0636:                                                                "Le_fichier_a_été_correctement_archivé."),
0637:                                                Language.getInstance().getText(
0638:                                                        "Info..."),
0639:                                                JOptionPane.INFORMATION_MESSAGE);
0640:                            } catch (Exception exception) {
0641:                                pScript.updatePlugArgInModel(oldplugArg);
0642:                                Tools.ihmExceptionView(exception);
0643:                            }
0644:
0645:                        } else {
0646:                            JOptionPane
0647:                                    .showMessageDialog(
0648:                                            EnvironmentView.this ,
0649:                                            Language
0650:                                                    .getInstance()
0651:                                                    .getText(
0652:                                                            "Impossible_d'initialiser_le_plugin_du_scrit"),
0653:                                            Language.getInstance().getText(
0654:                                                    "Erreur_!"),
0655:                                            JOptionPane.ERROR_MESSAGE);
0656:                            return;
0657:                        }
0658:                    } catch (Exception e1) {
0659:                        Tools.ihmExceptionView(e1);
0660:                    }
0661:                }
0662:            }
0663:
0664:            public void commitScriptPerformed(ActionEvent e) {
0665:                if (Api.isConnected()) {
0666:                    int selectedRow = environmentTable.getSelectedRow();
0667:                    if (selectedRow != -1) {
0668:                        //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0669:                        Environment env = DataModel.getCurrentProject()
0670:                                .getEnvironmentFromModel(
0671:                                        (String) sorter.getValueAt(selectedRow,
0672:                                                0));
0673:                        int transNumber = -1;
0674:                        try {
0675:                            transNumber = Api.beginTransaction(1,
0676:                                    ApiConstants.UPDATE_ATTACHMENT);
0677:                            Date date = new Date(importFile.lastModified());
0678:                            Script script = env.getInitScriptFromModel();
0679:                            script.updateInDB(importFile);
0680:                            /*script.updateContentInDB(importFile.getAbsolutePath());
0681:                            script.updateDateInDB(date);
0682:                            script.updateLengthInDB(importFile.length());
0683:                             */
0684:
0685:                            Api.commitTrans(transNumber);
0686:                            transNumber = -1;
0687:                            //if (Api.getException() == null || Api.getException().size() == 0) {
0688:                            modifyScriptList.put(env, new Boolean(false));
0689:                            //commitButton.setEnabled(false);
0690:                            actualItem.setEnabled(false);
0691:                            JOptionPane
0692:                                    .showMessageDialog(
0693:                                            EnvironmentView.this ,
0694:                                            Language
0695:                                                    .getInstance()
0696:                                                    .getText(
0697:                                                            "Le_fichier_a_été_correctement_archivé."),
0698:                                            Language.getInstance().getText(
0699:                                                    "Info..."),
0700:                                            JOptionPane.INFORMATION_MESSAGE);
0701:                            //}
0702:                        } catch (FileNotFoundException fe) {
0703:                            Api.forceRollBackTrans(transNumber);
0704:                            JOptionPane
0705:                                    .showMessageDialog(
0706:                                            EnvironmentView.this ,
0707:                                            Language
0708:                                                    .getInstance()
0709:                                                    .getText(
0710:                                                            "Impossible_de_trouver_le_fichier!\n_Vous_pouvez_l'importer_en_cliquant_sur_le_bouton_\"Modifier\""),
0711:                                            Language.getInstance().getText(
0712:                                                    "Erreur_!"),
0713:                                            JOptionPane.ERROR_MESSAGE);
0714:                        } catch (Exception exception) {
0715:                            Api.forceRollBackTrans(transNumber);
0716:                            Tools.ihmExceptionView(exception);
0717:                        }
0718:
0719:                    }
0720:                } else {
0721:                    JOptionPane
0722:                            .showMessageDialog(
0723:                                    EnvironmentView.this ,
0724:                                    Language
0725:                                            .getInstance()
0726:                                            .getText(
0727:                                                    "Impossible_!\nVous_n'êtes_pas_connecté_à_la_base."),
0728:                                    Language.getInstance().getText("Erreur_!"),
0729:                                    JOptionPane.ERROR_MESSAGE);
0730:                }
0731:            }
0732:
0733:            public void modifyScriptPerformed(ActionEvent e) {
0734:                int selectedRow = environmentTable.getSelectedRow();
0735:                if (selectedRow != -1) {
0736:                    Environment env = DataModel.getCurrentProject()
0737:                            .getEnvironmentFromModel(
0738:                                    (String) sorter.getValueAt(selectedRow, 0));
0739:                    if (env == null) {
0740:                        JOptionPane
0741:                                .showMessageDialog(
0742:                                        EnvironmentView.this ,
0743:                                        Language
0744:                                                .getInstance()
0745:                                                .getText(
0746:                                                        "Impossible_de_récupérer_l'environement_sélectionné."),
0747:                                        Language.getInstance().getText(
0748:                                                "Erreur_!"),
0749:                                        JOptionPane.ERROR_MESSAGE);
0750:                        return;
0751:                    }
0752:                    try {
0753:                        Cursor c = new Cursor(Cursor.WAIT_CURSOR);
0754:                        EnvironmentView.this .setCursor(c);
0755:                    } catch (Exception ex) {
0756:                        ex.printStackTrace();
0757:                    }
0758:                    try {
0759:                        Script pScript = null;
0760:                        String plugSeting = "";
0761:                        Hashtable param = new Hashtable();
0762:                        param.put("salome_projectName", DataModel
0763:                                .getCurrentProject().getNameFromModel());
0764:                        param.put("salome_ProjectObject", DataModel
0765:                                .getCurrentProject());
0766:                        param.put("salome_debug", new Boolean(true));
0767:                        param.put("salome_CampagneName", "");
0768:                        param.put("salome_ExecName", ""); // Add MM
0769:                        param.put("salome_environmentName", env
0770:                                .getNameFromModel());
0771:                        param.put("salome_TestName", "");
0772:                        param.put("salome_SuiteTestName", "");
0773:                        param.put(Language.getInstance().getText(
0774:                                "salome_FamilyName"), "");
0775:                        param.put("testLog", "");
0776:                        param.put("Verdict", "");
0777:                        int plugScriptType;
0778:                        String fileScript = null;
0779:                        pScript = new Script(env.getInitScriptFromDB());
0780:                        if (pScript == null) {
0781:                            JOptionPane
0782:                                    .showMessageDialog(
0783:                                            EnvironmentView.this ,
0784:                                            Language
0785:                                                    .getInstance()
0786:                                                    .getText(
0787:                                                            "Impossible_de_récupérer_le_fichier_depuis_la_base."),
0788:                                            Language.getInstance().getText(
0789:                                                    "Erreur_!"),
0790:                                            JOptionPane.ERROR_MESSAGE);
0791:                            return;
0792:                        }
0793:                        plugScriptType = ScriptEngine.ENV_SCRIPT;
0794:                        plugSeting = pScript.getPlugArgFromModel();
0795:                        if (Api.isConnected()) {
0796:                            //importFile = env.getEnvScriptFromDB(pScript.getNameFromModel());
0797:                            importFile = env.getInitScriptFileFromDB();
0798:                            fileScript = Tools.speedpurge(importFile
0799:                                    .getAbsolutePath());
0800:                        } else {
0801:                            fileScript = Tools.speedpurge(pScript
0802:                                    .getNameFromModel());
0803:                        }
0804:
0805:                        if (fileScript != null) {
0806:                            ScriptEngine pEngine = pScript
0807:                                    .getScriptEngine(
0808:                                            (Extension) SalomeTMFContext
0809:                                                    .getInstance().associatedExtension
0810:                                                    .get(pScript
0811:                                                            .getScriptExtensionFromModel()),
0812:                                            SalomeTMFContext.getInstance().urlSalome,
0813:                                            SalomeTMFContext.getInstance().jpf);
0814:                            if (pEngine != null) {
0815:                                pEngine.editScript(fileScript, plugScriptType,
0816:                                        pScript, param, plugSeting);
0817:                            } else {
0818:                                JOptionPane
0819:                                        .showMessageDialog(
0820:                                                EnvironmentView.this ,
0821:                                                Language
0822:                                                        .getInstance()
0823:                                                        .getText(
0824:                                                                "Impossible_d'initialiser_le_plugin_du_scrit"),
0825:                                                Language.getInstance().getText(
0826:                                                        "Erreur_!"),
0827:                                                JOptionPane.ERROR_MESSAGE);
0828:                            }
0829:                        } else {
0830:                            JOptionPane
0831:                                    .showMessageDialog(
0832:                                            EnvironmentView.this ,
0833:                                            Language
0834:                                                    .getInstance()
0835:                                                    .getText(
0836:                                                            "Impossible_de_récupérer_le_fichier_depuis_la_base."),
0837:                                            Language.getInstance().getText(
0838:                                                    "Erreur_!"),
0839:                                            JOptionPane.ERROR_MESSAGE);
0840:                        }
0841:
0842:                    } catch (Exception ex) {
0843:                        JOptionPane
0844:                                .showMessageDialog(
0845:                                        EnvironmentView.this ,
0846:                                        Language
0847:                                                .getInstance()
0848:                                                .getText(
0849:                                                        "Erreur_pour_lancer_l'éditeur_de_script_:_\n")
0850:                                                + ex.getMessage(), Language
0851:                                                .getInstance().getText(
0852:                                                        "Erreur_!"),
0853:                                        JOptionPane.ERROR_MESSAGE);
0854:                    }
0855:
0856:                    try {
0857:                        Cursor c = new Cursor(Cursor.DEFAULT_CURSOR);
0858:                        EnvironmentView.this .setCursor(c);
0859:                    } catch (Exception ee) {
0860:                        ee.printStackTrace();
0861:                    }
0862:                    //commitButton.setEnabled(true);
0863:                    actualItem.setEnabled(true);
0864:                    modifyScriptList.put(env, new Boolean(true));
0865:                }
0866:            }
0867:
0868:            public void deletePerformed(ActionEvent e) {
0869:                int selectedRow = environmentTable.getSelectedRow();
0870:                String message = "";
0871:                String text = "";
0872:                ArrayList concernedExecutions = DataModel.getCurrentProject()
0873:                        .getExecutionOfEnvironmentInModel(
0874:                                (String) sorter.getValueAt(selectedRow, 0));
0875:                if (concernedExecutions.size() > 0) {
0876:                    for (int i = 0; i < concernedExecutions.size(); i++) {
0877:                        message = message
0878:                                + "* "
0879:                                + ((Execution) concernedExecutions.get(i))
0880:                                        .getCampagneFromModel()
0881:                                        .getNameFromModel()
0882:                                + "/"
0883:                                + ((Execution) concernedExecutions.get(i))
0884:                                        .getNameFromModel() + "\n";
0885:                    }
0886:
0887:                    text = Language.getInstance().getText("L'environnement_<")
0888:                            + (String) sorter.getValueAt(selectedRow, 0)
0889:                            + Language.getInstance().getText(
0890:                                    ">_est_utilisé_pour_les_exécutions_:\n")
0891:                            + message;
0892:                    text = text
0893:                            + Language
0894:                                    .getInstance()
0895:                                    .getText(
0896:                                            "Sa_supression_entrainera_la_suppression_de_toutes_ces_exécutions.\n");
0897:                }
0898:                Object[] options = { Language.getInstance().getText("Oui"),
0899:                        Language.getInstance().getText("Non") };
0900:                int choice = -1;
0901:                //int actionCase = -1;
0902:                choice = JOptionPane
0903:                        .showOptionDialog(
0904:                                EnvironmentView.this ,
0905:                                //text + "Etes vous s?r de vouloir supprimer l'environnement <" + (String)environmentTableModel.getValueAt(selectedRow,0) + "> ?",
0906:                                text
0907:                                        + Language
0908:                                                .getInstance()
0909:                                                .getText(
0910:                                                        "Etes_vous_sûr_de_vouloir_supprimer_l'environnement_<")
0911:                                        + (String) sorter.getValueAt(
0912:                                                selectedRow, 0) + "> ?",
0913:                                Language.getInstance().getText("Attention_!"),
0914:                                JOptionPane.YES_NO_OPTION,
0915:                                JOptionPane.QUESTION_MESSAGE, null, options,
0916:                                options[1]);
0917:                if (choice == JOptionPane.YES_OPTION) {
0918:
0919:                    try {
0920:                        // BdD
0921:                        Environment env = DataModel.getCurrentProject()
0922:                                .getEnvironmentFromModel(
0923:                                        (String) sorter.getValueAt(selectedRow,
0924:                                                0));
0925:                        int idEnv = env.getIdBdd();
0926:                        //env.deleteFromDB();
0927:                        DataModel.getCurrentProject()
0928:                                .deleteEnvironmentInDBandModel(env);
0929:                        // IHM
0930:                        //ProjectData.getCurrentProject().removeEnvironment((String)sorter.getValueAt(selectedRow,0));
0931:                        environmentTableModel.removeData(sorter
0932:                                .modelIndex(selectedRow));
0933:                        for (int i = 0; i < concernedExecutions.size(); i++) {
0934:                            Campaign camp = ((Execution) concernedExecutions
0935:                                    .get(i)).getCampagneFromModel();
0936:                            //camp.removeExecution((Execution)concernedExecutions.get(i));
0937:                            if (DataModel.getCurrentCampaign() != null
0938:                                    && DataModel.getCurrentCampaign().equals(
0939:                                            camp)) {
0940:
0941:                                DataModel
0942:                                        .getExecutionTableModel()
0943:                                        .removeRow(
0944:                                                ((Execution) concernedExecutions
0945:                                                        .get(i))
0946:                                                        .getNameFromModel());
0947:
0948:                            }
0949:                        }
0950:
0951:                    } catch (Exception exception) {
0952:                        Tools.ihmExceptionView(exception);
0953:                    }
0954:                }
0955:            }
0956:
0957:            public void modifyPerformed(ActionEvent e) {
0958:                modifyEnvironment();
0959:            }
0960:
0961:            public void addPerformed(ActionEvent e) {
0962:                // Ouverture de la fen?tre d'ajout
0963:                AskNewEnvironment askNewEnvironment = new AskNewEnvironment();
0964:                Environment env = askNewEnvironment.getEnvironment();
0965:                // Si environnement est null = annuler
0966:                if (env != null) {
0967:                    int transNumber = -1;
0968:                    try {
0969:                        // BdD
0970:                        transNumber = Api.beginTransaction(1,
0971:                                ApiConstants.INSERT_ENVIRONMENT);
0972:                        //env.add2DB();
0973:                        DataModel.getCurrentProject()
0974:                                .addEnvironmentInDBAndModel(env);
0975:
0976:                        Set keysSet = env.getParametersHashTableFromModel()
0977:                                .keySet();
0978:                        for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
0979:                            Parameter param = (Parameter) iter.next();
0980:                            //env.addParamValue2DB(param);
0981:                            env.addParamValueInDBAndModel(param, env
0982:                                    .getParameterValueFromModel(param));
0983:                        }
0984:                        if (askNewEnvironment.getScriptFile() != null) {
0985:                            //env.addScript2BddAndModel(env.getInitScriptFromModel(),askNewEnvironment.getScriptFile());
0986:                            env.addScriptInDBAndModel(env
0987:                                    .getInitScriptFromModel(),
0988:                                    askNewEnvironment.getScriptFile());
0989:                        }
0990:                        Set keySet = env.getAttachmentMapFromModel().keySet();
0991:                        for (Iterator iter = keySet.iterator(); iter.hasNext();) {
0992:                            Attachment attach = (Attachment) env
0993:                                    .getAttachmentMapFromModel().get(
0994:                                            iter.next());
0995:                            env.addAttachementInDB(attach);
0996:                        }
0997:                        Api.commitTrans(transNumber);
0998:                        transNumber = -1;
0999:                        // IHM
1000:                        ArrayList data = new ArrayList();
1001:                        data.add(askNewEnvironment.getEnvironment()
1002:                                .getNameFromModel());
1003:                        String initScriptName = "";
1004:                        if (askNewEnvironment.getEnvironment()
1005:                                .getInitScriptFromModel() != null) {
1006:                            initScriptName = askNewEnvironment.getEnvironment()
1007:                                    .getInitScriptFromModel()
1008:                                    .getNameFromModel();
1009:                        }
1010:                        data.add(initScriptName);
1011:                        data.add(askNewEnvironment.getEnvironment()
1012:                                .getParametersHashTableFromModel());
1013:                        data.add(askNewEnvironment.getEnvironment()
1014:                                .getDescriptionFromModel());
1015:                        environmentTableModel.addRow(data);
1016:                        //ProjectData.getCurrentProject().addEnvironment(askNewEnvironment.getEnvironment());
1017:
1018:                    } catch (Exception exception) {
1019:                        Api.forceRollBackTrans(transNumber);
1020:                        Tools.ihmExceptionView(exception);
1021:                    }
1022:                }
1023:
1024:            }
1025:
1026:            public void activateBugTrackersMenu() {
1027:                //Menu for bugtrackers
1028:                //Vector bugTrackers = SalomeTMFContext.getInstance().bugTrackerExtensions;
1029:                Vector bugTrackers = SalomeTMFContext.getInstance()
1030:                        .getBugTracker();
1031:
1032:                if (bugTrackers.size() != 0) {
1033:                    for (int i = 0; i < bugTrackers.size(); i++) {
1034:                        //final BugTracker bugTracker = (BugTracker)SalomeTMFContext.getInstance().bugTrackers.elementAt(i);
1035:                        final BugTracker bugTracker = (BugTracker) bugTrackers
1036:                                .elementAt(i);
1037:                        //final BugTracker bugTracker = (BugTracker)bugTrackers.elementAt(i);
1038:                        JMenu bugTrackerMenu = new JMenu(bugTracker
1039:                                .getBugTrackerName());
1040:
1041:                        // Menu item for environment bugs
1042:                        JMenuItem showBugsItem = new JMenuItem(Language
1043:                                .getInstance().getText("Show_env_bugs"));
1044:                        showBugsItem.addActionListener(new ActionListener() {
1045:                            public void actionPerformed(ActionEvent e) {
1046:                                try {
1047:                                    int selectedRow = environmentTable
1048:                                            .getSelectedRow();
1049:                                    Environment currentEnv = DataModel
1050:                                            .getCurrentProject()
1051:                                            .getEnvironmentFromModel(
1052:                                                    (String) sorter.getValueAt(
1053:                                                            selectedRow, 0));
1054:                                    bugTracker.showEnvironmentBugs(currentEnv);
1055:                                } catch (Exception E) {
1056:                                    E.printStackTrace();
1057:                                }
1058:                            }
1059:                        });
1060:                        bugTrackerMenu.add(showBugsItem);
1061:
1062:                        if (Api.isWith_ICAL()) {
1063:                            // Menu item for ICAL calculation
1064:                            JMenuItem calculateICALItem = new JMenuItem(
1065:                                    Language.getInstance().getText(
1066:                                            "ICAL_calculation"));
1067:                            calculateICALItem
1068:                                    .addActionListener(new ActionListener() {
1069:                                        public void actionPerformed(
1070:                                                ActionEvent e) {
1071:                                            int selectedRow = environmentTable
1072:                                                    .getSelectedRow();
1073:                                            Environment currentEnv = DataModel
1074:                                                    .getCurrentProject()
1075:                                                    .getEnvironmentFromModel(
1076:                                                            (String) sorter
1077:                                                                    .getValueAt(
1078:                                                                            selectedRow,
1079:                                                                            0));
1080:                                            calculateICALForEnv(bugTracker,
1081:                                                    currentEnv);
1082:                                        }
1083:                                    });
1084:                            bugTrackerMenu.add(calculateICALItem);
1085:
1086:                            // Menu item for ICAL graph
1087:                            JMenuItem graphICALItem = new JMenuItem(Language
1088:                                    .getInstance().getText("ICAL_graph"));
1089:                            graphICALItem
1090:                                    .addActionListener(new ActionListener() {
1091:                                        public void actionPerformed(
1092:                                                ActionEvent e) {
1093:                                            int selectedRow = environmentTable
1094:                                                    .getSelectedRow();
1095:                                            Environment currentEnv = DataModel
1096:                                                    .getCurrentProject()
1097:                                                    .getEnvironmentFromModel(
1098:                                                            (String) sorter
1099:                                                                    .getValueAt(
1100:                                                                            selectedRow,
1101:                                                                            0));
1102:                                            graphICALForEnv(bugTracker,
1103:                                                    currentEnv);
1104:                                        }
1105:                                    });
1106:                            bugTrackerMenu.add(graphICALItem);
1107:                        }
1108:
1109:                        if (!bugTracker.isUserExistsInBugDB()) {
1110:                            bugTrackerMenu.setEnabled(false);
1111:                        }
1112:                        bugTrackMenu.add(bugTrackerMenu);
1113:                    }
1114:                    JMenuBar menuBar = new JMenuBar();
1115:                    menuBar.add(bugTrackMenu);
1116:                    buttonsPanel.add(menuBar);
1117:                }
1118:            }
1119:
1120:            void calculateICALForEnv(BugTracker bugTracker, Environment env) {
1121:                int choice = -1;
1122:                Object[] options = { Language.getInstance().getText("Oui"),
1123:                        Language.getInstance().getText("Non") };
1124:
1125:                /*int n0 = bugTracker.getEnvironmentNbBugs(env,BugTracker.CRITICAL,false);
1126:                Util.log("Nb Critical Bugs = " + n0);
1127:                
1128:                int n1 = bugTracker.getEnvironmentNbBugs(env,BugTracker.MAJOR,false);
1129:                Util.log("Nb Major Bugs = " + n1);
1130:                
1131:                int nc0 = bugTracker.getEnvironmentNbBugs(env,BugTracker.CRITICAL,true);
1132:                Util.log("Nb Corrected Critical Bugs = " + nc0);
1133:                
1134:                int nc1 = bugTracker.getEnvironmentNbBugs(env,BugTracker.MAJOR,true);
1135:                Util.log("Nb Corrected Major Bugs = " + nc1);*/
1136:
1137:                int nbMajorBugs = bugTracker.getEnvNbBugs(env, false);
1138:                Util.log("Nb Major Bugs = " + nbMajorBugs);
1139:
1140:                int nbCorMajorBugs = bugTracker.getEnvNbBugs(env, true);
1141:                Util.log("Nb Corrected Major Bugs = " + nbCorMajorBugs);
1142:
1143:                //if ((n0==0)&&(n1==0)) {
1144:                if (nbMajorBugs == 0) {
1145:                    JOptionPane.showMessageDialog(new Frame(), Language
1146:                            .getInstance().getText("ICAL_problem_env")
1147:                            + " '"
1148:                            + env.getNameFromModel()
1149:                            + "'."
1150:                            + Language.getInstance().getText(
1151:                                    "ICAL_problem_env2"), Language
1152:                            .getInstance().getText("Information_!"),
1153:                            JOptionPane.INFORMATION_MESSAGE);
1154:                    ;
1155:
1156:                } else {
1157:                    float ical_temp = Math
1158:                            .round(((float) nbCorMajorBugs / (float) nbMajorBugs) * 10000);
1159:                    float ical = ical_temp / 100;
1160:                    String message = "- ICAL = " + ical + " (env. '"
1161:                            + env.getNameFromModel() + "')";
1162:                    choice = JOptionPane.showOptionDialog(new Frame(), message
1163:                            + Language.getInstance().getText(
1164:                                    "ICAL_value_for_env"), Language
1165:                            .getInstance().getText("Information_!"),
1166:                            JOptionPane.YES_NO_OPTION,
1167:                            JOptionPane.QUESTION_MESSAGE, null, options,
1168:                            options[1]);
1169:
1170:                    if (choice == JOptionPane.YES_OPTION) {
1171:
1172:                        try {
1173:                            ISQLConfig pISQLConfig = Api.getISQLObjectFactory()
1174:                                    .getISQLConfig();
1175:                            if (pISQLConfig != null) {
1176:                                Hashtable projectConfs = pISQLConfig
1177:                                        .getAllProjectConf(DataModel
1178:                                                .getCurrentProject().getIdBdd());
1179:                                Locale locale = Locale.getDefault();
1180:                                DateFormat dateFormat = DateFormat
1181:                                        .getDateTimeInstance(DateFormat.LONG,
1182:                                                DateFormat.LONG, locale);
1183:                                java.util.Date date = new java.util.Date();
1184:                                String myDate = dateFormat.format(date);
1185:                                String key = bugTracker.getBugTrackerName()
1186:                                        + "_ICAL_" + env.getIdBdd();
1187:
1188:                                if (projectConfs.containsKey(key)) {
1189:                                    pISQLConfig.updateProjectConf(key,
1190:                                            (String) projectConfs.get(key)
1191:                                                    + "," + myDate + "_"
1192:                                                    + Float.toString(ical),
1193:                                            DataModel.getCurrentProject()
1194:                                                    .getIdBdd());
1195:                                } else {
1196:                                    pISQLConfig.insertProjectConf(bugTracker
1197:                                            .getBugTrackerName()
1198:                                            + "_ICAL_" + env.getIdBdd(), myDate
1199:                                            + "_" + Float.toString(ical),
1200:                                            DataModel.getCurrentProject()
1201:                                                    .getIdBdd());
1202:                                }
1203:
1204:                            } else {
1205:                                Util.log("[LookAndFeel] WARNING pISQLConfig = "
1206:                                        + pISQLConfig);
1207:                            }
1208:                        } catch (Exception E) {
1209:                            E.printStackTrace();
1210:                            Tools.ihmExceptionView(E);
1211:                        }
1212:
1213:                        JOptionPane
1214:                                .showMessageDialog(
1215:                                        new Frame(),
1216:                                        Language
1217:                                                .getInstance()
1218:                                                .getText(
1219:                                                        "ICAL_saved_confirmation_for_env"),
1220:                                        Language.getInstance().getText(
1221:                                                "Information_!"),
1222:                                        JOptionPane.INFORMATION_MESSAGE);
1223:
1224:                    }
1225:                }
1226:            }
1227:
1228:            void graphICALForEnv(BugTracker bugTracker, Environment env) {
1229:                JDialog dialog = new JDialog(
1230:                        SalomeTMFContext.getInstance().ptrFrame, true);
1231:                dialog.setTitle(Language.getInstance().getText("ICAL"));
1232:                JPanel pnl = new JPanel(new BorderLayout());
1233:                dialog.setContentPane(pnl);
1234:                dialog.setSize(600, 400);
1235:
1236:                try {
1237:                    String envICALKey = "";
1238:                    ISQLConfig pISQLConfig = Api.getISQLObjectFactory()
1239:                            .getISQLConfig();
1240:                    if (pISQLConfig != null) {
1241:                        Hashtable projectConfs = pISQLConfig
1242:                                .getAllProjectConf(DataModel
1243:                                        .getCurrentProject().getIdBdd());
1244:                        for (Enumeration e = projectConfs.keys(); e
1245:                                .hasMoreElements();) {
1246:                            String key = (String) e.nextElement();
1247:                            if (key.equals(bugTracker.getBugTrackerName()
1248:                                    + "_ICAL_" + env.getIdBdd())) {
1249:                                envICALKey = key;
1250:                            }
1251:                        }
1252:
1253:                        if ((envICALKey != null) && (!envICALKey.equals(""))) {
1254:
1255:                            TimeSeriesCollection dataset = new TimeSeriesCollection();
1256:                            TimeSeries ts = new TimeSeries(env
1257:                                    .getNameFromModel(), Second.class);
1258:                            String value = (String) projectConfs
1259:                                    .get(envICALKey);
1260:                            String[] res = value.split("[,]");
1261:                            for (int j = 0; j < res.length; j++) {
1262:                                String icalValues = res[j];
1263:                                String[] icals = icalValues.split("[_]");
1264:                                if (icals.length == 2) {
1265:                                    Locale locale = Locale.getDefault();
1266:                                    DateFormat dateFormat = DateFormat
1267:                                            .getDateTimeInstance(
1268:                                                    DateFormat.LONG,
1269:                                                    DateFormat.LONG, locale);
1270:                                    java.util.Date date = dateFormat
1271:                                            .parse(icals[0]);
1272:
1273:                                    float ical = Float.parseFloat(icals[1]);
1274:                                    ts.add(new TimeSeriesDataItem(new Second(
1275:                                            date), (double) ical));
1276:                                }
1277:                            }
1278:                            dataset.addSeries(ts);
1279:
1280:                            JFreeChart chart = ChartFactory
1281:                                    .createTimeSeriesChart(Language
1282:                                            .getInstance().getText(
1283:                                                    "ICALgraphForEnv")
1284:                                            + " '"
1285:                                            + env.getNameFromModel()
1286:                                            + "'", "Date", "ICAL (%)", dataset,
1287:                                            true, true, false);
1288:                            chart.setBackgroundPaint(Color.white);
1289:                            XYPlot plot = (XYPlot) chart.getPlot();
1290:                            plot.setBackgroundPaint(Color.lightGray);
1291:                            plot.setDomainGridlinePaint(Color.white);
1292:                            plot.setRangeGridlinePaint(Color.white);
1293:                            XYItemRenderer r = plot.getRenderer();
1294:                            if (r instanceof  XYLineAndShapeRenderer) {
1295:                                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
1296:                                renderer.setShapesVisible(true);
1297:                                renderer.setShapesFilled(true);
1298:                            }
1299:                            DateAxis axis = (DateAxis) plot.getDomainAxis();
1300:                            axis.setDateFormatOverride(new SimpleDateFormat(
1301:                                    "dd/MM/yy"));
1302:                            ValueAxis vAxis = (ValueAxis) plot.getRangeAxis();
1303:                            vAxis.setRange(0, 100);
1304:                            ChartPanel cPanel = new ChartPanel(chart);
1305:                            pnl.add(cPanel);
1306:
1307:                        } else {
1308:                            JLabel label = new JLabel(Language.getInstance()
1309:                                    .getText("No_ICAL_values_in_DB"));
1310:                            pnl.add(label);
1311:                        }
1312:
1313:                    } else {
1314:                        Util.log("[LookAndFeel] WARNING pISQLConfig = "
1315:                                + pISQLConfig);
1316:                    }
1317:                } catch (Exception e) {
1318:                    e.printStackTrace();
1319:                    Tools.ihmExceptionView(e);
1320:                }
1321:
1322:                dialog.setVisible(true);
1323:            }
1324:
1325:        } // Fin de la classe EnvironmentView
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.