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