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.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.util.Enumeration;
034:
035: import javax.swing.BorderFactory;
036: import javax.swing.Box;
037: import javax.swing.BoxLayout;
038: import javax.swing.JButton;
039: import javax.swing.JComboBox;
040: import javax.swing.JDialog;
041: import javax.swing.JLabel;
042: import javax.swing.JOptionPane;
043: import javax.swing.JPanel;
044: import javax.swing.JScrollPane;
045: import javax.swing.JTextArea;
046: import javax.swing.JTextField;
047:
048: import org.java.plugin.Extension;
049: import org.objectweb.salome_tmf.data.AutomaticTest;
050: import org.objectweb.salome_tmf.data.ManualTest;
051: import org.objectweb.salome_tmf.data.ProjectData;
052: import org.objectweb.salome_tmf.data.Test;
053: import org.objectweb.salome_tmf.ihm.languages.Language;
054:
055: /**
056: * Classe permettant de créer une vue pour entrer un noouveau test
057: * @author teaml039
058: * @version 0.1
059: */
060: public class AskNewTest extends JDialog {
061:
062: /**
063: * Le nom du test
064: */
065: JTextField testNameField;
066:
067: /**
068: * Le concepteur du test
069: */
070: JComboBox conceptorNameList;
071:
072: /**
073: * Types de tests
074: */
075: String[] types;
076: //String[] types = {"Manuel", "Automatique"};
077:
078: //Extension[] tabExtension;
079: /**
080: * Liste permettant de choisir le test
081: */
082: JComboBox typesList;
083:
084: /**
085: * La decsription du test
086: */
087: JTextArea descriptionArea;
088:
089: /**
090: * Le nouveau test
091: */
092: Test test;
093:
094: /******************************************************************************/
095: /** CONSTRUCTEUR ***/
096: /******************************************************************************/
097:
098: /**
099: * Constructeur de la fenêtre.
100: * @param textToBePrompt chaîne correspondant à la demande.
101: */
102: public AskNewTest(Component parent, String textToBePrompt) {
103:
104: //Pour bloquer le focus sur la boite de dialogue
105: super (SalomeTMF.ptrFrame, true);
106: initType();
107: JPanel page = new JPanel();
108: testNameField = new JTextField(10);
109: //descriptionArea = new JTextArea();
110: descriptionArea = new JTextArea(10, 20);
111: typesList = new JComboBox(types);
112: conceptorNameList = new JComboBox();
113: JLabel testNameLabel = new JLabel(Language.getInstance()
114: .getText("Nom_du_test_:_"));
115: JLabel conceptorNameLabel = new JLabel(Language.getInstance()
116: .getText("Nom_du_concepteur_:"));
117: //JLabel descriptionLabel = new JLabel("Description");
118:
119: JPanel giveName = new JPanel();
120: giveName.setLayout(new BoxLayout(giveName, BoxLayout.X_AXIS));
121: giveName.add(Box.createHorizontalGlue());
122: giveName.add(testNameLabel);
123: giveName.add(Box.createRigidArea(new Dimension(10, 0)));
124: giveName.add(testNameField);
125:
126: JPanel giveConceptorName = new JPanel();
127: giveConceptorName.setLayout(new BoxLayout(giveConceptorName,
128: BoxLayout.X_AXIS));
129: giveConceptorName.setBorder(BorderFactory.createEmptyBorder(0,
130: 10, 10, 10));
131: giveConceptorName.add(Box.createHorizontalGlue());
132: giveConceptorName.add(conceptorNameLabel);
133: giveConceptorName
134: .add(Box.createRigidArea(new Dimension(10, 0)));
135: giveConceptorName.add(conceptorNameList);
136:
137: JScrollPane descriptionScrollPane = new JScrollPane(
138: descriptionArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
139: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
140: descriptionScrollPane.setBorder(BorderFactory
141: .createTitledBorder(BorderFactory
142: .createLineBorder(Color.BLACK), Language
143: .getInstance().getText("Description")));
144:
145: JPanel textPanel = new JPanel();
146: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
147: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
148: textPanel.add(giveName);
149: textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
150: textPanel.add(typesList);
151: textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
152: textPanel.add(descriptionScrollPane);
153:
154: JButton okButton = new JButton(Language.getInstance().getText(
155: "Valider"));
156: okButton.setToolTipText(Language.getInstance().getText(
157: "Valider"));
158: okButton.addActionListener(new ActionListener() {
159: public void actionPerformed(ActionEvent e) {
160:
161: if (testNameField.getText() != null
162: && !testNameField.getText().trim().equals("")) {
163: if (((String) typesList.getSelectedItem())
164: .equalsIgnoreCase(Language.getInstance()
165: .getText("Manuel"))) {
166: test = new ManualTest();
167: } else {
168: test = new AutomaticTest((String) typesList
169: .getSelectedItem());
170: }
171: test.setName(testNameField.getText().trim());
172: test.setConceptor(ProjectData.getCurrentUser()
173: .getLogin());
174: test.setDescription(descriptionArea.getText());
175: AskNewTest.this .dispose();
176: } else {
177: JOptionPane
178: .showMessageDialog(
179: AskNewTest.this ,
180: Language
181: .getInstance()
182: .getText(
183: "Il_faut_obligatoirement_donner_un_nom_au_test_!"),
184: Language.getInstance().getText(
185: "Attention_!"),
186: JOptionPane.WARNING_MESSAGE);
187: }
188: }
189: });
190:
191: testNameField.addActionListener(new ActionListener() {
192: public void actionPerformed(ActionEvent e) {
193: }
194: });
195:
196: JButton cancelButton = new JButton(Language.getInstance()
197: .getText("Annuler"));
198: cancelButton.setToolTipText(Language.getInstance().getText(
199: "Annuler"));
200: cancelButton.addActionListener(new ActionListener() {
201: public void actionPerformed(ActionEvent e) {
202: AskNewTest.this .dispose();
203: }
204: });
205:
206: JPanel buttonPanel = new JPanel();
207: buttonPanel.setLayout(new BorderLayout());
208: buttonPanel.add(okButton, BorderLayout.NORTH);
209: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
210:
211: page.add(textPanel, BorderLayout.WEST);
212: page.add(Box.createRigidArea(new Dimension(40, 10)),
213: BorderLayout.CENTER);
214: page.add(buttonPanel, BorderLayout.EAST);
215:
216: Container contentPaneFrame = this .getContentPane();
217: contentPaneFrame.add(page, BorderLayout.CENTER);
218:
219: this .setLocation(400, 300);
220: this .setTitle(textToBePrompt);
221: this .pack();
222: this .setVisible(true);
223:
224: } // Fin du constructeur AskName/1
225:
226: /******************************************************************************/
227: /** METHODES PUBLIQUES ***/
228: /******************************************************************************/
229:
230: /**
231: * Méthode qui retourne le test créé
232: * @return le test, <code>null</code> si aucun test créé
233: */
234: public Test getTest() {
235: return test;
236: } // Fin de la méthode getTest/0
237:
238: private void initType() {
239: int i = 1;
240: types = new String[SalomeTMF.associatedTestDriver.size() + 1];
241: types[0] = Language.getInstance().getText("Manuel");
242: Enumeration e = SalomeTMF.associatedTestDriver.keys();
243: while (e.hasMoreElements()) {
244: Extension testDriverExt = (Extension) e.nextElement();
245: //tabExtension[i-1] = testDriverExt;
246: types[i] = testDriverExt.getId();
247: i++;
248: }
249: }
250:
251: } // Fin de la classe AskNewTest
|