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:
024: package salomeTMF_plug.gen_doc_xml;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Container;
028: import java.awt.FlowLayout;
029: import java.awt.Font;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032: import java.io.File;
033: import java.io.FileInputStream;
034: import java.util.ArrayList;
035:
036: import javax.swing.BorderFactory;
037: import javax.swing.Box;
038: import javax.swing.BoxLayout;
039: import javax.swing.ButtonGroup;
040: import javax.swing.JButton;
041: import javax.swing.JCheckBox;
042: import javax.swing.JDialog;
043: import javax.swing.JFileChooser;
044: import javax.swing.JLabel;
045: import javax.swing.JOptionPane;
046: import javax.swing.JPanel;
047: import javax.swing.JProgressBar;
048: import javax.swing.JRadioButton;
049: import javax.swing.JTabbedPane;
050: import javax.swing.JTextField;
051: import javax.swing.tree.DefaultMutableTreeNode;
052:
053: import org.dom4j.Document;
054: import org.dom4j.io.SAXReader;
055: import org.java.plugin.Extension;
056: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
057: import org.objectweb.salome_tmf.ihm.models.ScriptFileFilter;
058: import org.objectweb.salome_tmf.plugins.IPlugObject;
059:
060: import salomeTMF_plug.gen_doc_xml.languages.Language;
061:
062: /**
063: *
064: * @author vapu8214
065: */
066: public class ImportDialog extends JDialog {
067:
068: private static String fs = System.getProperties().getProperty(
069: "file.separator");
070:
071: /* private final int TEST = 1;
072: private final int CAMPAIGN = 2;
073: private final int EXECUTION = 3;
074: private final int RESEXECUTION = 4;
075: private final int ACTION = 5;
076: */
077: JCheckBox importTestBox;
078: JCheckBox importReqBox;
079:
080: JLabel importTestLabel;
081: JLabel importReqLabel;
082:
083: JButton testSelection;
084: JLabel tousTests;
085: boolean selectionDesTests = false;
086:
087: String xmlFile;
088: JLabel sauvLabel;
089: JTextField sauvTF;
090: JButton sauvButton;
091:
092: JButton valider;
093: JButton annuler;
094:
095: JCheckBox suppr;
096: JLabel supprLabel;
097:
098: JCheckBox supprActionCheck;
099: JLabel supprActionLabel;
100:
101: JLabel conflitLabel;
102: JRadioButton neRienFaire;
103: JLabel neRienFaireLabel;
104: JRadioButton creerCopie;
105: JLabel creerCopieLabel;
106: JRadioButton miseAJour;
107: JLabel miseAJourLabel;
108:
109: JProgressBar progress;
110:
111: // private boolean update = true;
112: private boolean conflit = false;
113: private boolean creer_copy = false;
114: private boolean existeModif = false;
115: private boolean majPossible = false;
116: private boolean supprElement = false;
117: private boolean supprAction = false;
118:
119: String errorMessage = "";
120: boolean recupAttachPb = false;
121: boolean majAttachPb = false;
122:
123: boolean initSelection = false;
124: ArrayList suiteSelectionList;
125: ArrayList familySelectionList;
126: ArrayList testSelectionList;
127: DefaultMutableTreeNode chosenRoot;
128:
129: Import traitement;
130:
131: Thread t;
132: IPlugObject pIPlugObject;
133: Extension ext = null;
134:
135: /** Creates a new instance of Import */
136: public ImportDialog(IPlugObject iPlugObject) {
137: super (SalomeTMFContext.getInstance().getSalomeFrame(), true);
138: this .pIPlugObject = iPlugObject;
139: suiteSelectionList = new ArrayList();
140: familySelectionList = new ArrayList();
141: testSelectionList = new ArrayList();
142:
143: importTestBox = new JCheckBox();
144: importTestBox.addActionListener(new ActionListener() {
145: public void actionPerformed(ActionEvent e) {
146: if (!importTestBox.isSelected()) {
147: testSelection.setEnabled(false);
148: } else {
149: testSelection.setEnabled(true);
150: }
151: }
152: });
153: importTestBox.setSelected(true);
154:
155: importReqBox = new JCheckBox();
156: /*importReqBox.addActionListener(new ActionListener(){
157: public void actionPerformed(ActionEvent e){
158: }
159: });*/
160: importReqBox.setSelected(true);
161:
162: importTestLabel = new JLabel(Language.getInstance().getText(
163: "Importer_uniquement_les_tests"));
164: ext = (Extension) pIPlugObject
165: .getAssociatedExtension("requirements.Common");
166:
167: if (ext != null) {
168: importReqLabel = new JLabel(Language.getInstance().getText(
169: "Importer_les_exigences"));
170: }
171:
172: testSelection = new JButton(Language.getInstance().getText(
173: "Sélection_des_tests..."));
174: testSelection.addActionListener(new ActionListener() {
175: public void actionPerformed(ActionEvent e) {
176: if (xmlFile == null || xmlFile.equals("")) {
177: JOptionPane
178: .showMessageDialog(
179: ImportDialog.this ,
180: Language
181: .getInstance()
182: .getText(
183: "Avant_de_sélectionner_les_tests_à_importer,_veuillez_indiquer_le_fichier_XML_à_utiliser"),
184: Language.getInstance().getText(
185: "Erreur_!"),
186: JOptionPane.ERROR_MESSAGE);
187: } else {
188: Document doc = null;
189: try {
190: doc = xmlParser(xmlFile);
191: } catch (Exception ex) {
192: ex.printStackTrace();
193: errorMessage += Language
194: .getInstance()
195: .getText(
196: "Problème_lors_de_l'import_des_données_du_document_XML");
197: showErrorMessage();
198: }
199: if (initSelection) {
200: new ImportTestChooser(ImportDialog.this , doc,
201: true);
202: } else {
203: new ImportTestChooser(ImportDialog.this , doc,
204: false);
205: }
206: }
207: }
208: });
209: tousTests = new JLabel(Language.getInstance().getText(
210: "(Par_défaut,_tous_les_tests_sont_importés)"));
211: tousTests.setFont(new Font(null, Font.ITALIC, 12));
212:
213: sauvLabel = new JLabel(Language.getInstance().getText(
214: "Fichier_XML_:"));
215: sauvTF = new JTextField(50);
216: sauvButton = new JButton(Language.getInstance().getText(
217: "Choisir..."));
218: sauvButton.addActionListener(new ActionListener() {
219: public void actionPerformed(ActionEvent e) {
220: JFileChooser fileChooser = new JFileChooser();
221: fileChooser
222: .addChoosableFileFilter(new ScriptFileFilter(
223: Language.getInstance().getText(
224: "Fichier_XML_[*.xml]"), ".xml"));
225: int returnVal = fileChooser.showDialog(
226: ImportDialog.this , Language.getInstance()
227: .getText("Sélectionner"));
228: if (returnVal == JFileChooser.APPROVE_OPTION) {
229: xmlFile = fileChooser.getSelectedFile()
230: .getAbsolutePath();
231: if (xmlFile.indexOf(".") != -1) {
232: if (!xmlFile
233: .substring(xmlFile.lastIndexOf("."))
234: .equals(".xml")) {
235: xmlFile += ".xml";
236: }
237: } else {
238: xmlFile += ".xml";
239: }
240: sauvTF.setText(xmlFile);
241: }
242: }
243: });
244:
245: valider = new JButton(Language.getInstance().getText("OK"));
246: valider.addActionListener(new ActionListener() {
247: public void actionPerformed(ActionEvent e) {
248: if (xmlFile == null || xmlFile.equals("")) {
249: JOptionPane
250: .showMessageDialog(
251: ImportDialog.this ,
252: Language
253: .getInstance()
254: .getText(
255: "Vous_devez_entrer_un_nom_de_fichier_pour_le_document_d'import"),
256: Language.getInstance().getText(
257: "Erreur_!"),
258: JOptionPane.ERROR_MESSAGE);
259: } else {
260: t = new Thread() {
261: public void run() {
262: String dirXml = xmlFile.substring(0,
263: xmlFile.lastIndexOf(fs));
264: if (creerCopie.isSelected()) {
265: creer_copy = true;
266: } else if (miseAJour.isSelected()) {
267: majPossible = true;
268: }
269: if (supprActionCheck.isSelected()) {
270: supprAction = true;
271: }
272: if (suppr.isSelected()) {
273: supprElement = true;
274: }
275: if (sauvTF.getText().equals("")) {
276: JOptionPane
277: .showMessageDialog(
278: ImportDialog.this ,
279: Language
280: .getInstance()
281: .getText(
282: "Vous_devez_entrez_un_nom_de_fichier_pour_le_document_généré"),
283: Language
284: .getInstance()
285: .getText(
286: "Erreur_!"),
287: JOptionPane.ERROR_MESSAGE);
288: } else {
289: progress.setIndeterminate(true);
290: try {
291: traitement = new Import(
292: ImportDialog.this ,
293: xmlParser(xmlFile),
294: familySelectionList,
295: suiteSelectionList,
296: testSelectionList, null,
297: pIPlugObject);
298: } catch (Exception e) {
299: e.printStackTrace();
300: errorMessage += Language
301: .getInstance()
302: .getText(
303: "Problème_lors_de_l'import_des_données_du_document_XML");
304: showErrorMessage();
305: traitement.setAnnule(true);
306: }
307: traitement
308: .setImportOnlyTests(importTestBox
309: .isSelected());
310: traitement.setDirXml(dirXml);
311: traitement
312: .setSelectionDesTests(isInitSelection());
313: traitement
314: .setImportOnlyTests(importTestBox
315: .isSelected());
316: if (ext != null) {
317: traitement
318: .setImportRequirement(importReqBox
319: .isSelected());
320: }
321: traitement.importInProject();
322: if (!traitement.isAnnule()) {
323: if (errorMessage.equals("")) {
324: progress.setVisible(false);
325: JOptionPane
326: .showMessageDialog(
327: ImportDialog.this ,
328: Language
329: .getInstance()
330: .getText(
331: "L'import_s'est_terminée_avec_succès."),
332: Language
333: .getInstance()
334: .getText(
335: "Information..."),
336: JOptionPane.INFORMATION_MESSAGE);
337: ImportDialog.this .dispose();
338: } else {
339: progress.setVisible(false);
340: JOptionPane
341: .showMessageDialog(
342: ImportDialog.this ,
343: errorMessage,
344: Language
345: .getInstance()
346: .getText(
347: "Erreur..."),
348: JOptionPane.ERROR_MESSAGE);
349: ImportDialog.this .dispose();
350: }
351: } else if (!errorMessage.equals("")) {
352: progress.setVisible(false);
353: JOptionPane
354: .showMessageDialog(
355: ImportDialog.this ,
356: errorMessage,
357: Language
358: .getInstance()
359: .getText(
360: "Erreur..."),
361: JOptionPane.ERROR_MESSAGE);
362: ImportDialog.this .dispose();
363: }
364: }
365: }
366: };
367: t.start();
368: }
369: }
370: });
371:
372: annuler = new JButton(Language.getInstance().getText("Annuler"));
373: annuler.addActionListener(new ActionListener() {
374: public void actionPerformed(ActionEvent e) {
375: if (traitement != null) {
376: traitement.setAnnule(true);
377: }
378: ImportDialog.this .dispose();
379: }
380: });
381:
382: JPanel importTestPanel = new JPanel();
383: importTestPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
384: importTestPanel.add(importTestBox);
385: importTestPanel.add(importTestLabel);
386:
387: JPanel importReqPanel = null;
388: if (ext != null) {
389: importReqPanel = new JPanel();
390: importReqPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
391: importReqPanel.add(importReqBox);
392: importReqPanel.add(importReqLabel);
393: }
394:
395: JPanel selectTestPanel = new JPanel();
396: selectTestPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
397: selectTestPanel.add(testSelection);
398: selectTestPanel.add(tousTests);
399:
400: JPanel selectPanel = new JPanel();
401: selectPanel.setLayout(new BoxLayout(selectPanel,
402: BoxLayout.Y_AXIS));
403: selectPanel.setBorder(BorderFactory.createTitledBorder(""));
404: selectPanel.add(importTestPanel);
405: if (ext != null) {
406: selectPanel.add(importReqPanel);
407: }
408: selectPanel.add(selectTestPanel);
409:
410: JPanel sauvLabelPanel = new JPanel(new FlowLayout(
411: FlowLayout.LEFT));
412: sauvLabelPanel.add(sauvLabel);
413: JPanel sauvTFPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
414: sauvTFPanel.add(sauvTF);
415: JPanel sauvButtonPanel = new JPanel(new FlowLayout(
416: FlowLayout.LEFT));
417: sauvButtonPanel.add(sauvButton);
418:
419: JPanel sauvPanel = new JPanel();
420: sauvPanel.setLayout(new BoxLayout(sauvPanel, BoxLayout.Y_AXIS));
421: sauvPanel.setBorder(BorderFactory.createTitledBorder(""));
422: sauvPanel.add(sauvLabelPanel);
423: sauvPanel.add(sauvTFPanel);
424: sauvPanel.add(sauvButtonPanel);
425:
426: JPanel buttons = new JPanel();
427: buttons.add(valider);
428: buttons.add(annuler);
429:
430: progress = new JProgressBar();
431: JPanel progression = new JPanel(new FlowLayout(
432: FlowLayout.CENTER));
433: progression.add(progress);
434:
435: JPanel page = new JPanel();
436: page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
437: page.add(Box.createVerticalStrut(10));
438: page.add(sauvPanel);
439: page.add(Box.createVerticalStrut(10));
440: page.add(selectPanel);
441: page.add(Box.createVerticalStrut(10));
442: page.add(buttons);
443: page.add(progression);
444:
445: suppr = new JCheckBox();
446: supprLabel = new JLabel(
447: Language
448: .getInstance()
449: .getText(
450: "Supprimer_les_éléments_qui_ne_sont_pas_dans_le_document_XML"));
451: JPanel supprPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
452: supprPanel.add(suppr);
453: supprPanel.add(supprLabel);
454:
455: supprActionCheck = new JCheckBox();
456: supprActionLabel = new JLabel(
457: Language
458: .getInstance()
459: .getText(
460: "Supprimer_les_informations_des_tests_absentes_dans_le_document_XML"));
461: JPanel supprActionPanel = new JPanel(new FlowLayout(
462: FlowLayout.LEFT));
463: supprActionPanel.add(supprActionCheck);
464: supprActionPanel.add(supprActionLabel);
465:
466: conflitLabel = new JLabel(Language.getInstance().getText(
467: "En_cas_de_conflit_:_"));
468: neRienFaire = new JRadioButton();
469: neRienFaireLabel = new JLabel(Language.getInstance().getText(
470: "Conserver_l'original_et_ne_rien_faire_de_plus"));
471: creerCopie = new JRadioButton();
472: creerCopie.setSelected(true);
473: creerCopieLabel = new JLabel(
474: Language
475: .getInstance()
476: .getText(
477: "Conserver_l'original_et_faire_une_copie_des_nouvelles_données_en_préfixant_par_\"copy_\""));
478: miseAJour = new JRadioButton();
479: miseAJourLabel = new JLabel(
480: Language
481: .getInstance()
482: .getText(
483: "<html>Mettre_à_jour_les_éléments_possibles_(description_et_attachements_des_tests,_<br>_script_des_tests_automatiques,_attachements_des_actions,_...)</html>"));
484: ButtonGroup buttonGroup = new ButtonGroup();
485: buttonGroup.add(neRienFaire);
486: buttonGroup.add(creerCopie);
487: buttonGroup.add(miseAJour);
488:
489: JPanel conflitPanel = new JPanel(
490: new FlowLayout(FlowLayout.LEFT));
491: conflitPanel.add(conflitLabel);
492:
493: JPanel neRienFairePanel = new JPanel(new FlowLayout(
494: FlowLayout.LEFT));
495: neRienFairePanel.add(neRienFaire);
496: neRienFairePanel.add(neRienFaireLabel);
497:
498: JPanel creerCopiePanel = new JPanel(new FlowLayout(
499: FlowLayout.LEFT));
500: creerCopiePanel.add(creerCopie);
501: creerCopiePanel.add(creerCopieLabel);
502:
503: JPanel miseAJourPanel = new JPanel(new FlowLayout(
504: FlowLayout.LEFT));
505: miseAJourPanel.add(miseAJour);
506: miseAJourPanel.add(miseAJourLabel);
507:
508: JPanel options = new JPanel();
509: options.setLayout(new BoxLayout(options, BoxLayout.Y_AXIS));
510: options.add(supprPanel);
511: options.add(supprActionPanel);
512: options.add(conflitPanel);
513: options.add(creerCopiePanel);
514: options.add(miseAJourPanel);
515: options.add(neRienFairePanel);
516:
517: JTabbedPane onglets = new JTabbedPane();
518: onglets.addTab(Language.getInstance().getText("Principal"),
519: page);
520: onglets.addTab(Language.getInstance().getText("Options"),
521: options);
522:
523: Container contentPaneFrame = this .getContentPane();
524: contentPaneFrame.add(onglets, BorderLayout.CENTER);
525:
526: this .setLocation(400, 100);
527: this .setTitle(Language.getInstance().getText(
528: "Import_à_partir_d'un_fichier_XML"));
529: this .pack();
530: this .setVisible(true);
531: }
532:
533: /**
534: * Méthode qui parse le document XML dont le chemin est indiqué dans "path"
535: * @param path
536: * @return un document DOM4J
537: * @throws Exception
538: */
539: public Document xmlParser(String path) throws Exception {
540: SAXReader reader = new SAXReader(false);
541: Document doc = reader.read(new FileInputStream(new File(path)));
542: return doc;
543: }
544:
545: /**
546: * Méthode qui affiche les messages d'erreur
547: * @return
548: */
549: public void showErrorMessage() {
550: JOptionPane.showMessageDialog(ImportDialog.this , errorMessage,
551: Language.getInstance().getText("Erreur_!"),
552: JOptionPane.ERROR_MESSAGE);
553: ImportDialog.this .dispose();
554: }
555:
556: /**
557: * @return Returns the initSelection.
558: */
559: public boolean isInitSelection() {
560: return initSelection;
561: }
562:
563: /**
564: * @param initSelection The initSelection to set.
565: */
566: public void setInitSelection(boolean initSelection) {
567: this .initSelection = initSelection;
568: }
569:
570: /**
571: * @return Returns the suiteList.
572: */
573: public ArrayList getSuiteSelectionList() {
574: return suiteSelectionList;
575: }
576:
577: /**
578: * @param suiteList The suiteList to set.
579: */
580: public void setSuiteSelectionList(ArrayList suiteSelectionList) {
581: this .suiteSelectionList = suiteSelectionList;
582: }
583:
584: /**
585: * @return Returns the familyList.
586: */
587: public ArrayList getFamilySelectionList() {
588: return familySelectionList;
589: }
590:
591: /**
592: * @param familyList The familyList to set.
593: */
594: public void setFamilySelectionList(ArrayList familySelectionList) {
595: this .familySelectionList = familySelectionList;
596: }
597:
598: /**
599: * @return Returns the testList.
600: */
601: public ArrayList getTestSelectionList() {
602: return testSelectionList;
603: }
604:
605: /**
606: * @param testList The testList to set.
607: */
608: public void setTestSelectionList(ArrayList testSelectionList) {
609: this .testSelectionList = testSelectionList;
610: }
611:
612: /**
613: * @return Returns the chosenRoot.
614: */
615: public DefaultMutableTreeNode getChosenRoot() {
616: return chosenRoot;
617: }
618:
619: /**
620: * @param chosenRoot The chosenRoot to set.
621: */
622: public void setChosenRoot(DefaultMutableTreeNode chosenRoot) {
623: this .chosenRoot = chosenRoot;
624: }
625:
626: /**
627: * @return Returns the selectionDesTests.
628: */
629: public boolean isSelectionDesTests() {
630: return selectionDesTests;
631: }
632:
633: /**
634: * @param selectionDesTests The selectionDesTests to set.
635: */
636: public void setSelectionDesTests(boolean selectionDesTests) {
637: this .selectionDesTests = selectionDesTests;
638: }
639:
640: /**
641: * @return Returns the recupAttachPb.
642: */
643: public boolean isRecupAttachPb() {
644: return recupAttachPb;
645: }
646:
647: /**
648: * @param recupAttachPb The recupAttachPb to set.
649: */
650: public void setRecupAttachPb(boolean recupAttachPb) {
651: this .recupAttachPb = recupAttachPb;
652: }
653:
654: /**
655: * @return Returns the supprAction.
656: */
657: public boolean isSupprAction() {
658: return supprAction;
659: }
660:
661: /**
662: * @param supprAction The supprAction to set.
663: */
664: public void setSupprAction(boolean supprAction) {
665: this .supprAction = supprAction;
666: }
667:
668: /**
669: * @return Returns the conflit.
670: */
671: public boolean isConflit() {
672: return conflit;
673: }
674:
675: /**
676: * @param conflit The conflit to set.
677: */
678: public void setConflit(boolean conflit) {
679: this .conflit = conflit;
680: }
681:
682: /**
683: * @return Returns the existeModif.
684: */
685: public boolean isExisteModif() {
686: return existeModif;
687: }
688:
689: /**
690: * @param existeModif The existeModif to set.
691: */
692: public void setExisteModif(boolean existeModif) {
693: this .existeModif = existeModif;
694: }
695:
696: /**
697: * @return Returns the creer_copy.
698: */
699: public boolean isCreer_copy() {
700: return creer_copy;
701: }
702:
703: /**
704: * @param creer_copy The creer_copy to set.
705: */
706: public void setCreer_copy(boolean creer_copy) {
707: this .creer_copy = creer_copy;
708: }
709:
710: /**
711: * @return Returns the majPossible.
712: */
713: public boolean isMajPossible() {
714: return majPossible;
715: }
716:
717: /**
718: * @param majPossible The majPossible to set.
719: */
720: /*public void setMajPossible(boolean majPossible) {
721: this.majPossible = majPossible;
722: }*/
723: /**
724: * @return Returns the majAttachPb.
725: */
726: public boolean isMajAttachPb() {
727: return majAttachPb;
728: }
729:
730: /**
731: * @param majAttachPb The majAttachPb to set.
732: */
733: public void setMajAttachPb(boolean majAttachPb) {
734: this .majAttachPb = majAttachPb;
735: }
736:
737: /**
738: * @return Returns the supprElement.
739: */
740: public boolean isSupprElement() {
741: return supprElement;
742: }
743:
744: /**
745: * @param supprElement The supprElement to set.
746: */
747: public void setSupprElement(boolean supprElement) {
748: this .supprElement = supprElement;
749: }
750:
751: /**
752: * @return Returns the errorMessage.
753: */
754: public String getErrorMessage() {
755: return errorMessage;
756: }
757:
758: /**
759: * @param errorMessage The errorMessage to set.
760: */
761: public void setErrorMessage(String errorMessage) {
762: this.errorMessage = errorMessage;
763: }
764: }
|