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 Aurore PENAULT
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023: package salomeTMF_plug.gen_doc_xml;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Color;
027: import java.awt.Container;
028: import java.awt.Dimension;
029: import java.awt.FlowLayout;
030: import java.awt.Font;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.io.File;
034: import java.io.FileInputStream;
035: import java.util.ArrayList;
036:
037: import javax.swing.BorderFactory;
038: import javax.swing.Box;
039: import javax.swing.BoxLayout;
040: import javax.swing.DefaultComboBoxModel;
041: import javax.swing.JButton;
042: import javax.swing.JCheckBox;
043: import javax.swing.JComboBox;
044: import javax.swing.JDialog;
045: import javax.swing.JFileChooser;
046: import javax.swing.JLabel;
047: import javax.swing.JOptionPane;
048: import javax.swing.JPanel;
049: import javax.swing.JScrollPane;
050: import javax.swing.JTextField;
051: import javax.swing.JTextPane;
052: import javax.swing.tree.DefaultMutableTreeNode;
053:
054: import org.dom4j.Document;
055: import org.dom4j.io.SAXReader;
056: import org.objectweb.salome_tmf.data.AdminVTData;
057: import org.objectweb.salome_tmf.data.Project;
058: import org.objectweb.salome_tmf.data.User;
059: import org.objectweb.salome_tmf.ihm.admin.Administration;
060: import org.objectweb.salome_tmf.ihm.admin.models.UserListRenderer;
061: import org.objectweb.salome_tmf.ihm.models.ScriptFileFilter;
062: import org.objectweb.salome_tmf.plugins.IPlugObject;
063:
064: import salomeTMF_plug.gen_doc_xml.languages.Language;
065:
066: public class CreateProjectDialog extends JDialog {
067:
068: /**
069: * Champ pour récupérer le nom du projet
070: */
071: private JTextField projetNameTextField;
072:
073: /**
074: * Modèle de données pour la liste des utilisateurs pouvant être admin
075: */
076: private DefaultComboBoxModel comboModel;
077:
078: /**
079: * La description du projet
080: */
081: private JTextPane descriptionArea;
082:
083: /**
084: * La liste des utilisateurs pouvant être admin
085: */
086: JComboBox adminNameComboBox;
087:
088: JLabel newProjectNameLabel;
089:
090: JScrollPane descriptionScrollPane;
091:
092: String errorMessage = "";
093:
094: JCheckBox importTestBox;
095: JLabel importTestLabel;
096: JButton testSelection;
097: JLabel tousTests;
098: boolean selectionDesTests = false;
099:
100: boolean initSelection = false;
101: ArrayList suiteSelectionList;
102: ArrayList familySelectionList;
103: ArrayList testSelectionList;
104: DefaultMutableTreeNode chosenRoot;
105:
106: String xmlFile;
107: JLabel sauvLabel;
108: JTextField sauvTF;
109: JButton sauvButton;
110:
111: boolean recupAttachPb = false;
112: boolean majAttachPb = false;
113:
114: Project newProject;
115:
116: Import traitement;
117:
118: AdminVTData pAdminVTData;
119: IPlugObject pIPlugObject;
120:
121: public CreateProjectDialog(IPlugObject iPlugObject) {
122: super (Administration.ptrFrame, true);
123: pAdminVTData = Administration.pAdminVTData;
124: this .pIPlugObject = iPlugObject;
125:
126: suiteSelectionList = new ArrayList();
127: familySelectionList = new ArrayList();
128: testSelectionList = new ArrayList();
129:
130: projetNameTextField = new JTextField(20);
131: comboModel = new DefaultComboBoxModel();
132: descriptionArea = new JTextPane();
133: adminNameComboBox = new JComboBox(comboModel);
134: // Partie supérieure
135: JLabel adminNameLabel = new JLabel(Language.getInstance()
136: .getText("Administrateur_du_projet"));
137:
138: adminNameComboBox.setRenderer(new UserListRenderer());
139: for (int i = 0; i < pAdminVTData.getAllUsersCountFromModel(); i++) {
140: comboModel.addElement(pAdminVTData.getAllUsersFromModel()
141: .get(i));
142: }
143:
144: JPanel adminPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
145: adminPanel.add(adminNameLabel);
146: adminPanel.add(adminNameComboBox);
147: adminPanel.setBorder(BorderFactory.createRaisedBevelBorder());
148:
149: JLabel newProjectLabel = new JLabel(Language.getInstance()
150: .getText("Nouveau_Projet"));
151: newProjectLabel.setFont(new Font(null, Font.BOLD, 18));
152: newProjectNameLabel = new JLabel(Language.getInstance()
153: .getText("Nom_du_nouveau_projet_:"));
154:
155: JPanel newProjectNamePanel = new JPanel(new FlowLayout(
156: FlowLayout.LEFT));
157: newProjectNamePanel.add(newProjectNameLabel);
158: newProjectNamePanel.add(projetNameTextField);
159:
160: descriptionArea.setPreferredSize(new Dimension(100, 150));
161: descriptionScrollPane = new JScrollPane(descriptionArea,
162: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
163: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
164: descriptionScrollPane.setBorder(BorderFactory
165: .createTitledBorder(BorderFactory
166: .createLineBorder(Color.BLACK), Language
167: .getInstance().getText("Description")));
168:
169: JPanel newProjectPanel = new JPanel();
170: newProjectPanel.setLayout(new BoxLayout(newProjectPanel,
171: BoxLayout.Y_AXIS));
172: newProjectPanel.add(newProjectLabel);
173: newProjectPanel.add(newProjectNamePanel);
174: newProjectPanel.add(descriptionScrollPane);
175: newProjectPanel.setBorder(BorderFactory
176: .createRaisedBevelBorder());
177:
178: importTestBox = new JCheckBox();
179: importTestBox.addActionListener(new ActionListener() {
180: public void actionPerformed(ActionEvent e) {
181: if (!importTestBox.isSelected()) {
182: testSelection.setEnabled(false);
183: } else {
184: testSelection.setEnabled(true);
185: }
186: }
187: });
188: importTestBox.setSelected(true);
189: importTestLabel = new JLabel(Language.getInstance().getText(
190: "Importer_uniquement_les_tests"));
191: testSelection = new JButton(Language.getInstance().getText(
192: "Sélection_des_tests..."));
193: testSelection.addActionListener(new ActionListener() {
194: public void actionPerformed(ActionEvent e) {
195: if (xmlFile == null || xmlFile.equals("")) {
196: JOptionPane
197: .showMessageDialog(
198: CreateProjectDialog.this ,
199: Language
200: .getInstance()
201: .getText(
202: "Avant_de_sélectionner_les_tests_à_importer,_veuillez_indiquer_le_fichier_XML_à_utiliser"),
203: Language.getInstance().getText(
204: "Erreur_!"),
205: JOptionPane.ERROR_MESSAGE);
206: } else {
207: Document doc = null;
208: try {
209: doc = xmlParser(xmlFile);
210: } catch (Exception ex) {
211: ex.printStackTrace();
212: errorMessage += Language
213: .getInstance()
214: .getText(
215: "Problème_lors_de_l'import_des_données_du_document_XML");
216: showErrorMessage();
217: }
218: if (initSelection) {
219: new ImportTestChooser(CreateProjectDialog.this ,
220: doc, true);
221: } else {
222: new ImportTestChooser(CreateProjectDialog.this ,
223: doc, false);
224: }
225: }
226: }
227: });
228: tousTests = new JLabel(Language.getInstance().getText(
229: "(Par_défaut,_tous_les_tests_sont_importés)"));
230: tousTests.setFont(new Font(null, Font.ITALIC, 12));
231:
232: JPanel importTestPanel = new JPanel();
233: importTestPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
234: importTestPanel.add(importTestBox);
235: importTestPanel.add(importTestLabel);
236:
237: JPanel selectTestPanel = new JPanel();
238: selectTestPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
239: selectTestPanel.add(testSelection);
240: selectTestPanel.add(tousTests);
241:
242: JPanel selectPanel = new JPanel();
243: selectPanel.setLayout(new BoxLayout(selectPanel,
244: BoxLayout.Y_AXIS));
245: selectPanel.setBorder(BorderFactory.createRaisedBevelBorder());
246: selectPanel.add(importTestPanel);
247: selectPanel.add(selectTestPanel);
248:
249: sauvLabel = new JLabel(Language.getInstance().getText(
250: "Fichier_XML_:"));
251: sauvTF = new JTextField(40);
252: sauvButton = new JButton(Language.getInstance().getText(
253: "Choisir..."));
254: sauvButton.addActionListener(new ActionListener() {
255: public void actionPerformed(ActionEvent e) {
256: JFileChooser fileChooser = new JFileChooser();
257: fileChooser
258: .addChoosableFileFilter(new ScriptFileFilter(
259: Language.getInstance().getText(
260: "Fichier_XML_[*.xml]"), ".xml"));
261: int returnVal = fileChooser.showDialog(
262: CreateProjectDialog.this , Language
263: .getInstance().getText("Sélectionner"));
264: if (returnVal == JFileChooser.APPROVE_OPTION) {
265: xmlFile = fileChooser.getSelectedFile()
266: .getAbsolutePath();
267: if (xmlFile.indexOf(".") != -1) {
268: if (!xmlFile
269: .substring(xmlFile.lastIndexOf("."))
270: .equals(".xml")) {
271: xmlFile += ".xml";
272: }
273: } else {
274: xmlFile += ".xml";
275: }
276: sauvTF.setText(xmlFile);
277: }
278: }
279: });
280:
281: JPanel sauvLabelPanel = new JPanel(new FlowLayout(
282: FlowLayout.LEFT));
283: sauvLabelPanel.add(sauvLabel);
284: JPanel sauvTFPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
285: sauvTFPanel.add(sauvTF);
286: JPanel sauvButtonPanel = new JPanel(new FlowLayout(
287: FlowLayout.LEFT));
288: sauvButtonPanel.add(sauvButton);
289:
290: JPanel sauvPanel = new JPanel();
291: sauvPanel.setLayout(new BoxLayout(sauvPanel, BoxLayout.Y_AXIS));
292: sauvPanel.setBorder(BorderFactory.createRaisedBevelBorder());
293: sauvPanel.add(sauvLabelPanel);
294: sauvPanel.add(sauvTFPanel);
295: sauvPanel.add(sauvButtonPanel);
296:
297: JButton validation = new JButton(Language.getInstance()
298: .getText("Valider"));
299: validation.setToolTipText(Language.getInstance().getText(
300: "Valider"));
301: validation.addActionListener(new ActionListener() {
302: public void actionPerformed(ActionEvent e) {
303: if (projetNameTextField.getText().trim() != null
304: && !projetNameTextField.getText().trim()
305: .equals("")) {
306: if (!pAdminVTData
307: .containsProjectInModel(projetNameTextField
308: .getText().trim())) {
309: if (adminNameComboBox.getSelectedItem() != null) {
310: if (!sauvTF.getText().equals("")) {
311: Document doc = null;
312: try {
313: doc = xmlParser(xmlFile);
314: } catch (Exception ex) {
315: ex.printStackTrace();
316: errorMessage += Language
317: .getInstance()
318: .getText(
319: "Problème_lors_de_l'import_des_données_du_document_XML");
320: showErrorMessage();
321: }
322: newProject = new Project(
323: projetNameTextField.getText()
324: .trim(),
325: descriptionArea.getText());
326: //newProject.setName(projetNameTextField.getText().trim());
327: newProject
328: .setAdministratorInModel((User) adminNameComboBox
329: .getSelectedItem());
330: //newProject.setDescription(descriptionArea.getText());
331: traitement = new Import(
332: CreateProjectDialog.this , doc,
333: familySelectionList,
334: suiteSelectionList,
335: testSelectionList,
336: pAdminVTData, pIPlugObject);
337: traitement
338: .setDirXml(xmlFile
339: .substring(
340: 0,
341: xmlFile
342: .lastIndexOf(System
343: .getProperties()
344: .getProperty(
345: "file.separator"))));
346: traitement
347: .setSelectionDesTests(selectionDesTests);
348: traitement
349: .setImportOnlyTests(importTestBox
350: .isSelected());
351: traitement.importInNewProject();
352: if (!traitement.isAnnule()) {
353: if (errorMessage.equals("")) {
354: JOptionPane
355: .showMessageDialog(
356: CreateProjectDialog.this ,
357: Language
358: .getInstance()
359: .getText(
360: "L'import_s'est_terminée_avec_succès."),
361: Language
362: .getInstance()
363: .getText(
364: "Information..."),
365: JOptionPane.INFORMATION_MESSAGE);
366: CreateProjectDialog.this
367: .dispose();
368: } else {
369: JOptionPane
370: .showMessageDialog(
371: CreateProjectDialog.this ,
372: errorMessage,
373: Language
374: .getInstance()
375: .getText(
376: "Erreur..."),
377: JOptionPane.ERROR_MESSAGE);
378: CreateProjectDialog.this
379: .dispose();
380: }
381: } else if (!errorMessage.equals("")) {
382: JOptionPane
383: .showMessageDialog(
384: CreateProjectDialog.this ,
385: errorMessage,
386: Language
387: .getInstance()
388: .getText(
389: "Erreur..."),
390: JOptionPane.ERROR_MESSAGE);
391: CreateProjectDialog.this .dispose();
392: }
393: } else {
394: JOptionPane
395: .showMessageDialog(
396: CreateProjectDialog.this ,
397: Language
398: .getInstance()
399: .getText(
400: "Vous_devez_entrez_un_nom_de_fichier_pour_le_document_généré"),
401: Language
402: .getInstance()
403: .getText(
404: "Erreur_!"),
405: JOptionPane.ERROR_MESSAGE);
406: }
407: } else {
408: JOptionPane
409: .showMessageDialog(
410: CreateProjectDialog.this ,
411: Language
412: .getInstance()
413: .getText(
414: "Il_faut_obligatoirement_nommer_un_administrateur_au_projet_!"),
415: Language
416: .getInstance()
417: .getText(
418: "Attention_!"),
419: JOptionPane.WARNING_MESSAGE);
420: }
421: } else {
422: JOptionPane
423: .showMessageDialog(
424: CreateProjectDialog.this ,
425: Language
426: .getInstance()
427: .getText(
428: "Ce_nom_de_projet_existe_déjà_!"),
429: Language.getInstance().getText(
430: "Attention_!"),
431: JOptionPane.WARNING_MESSAGE);
432: }
433: } else {
434: JOptionPane
435: .showMessageDialog(
436: CreateProjectDialog.this ,
437: Language
438: .getInstance()
439: .getText(
440: "Il_faut_obligatoirement_donner_un_nom_au_projet_!"),
441: Language.getInstance().getText(
442: "Attention_!"),
443: JOptionPane.WARNING_MESSAGE);
444: }
445: }
446: });
447:
448: JButton cancel = new JButton(Language.getInstance().getText(
449: "Annuler"));
450: cancel
451: .setToolTipText(Language.getInstance().getText(
452: "Annuler"));
453: cancel.addActionListener(new ActionListener() {
454: public void actionPerformed(ActionEvent e) {
455: if (traitement != null) {
456: traitement.setAnnule(true);
457: CreateProjectDialog.this .dispose();
458: }
459: CreateProjectDialog.this .dispose();
460: }
461: });
462:
463: JPanel buttonsSet = new JPanel(new FlowLayout(FlowLayout.RIGHT));
464: buttonsSet.add(validation);
465: buttonsSet.add(cancel);
466:
467: JPanel page = new JPanel();
468: page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
469: page.add(Box.createVerticalStrut(10));
470: page.add(adminPanel);
471: page.add(Box.createVerticalStrut(10));
472: page.add(newProjectPanel);
473: page.add(Box.createVerticalStrut(10));
474: page.add(sauvPanel);
475: page.add(Box.createVerticalStrut(10));
476: page.add(selectPanel);
477: page.add(Box.createVerticalStrut(10));
478: page.add(buttonsSet);
479:
480: Container contentPaneFrame = this .getContentPane();
481: contentPaneFrame.add(page, BorderLayout.CENTER);
482:
483: this .setTitle(Language.getInstance().getText(
484: "Créer_un_nouveau_projet"));
485: this .pack();
486: this .setLocation(300, 100);
487: this .setVisible(true);
488: }
489:
490: /**
491: * Méthode qui parse le document XML dont le chemin est indiqué dans "path"
492: * @param path
493: * @return un document DOM4J
494: * @throws Exception
495: */
496: public Document xmlParser(String path) throws Exception {
497: SAXReader reader = new SAXReader(false);
498: Document doc = reader.read(new FileInputStream(new File(path)));
499: return doc;
500: }
501:
502: /**
503: * Méthode qui affiche les messages d'erreur
504: * @return
505: */
506: public void showErrorMessage() {
507: JOptionPane
508: .showMessageDialog(CreateProjectDialog.this ,
509: errorMessage, Language.getInstance().getText(
510: "Erreur_!"), JOptionPane.ERROR_MESSAGE);
511: CreateProjectDialog.this .dispose();
512: }
513:
514: /**
515: * @return Returns the chosenRoot.
516: */
517: public DefaultMutableTreeNode getChosenRoot() {
518: return chosenRoot;
519: }
520:
521: /**
522: * @param chosenRoot The chosenRoot to set.
523: */
524: public void setChosenRoot(DefaultMutableTreeNode chosenRoot) {
525: this .chosenRoot = chosenRoot;
526: }
527:
528: /**
529: * @return Returns the initSelection.
530: */
531: public boolean isInitSelection() {
532: return initSelection;
533: }
534:
535: /**
536: * @param initSelection The initSelection to set.
537: */
538: public void setInitSelection(boolean initSelection) {
539: this .initSelection = initSelection;
540: }
541:
542: /**
543: * @return Returns the familySelectionList.
544: */
545: public ArrayList getFamilySelectionList() {
546: return familySelectionList;
547: }
548:
549: /**
550: * @param familySelectionList The familySelectionList to set.
551: */
552: public void setFamilySelectionList(ArrayList familySelectionList) {
553: this .familySelectionList = familySelectionList;
554: }
555:
556: /**
557: * @return Returns the suiteSelectionList.
558: */
559: public ArrayList getSuiteSelectionList() {
560: return suiteSelectionList;
561: }
562:
563: /**
564: * @param suiteSelectionList The suiteSelectionList to set.
565: */
566: public void setSuiteSelectionList(ArrayList suiteSelectionList) {
567: this .suiteSelectionList = suiteSelectionList;
568: }
569:
570: /**
571: * @return Returns the testSelectionList.
572: */
573: public ArrayList getTestSelectionList() {
574: return testSelectionList;
575: }
576:
577: /**
578: * @param testSelectionList The testSelectionList to set.
579: */
580: public void setTestSelectionList(ArrayList testSelectionList) {
581: this .testSelectionList = testSelectionList;
582: }
583:
584: /**
585: * @return Returns the selectionDesTests.
586: */
587: public boolean isSelectionDesTests() {
588: return selectionDesTests;
589: }
590:
591: /**
592: * @param selectionDesTests The selectionDesTests to set.
593: */
594: public void setSelectionDesTests(boolean selectionDesTests) {
595: this .selectionDesTests = selectionDesTests;
596: }
597:
598: /**
599: * @return Returns the newProject.
600: */
601: public Project getNewProject() {
602: return newProject;
603: }
604:
605: /**
606: * @param newProject The newProject to set.
607: */
608: public void setNewProject(Project newProject) {
609: this .newProject = newProject;
610: }
611:
612: /**
613: * @return Returns the errorMessage.
614: */
615: public String getErrorMessage() {
616: return errorMessage;
617: }
618:
619: /**
620: * @param errorMessage The errorMessage to set.
621: */
622: public void setErrorMessage(String errorMessage) {
623: this .errorMessage = errorMessage;
624: }
625:
626: /**
627: * @return Returns the recupAttachPb.
628: */
629: public boolean isRecupAttachPb() {
630: return recupAttachPb;
631: }
632:
633: /**
634: * @param recupAttachPb The recupAttachPb to set.
635: */
636: public void setRecupAttachPb(boolean recupAttachPb) {
637: this .recupAttachPb = recupAttachPb;
638: }
639:
640: /**
641: * @return Returns the majAttachPb.
642: */
643: public boolean isMajAttachPb() {
644: return majAttachPb;
645: }
646:
647: /**
648: * @param majAttachPb The majAttachPb to set.
649: */
650: public void setMajAttachPb(boolean majAttachPb) {
651: this.majAttachPb = majAttachPb;
652: }
653: }
|