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

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


001:        /*
002:         * SalomeTMF is a Test Management Framework
003:         * Copyright (C) 2005 France Telecom R&D
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:         *
019:         * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020:         *
021:         * Contact: mikael.marche@rd.francetelecom.com
022:         */
023:
024:        package org.objectweb.salome_tmf.ihm;
025:
026:        import java.awt.BorderLayout;
027:        import java.awt.Color;
028:        import java.awt.Component;
029:        import java.awt.Container;
030:        import java.awt.Dimension;
031:        import java.awt.FlowLayout;
032:        import java.awt.event.ActionEvent;
033:        import java.awt.event.ActionListener;
034:        import java.awt.event.WindowEvent;
035:        import java.awt.event.WindowListener;
036:        import java.util.ArrayList;
037:        import java.util.Collection;
038:        import java.util.Iterator;
039:
040:        import javax.swing.BorderFactory;
041:        import javax.swing.Box;
042:        import javax.swing.BoxLayout;
043:        import javax.swing.JButton;
044:        import javax.swing.JDialog;
045:        import javax.swing.JLabel;
046:        import javax.swing.JOptionPane;
047:        import javax.swing.JPanel;
048:        import javax.swing.JScrollPane;
049:        import javax.swing.JTextField;
050:        import javax.swing.JTextPane;
051:        import javax.swing.text.BadLocationException;
052:        import javax.swing.text.Style;
053:        import javax.swing.text.StyleConstants;
054:        import javax.swing.text.StyleContext;
055:        import javax.swing.text.StyledDocument;
056:
057:        import org.objectweb.salome_tmf.data.Action;
058:        import org.objectweb.salome_tmf.data.Attachment;
059:        import org.objectweb.salome_tmf.data.CampaignData;
060:        import org.objectweb.salome_tmf.data.ConnectionData;
061:        import org.objectweb.salome_tmf.data.DataConstants;
062:        import org.objectweb.salome_tmf.data.ManualTest;
063:        import org.objectweb.salome_tmf.data.Parameter;
064:        import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
065:        import org.objectweb.salome_tmf.ihm.languages.Language;
066:        import org.objectweb.salome_tmf.ihm.tools.Tools;
067:
068:        /**
069:         * Classe qui représente la vue pour ajouter/éditer une action
070:
071:         */
072:        public class AskNewAction extends JDialog implements  DataConstants,
073:                IHMConstants {
074:
075:            /**
076:             * La zone texte pour saisir le nom de l'action
077:             */
078:            JTextField nameField;
079:
080:            /**
081:             * La zone texte pour saisir la description
082:             */
083:            JTextPane descriptionArea;
084:
085:            /**
086:             * La zone texte pour saisir le résultat attendu
087:             */
088:            JTextPane awaitedResultArea;
089:
090:            Style paramStyleDescription;
091:            Style paramStyleAwaitedResult;
092:
093:            Style def;
094:
095:            Style regularDescription;
096:            Style regularAwaitedResult;
097:            StyledDocument descriptionDoc;
098:
099:            StyledDocument awaitedResultDoc;
100:
101:            /**
102:             * L'action crée
103:             */
104:            Action action;
105:
106:            AttachmentView attachmentPanel;
107:
108:            /**************************************************************************/
109:            /**							METHODES PUBLIQUES							***/
110:            /**************************************************************************/
111:
112:            /**
113:             * Constructeur de la vue pour ajouter/éditer une action
114:             * @param parent le composant père
115:             * @param title le titre du composant
116:             * @param name le nom de l'action
117:             * @param descr la description de l'action
118:             * @param result le résultat de l'action
119:             * @param attach la liste des attachements
120:             */
121:            public AskNewAction(Component parent, String title, Action oldAction) {
122:
123:                //Pour bloquer le focus sur la boite de dialogue
124:                super (SalomeTMF.ptrFrame, true);
125:                nameField = new JTextField(10);
126:                descriptionArea = new JTextPane();
127:                awaitedResultArea = new JTextPane();
128:                descriptionDoc = descriptionArea.getStyledDocument();
129:                awaitedResultDoc = descriptionArea.getStyledDocument();
130:                JPanel page = new JPanel();
131:
132:                // Cas ou le test est utilisé dans une campagne de test
133:                String message = CampaignData
134:                        .getCampaignWithExecResultWhereTestIsUse(DataModel
135:                                .getCurrentTest());
136:                if (!message.equals("")) {
137:                    nameField.setEditable(false);
138:                    descriptionArea.setEditable(false);
139:                    awaitedResultArea.setEditable(false);
140:                }
141:
142:                JLabel testNameLabel = new JLabel(Language.getInstance()
143:                        .getText("Nom_de_l'action_:_"));
144:
145:                JPanel giveName = new JPanel(new FlowLayout(FlowLayout.LEFT));
146:                giveName.add(Box.createHorizontalGlue());
147:                giveName.add(testNameLabel);
148:                giveName.add(Box.createRigidArea(new Dimension(10, 0)));
149:                giveName.add(nameField);
150:
151:                JScrollPane descriptionScrollPane = new JScrollPane(
152:                        descriptionArea);
153:                descriptionScrollPane.setBorder(BorderFactory
154:                        .createTitledBorder(BorderFactory
155:                                .createLineBorder(Color.BLACK), Language
156:                                .getInstance().getText("Description")));
157:                descriptionScrollPane.setPreferredSize(new Dimension(500, 100));
158:
159:                JScrollPane awaitedResultScrollPane = new JScrollPane(
160:                        awaitedResultArea);
161:                awaitedResultScrollPane.setBorder(BorderFactory
162:                        .createTitledBorder(BorderFactory
163:                                .createLineBorder(Color.BLACK), Language
164:                                .getInstance().getText("Résultat_attendu")));
165:                awaitedResultScrollPane
166:                        .setPreferredSize(new Dimension(500, 100));
167:
168:                JButton okButton = new JButton(Language.getInstance().getText(
169:                        "Valider"));
170:                okButton.setToolTipText(Language.getInstance().getText(
171:                        "Valider"));
172:                okButton.addActionListener(new ActionListener() {
173:                    public void actionPerformed(ActionEvent e) {
174:                        if (!nameField.getText().trim().equals("")) {
175:                            if (!((ManualTest) DataModel.getCurrentTest())
176:                                    .hasActionName(nameField.getText().trim())
177:                                    && !nameField.getText().trim().equals(
178:                                            DataModel.EMPTY_NAME)
179:                                    && !ConnectionData.isInBaseAction(DataModel
180:                                            .getCurrentTest(), nameField
181:                                            .getText().trim())) {
182:                                createAndQuit();
183:                            } else if (((ManualTest) DataModel.getCurrentTest())
184:                                    .getAction(nameField.getText().trim()) != null
185:                                    && ((ManualTest) DataModel.getCurrentTest())
186:                                            .getAction(
187:                                                    nameField.getText().trim())
188:                                            .equals(action)) {
189:                                createAndQuit();
190:                            } else {
191:                                JOptionPane
192:                                        .showMessageDialog(
193:                                                AskNewAction.this ,
194:                                                Language
195:                                                        .getInstance()
196:                                                        .getText(
197:                                                                "Ce_nom_d'action_existe_déjà_!"),
198:                                                Language.getInstance().getText(
199:                                                        "Erreur_!"),
200:                                                JOptionPane.ERROR_MESSAGE);
201:                            }
202:                        } else {
203:                            JOptionPane
204:                                    .showMessageDialog(
205:                                            AskNewAction.this ,
206:                                            Language
207:                                                    .getInstance()
208:                                                    .getText(
209:                                                            "Il_faut_obligatoirement_donner_un_nom_à_l'action_!"),
210:                                            Language.getInstance().getText(
211:                                                    "Attention_!"),
212:                                            JOptionPane.WARNING_MESSAGE);
213:                        }
214:                    }
215:                });
216:
217:                JButton cancelButton = new JButton(Language.getInstance()
218:                        .getText("Annuler"));
219:                cancelButton.setToolTipText(Language.getInstance().getText(
220:                        "Annuler"));
221:                cancelButton.addActionListener(new ActionListener() {
222:                    public void actionPerformed(ActionEvent e) {
223:                        action = null;
224:                        DataModel.initAttachmentTable(DataModel
225:                                .getCurrentTest().getAttachmentMap().values());
226:                        AskNewAction.this .dispose();
227:                    }
228:                });
229:
230:                JButton descriptionAddParameterButton = new JButton(Language
231:                        .getInstance().getText("Paramètre"));
232:                descriptionAddParameterButton.setIcon(Tools
233:                        .createAppletImageIcon(PATH_TO_PARAM_ICON, ""));
234:                descriptionAddParameterButton.setToolTipText(Language
235:                        .getInstance().getText(
236:                                "Ajouter_un_paramètre_à_la_description"));
237:                descriptionAddParameterButton
238:                        .addActionListener(new ActionListener() {
239:                            public void actionPerformed(ActionEvent e) {
240:                                addParameterInText(descriptionArea);
241:                            }
242:                        });
243:                // Cas ou le test est utilisé dans une campagne de test
244:                if (!message.equals("")) {
245:                    descriptionAddParameterButton.setEnabled(false);
246:                }
247:
248:                JButton resultAddParameterButton = new JButton(Language
249:                        .getInstance().getText("Paramètre"));
250:                resultAddParameterButton.setIcon(Tools.createAppletImageIcon(
251:                        PATH_TO_PARAM_ICON, ""));
252:                resultAddParameterButton.setToolTipText(Language.getInstance()
253:                        .getText("Ajouter_un_paramètre_au_résultat_attendu"));
254:                resultAddParameterButton
255:                        .addActionListener(new ActionListener() {
256:                            public void actionPerformed(ActionEvent e) {
257:                                addParameterInText(awaitedResultArea);
258:                            }
259:                        });
260:                // Cas ou le test est utilisé dans une campagne de test
261:                if (!message.equals("")) {
262:                    resultAddParameterButton.setEnabled(false);
263:                }
264:
265:                JPanel completeDescriptionPane = new JPanel();
266:                completeDescriptionPane.setLayout(new BoxLayout(
267:                        completeDescriptionPane, BoxLayout.X_AXIS));
268:                completeDescriptionPane.add(descriptionScrollPane);
269:                completeDescriptionPane.add(descriptionAddParameterButton);
270:
271:                JPanel completeAwaitedResultPane = new JPanel();
272:                completeAwaitedResultPane.setLayout(new BoxLayout(
273:                        completeAwaitedResultPane, BoxLayout.X_AXIS));
274:                completeAwaitedResultPane.add(awaitedResultScrollPane);
275:                completeAwaitedResultPane.add(resultAddParameterButton);
276:
277:                JPanel buttonPanel = new JPanel(new FlowLayout(
278:                        FlowLayout.CENTER));
279:                buttonPanel.add(okButton);
280:                buttonPanel.add(cancelButton);
281:
282:                JPanel textPanel = new JPanel();
283:                textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
284:                textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
285:                textPanel.add(giveName);
286:                textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
287:                textPanel.add(completeDescriptionPane);
288:                textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
289:                textPanel.add(completeAwaitedResultPane);
290:                textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
291:
292:                attachmentPanel = new AttachmentView(DataModel.getApplet(),
293:                        ACTION, ACTION, oldAction, SMALL_SIZE_FOR_ATTACH, null,
294:                        null, null);
295:                attachmentPanel.setBorder(BorderFactory.createTitledBorder(
296:                        BorderFactory.createLineBorder(Color.BLACK), Language
297:                                .getInstance().getText("Attachements")));
298:                textPanel.add(attachmentPanel);
299:
300:                JPanel centerPanel = new JPanel();
301:                centerPanel.add(textPanel);
302:
303:                page.setLayout(new BorderLayout());
304:                page.add(textPanel);
305:                page.add(buttonPanel, BorderLayout.SOUTH);
306:
307:                Container contentPaneFrame = this .getContentPane();
308:                contentPaneFrame.add(page, BorderLayout.CENTER);
309:
310:                def = StyleContext.getDefaultStyleContext().getStyle(
311:                        StyleContext.DEFAULT_STYLE);
312:
313:                regularDescription = descriptionDoc.addStyle("regularD", def);
314:                StyleConstants.setForeground(regularDescription, Color.BLACK);
315:                //		  Style souligné
316:                paramStyleDescription = descriptionDoc.addStyle("parameterD",
317:                        regularDescription);
318:                StyleConstants.setForeground(paramStyleDescription, Color.red);
319:
320:                regularAwaitedResult = descriptionDoc
321:                        .addStyle("regularAR", def);
322:                StyleConstants.setForeground(regularAwaitedResult, Color.BLACK);
323:                //		  Style souligné
324:                paramStyleAwaitedResult = descriptionDoc.addStyle(
325:                        "parameterAR", regularAwaitedResult);
326:                StyleConstants
327:                        .setForeground(paramStyleAwaitedResult, Color.red);
328:
329:                initData(oldAction);
330:
331:                this .addWindowListener(new WindowListener() {
332:                    public void windowClosing(WindowEvent e) {
333:                        action = null;
334:                        DataModel.initAttachmentTable(DataModel
335:                                .getCurrentTest().getAttachmentMap().values());
336:                    }
337:
338:                    public void windowDeiconified(WindowEvent e) {
339:                    }
340:
341:                    public void windowOpened(WindowEvent e) {
342:                    }
343:
344:                    public void windowActivated(WindowEvent e) {
345:                    }
346:
347:                    public void windowDeactivated(WindowEvent e) {
348:                    }
349:
350:                    public void windowClosed(WindowEvent e) {
351:                    }
352:
353:                    public void windowIconified(WindowEvent e) {
354:                    }
355:                });
356:
357:                this .setLocation(300, 80);
358:                this .setTitle(title);
359:                this .pack();
360:                this .setVisible(true);
361:
362:            } // Fin du constructeur AddAction/6
363:
364:            /**
365:             * Constructeur
366:             * @param parent le composant père
367:             * @param title le titre du composant
368:             */
369:            public AskNewAction(Component parent, String title) {
370:                this (parent, title, null);
371:            } // Fin du constructeur AddAction/2
372:
373:            /**************************************************************************/
374:            /**							METHODES PUBLIQUES							***/
375:            /**************************************************************************/
376:
377:            /**
378:             * Accesseur de l'action construite
379:             * @return une action
380:             */
381:            public Action getAction() {
382:                return action;
383:            } // Fin de la méthode getAction/0
384:
385:            private void initData(Action oldAction) {
386:                if (oldAction != null) {
387:                    action = oldAction;
388:                    //Initialisation pour édition
389:                    nameField.setText(oldAction.getName());
390:                    descriptionArea.setText(oldAction.getDescription());
391:                    awaitedResultArea.setText(oldAction.getAwaitedResult());
392:                    Collection col = oldAction.getAttachmentMap().values();
393:                    DataModel.initAttachmentTable(col);
394:                } else {
395:                    ManualTest test = (ManualTest) DataModel.getCurrentTest();
396:                    //action = new Action(test.getIdBDD());
397:                    action = new Action(test);
398:                    int i = DataModel.getActionTableModel().getRowCount();
399:                    while (test.getActionList().contains(
400:                            test.getAction("A" + i))) {
401:                        i++;
402:                    }
403:                    nameField.setText("A" + i);
404:                    DataModel.getAttachmentTableModel().clearTable();
405:                }
406:                DataModel.setCurrentAction(action);
407:
408:            }
409:
410:            /**
411:             *
412:             * @param area
413:             */
414:            private void addParameterInText(JTextPane textPane) {
415:                ParameterInsertionView insertView = new ParameterInsertionView();
416:                if (insertView.getParameter() != null) {
417:                    action.addParameter(insertView.getParameter());
418:                    try {
419:                        StyledDocument doc = (StyledDocument) textPane
420:                                .getDocument();
421:                        if (textPane.equals(awaitedResultArea)) {
422:
423:                            doc.insertString(textPane.getCaretPosition(),
424:                                    "$" + insertView.getParameter().getName()
425:                                            + "$", doc.getStyle("parameterAR"));
426:                            doc.insertString(doc.getLength(), " ", doc
427:                                    .getStyle("regularAR"));
428:                        } else {
429:                            doc.insertString(textPane.getCaretPosition(),
430:                                    "$" + insertView.getParameter().getName()
431:                                            + "$", doc.getStyle("parameterD"));
432:                            doc.insertString(doc.getLength(), " ", doc
433:                                    .getStyle("regularD"));
434:                        }
435:                    } catch (BadLocationException ble) {
436:                    }
437:                }
438:            } // Fin de la méthode addParameterInText/1
439:
440:            private void createAndQuit() {
441:
442:                action.setName(nameField.getText().trim());
443:                action.setDescription(descriptionArea.getText());
444:                action.setAwaitedResult(awaitedResultArea.getText());
445:                action.getAttachmentMap().clear();
446:                Collection values = attachmentPanel.getAttachmentMap().values();
447:                for (Iterator iter = values.iterator(); iter.hasNext();) {
448:                    action.addAttachment((Attachment) iter.next());
449:                }
450:                ArrayList paramInDesc = Tools
451:                        .getParametersInDescription(descriptionArea.getText(),
452:                                action.getParameterHashSet());
453:                ArrayList paramInAwaitedResult = Tools
454:                        .getParametersInDescription(
455:                                awaitedResultArea.getText(), action
456:                                        .getParameterHashSet());
457:                ArrayList toBeDelete = new ArrayList();
458:                for (Iterator iter = action.getParameterHashSet().iterator(); iter
459:                        .hasNext();) {
460:                    Parameter param = (Parameter) iter.next();
461:                    if (!paramInDesc.contains(param)
462:                            && !paramInAwaitedResult.contains(param))
463:                        toBeDelete.add(param);
464:                }
465:                for (int i = 0; i < toBeDelete.size(); i++) {
466:                    action.removeParameter((Parameter) toBeDelete.get(i));
467:                }
468:                DataModel.initAttachmentTable(DataModel.getCurrentTest()
469:                        .getAttachmentMap().values());
470:
471:                AskNewAction.this .dispose();
472:            }
473:
474:        } // Fin de la classe AddAction
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.