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