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.common;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Container;
028: import java.awt.Dimension;
029: import java.awt.Rectangle;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032: import java.util.ArrayList;
033: import java.util.Iterator;
034: import java.util.List;
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.JDialog;
041: import javax.swing.JOptionPane;
042: import javax.swing.JPanel;
043: import javax.swing.JScrollPane;
044: import javax.swing.JTree;
045: import javax.swing.event.TreeSelectionEvent;
046: import javax.swing.event.TreeSelectionListener;
047: import javax.swing.tree.DefaultMutableTreeNode;
048: import javax.swing.tree.DefaultTreeModel;
049: import javax.swing.tree.TreePath;
050:
051: import org.dom4j.Document;
052: import org.dom4j.Element;
053: import org.dom4j.Node;
054: import org.objectweb.salome_tmf.api.data.AutomaticTestWrapper;
055: import org.objectweb.salome_tmf.api.data.FamilyWrapper;
056: import org.objectweb.salome_tmf.api.data.ManualTestWrapper;
057: import org.objectweb.salome_tmf.api.data.SuiteWrapper;
058: import org.objectweb.salome_tmf.data.AutomaticTest;
059: import org.objectweb.salome_tmf.data.Campaign;
060: import org.objectweb.salome_tmf.data.DataConstants;
061: import org.objectweb.salome_tmf.data.Execution;
062: import org.objectweb.salome_tmf.data.Family;
063: import org.objectweb.salome_tmf.data.ManualTest;
064: import org.objectweb.salome_tmf.data.Test;
065: import org.objectweb.salome_tmf.data.TestList;
066: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
067: import org.objectweb.salome_tmf.ihm.models.TestTreeModel;
068: import org.objectweb.salome_tmf.ihm.models.TreeRenderer;
069: import org.objectweb.salome_tmf.ihm.tools.Tools;
070:
071: import salomeTMF_plug.docXML.importxml.ImportDialog;
072: import salomeTMF_plug.docXML.importxml.ImportDialog2;
073: import salomeTMF_plug.docXML.languages.Language;
074:
075: public class ImportTestChooser2 extends JDialog implements
076: DataConstants {
077:
078: /**
079: * Modèle de l'arbre des tests
080: */
081: protected TestTreeModel testTreeModel;
082:
083: /**
084: * Modèle de l'arbre des tests sélectionnés
085: */
086: protected TestTreeModel chosenTreeModel;
087:
088: /**
089: * l'arbre des tests choisis
090: */
091: JTree chosenTree;
092:
093: /**
094: * l'arbre des tests
095: */
096: JTree testTree;
097:
098: /**
099: * Noeud sélectionné dans l'arbre des tests choisis
100: */
101: DefaultMutableTreeNode chosenSelectedNode;
102:
103: /**
104: * Noeud sélectionné dans l'arbre des tests
105: */
106: DefaultMutableTreeNode testSelectedNode;
107:
108: /**
109: * Racine de l'arbre temporaire des tests choisis
110: */
111: DefaultMutableTreeNode temporaryChosenRootNode;
112:
113: /**
114: * Racine de l'arbre final des tests choisis
115: */
116: DefaultMutableTreeNode realChosenRoot;
117:
118: /**
119: * Liste des tests sélectionnés
120: */
121: ArrayList<Test> temporaryTestList;
122:
123: /**
124: * Liste des suites sélectionnées
125: */
126: ArrayList<TestList> temporaryTestListList;
127:
128: /**
129: * Liste des familles sélectionnées
130: */
131: ArrayList<Family> temporaryFamilyList;
132:
133: ArrayList<Object> testSelectedNodes;
134:
135: ArrayList<Object> chosenSelectedNodes;
136:
137: ImportDialog idialog;
138: ImportDialog2 idialog2;
139: CreateProjectDialog cdialog;
140:
141: private String errorMessage = "";
142:
143: public ImportTestChooser2(JDialog i, Document doc,
144: boolean initSelection) throws Exception {
145: super (i, true);
146:
147: if (i instanceof ImportDialog) {
148: idialog = (ImportDialog) i;
149: } else if (i instanceof CreateProjectDialog) {
150: cdialog = (CreateProjectDialog) i;
151: } else if (i instanceof ImportDialog2) {
152: idialog2 = (ImportDialog2) i;
153: }
154: temporaryTestList = new ArrayList<Test>();
155: temporaryTestListList = new ArrayList<TestList>();
156: temporaryFamilyList = new ArrayList<Family>();
157:
158: chosenSelectedNodes = new ArrayList<Object>();
159: testSelectedNodes = new ArrayList<Object>();
160:
161: DynamicTree testDynamicTree = createTestDynamicTree(doc);
162:
163: realChosenRoot = testDynamicTree.getRoot();
164:
165: TreeRenderer chosenRenderer = new TreeRenderer();
166: TreeRenderer testRenderer = new TreeRenderer();
167:
168: if (initSelection) {
169: if (idialog != null) {
170: temporaryChosenRootNode = new DefaultMutableTreeNode(
171: idialog.getChosenRoot().getUserObject());
172: } else if (cdialog != null) {
173: temporaryChosenRootNode = new DefaultMutableTreeNode(
174: cdialog.getChosenRoot().getUserObject());
175: } else if (idialog2 != null) {
176: temporaryChosenRootNode = new DefaultMutableTreeNode(
177: idialog2.getChosenRoot().getUserObject());
178: }
179: } else {
180: temporaryChosenRootNode = new DefaultMutableTreeNode(
181: testDynamicTree.getRoot().getUserObject());
182: }
183:
184: chosenSelectedNode = temporaryChosenRootNode;
185:
186: chosenTree = new JTree();
187: chosenTreeModel = new TestTreeModel(temporaryChosenRootNode,
188: chosenTree, null);
189: chosenTree.setModel(chosenTreeModel);
190:
191: if (initSelection) {
192: if (idialog != null) {
193: initTemporaryTree(idialog.getChosenRoot());
194: } else if (cdialog != null) {
195: initTemporaryTree(cdialog.getChosenRoot());
196: } else if (idialog2 != null) {
197: initTemporaryTree(idialog2.getChosenRoot());
198: }
199: } else {
200: initTemporaryTree(testDynamicTree.getRoot());
201: }
202:
203: chosenTree.setCellRenderer(chosenRenderer);
204: chosenTree
205: .addTreeSelectionListener(new TreeSelectionListener() {
206: public void valueChanged(TreeSelectionEvent e) {
207: try {
208: chosenSelectedNodes.clear();
209: TreePath[] pathTab = chosenTree
210: .getSelectionPaths();
211: if (pathTab != null) {
212: for (int i = 0; i < pathTab.length; i++) {
213: chosenSelectedNodes.add(pathTab[i]
214: .getLastPathComponent());
215: }
216: }
217: } catch (Exception ex) {
218: Tools.ihmExceptionView(ex);
219: }
220: }
221: });
222: testTree = new JTree(testTreeModel);
223: testTreeModel = new TestTreeModel(testDynamicTree.getRoot(),
224: testTree, null);
225: testTree.setModel(testTreeModel);
226:
227: testTree.setCellRenderer(testRenderer);
228: testTree.addTreeSelectionListener(new TreeSelectionListener() {
229: public void valueChanged(TreeSelectionEvent e) {
230: try {
231: testSelectedNodes.clear();
232: TreePath[] pathTab = testTree.getSelectionPaths();
233: if (pathTab != null) {
234: for (int i = 0; i < pathTab.length; i++) {
235: testSelectedNodes.add(pathTab[i]
236: .getLastPathComponent());
237: }
238: }
239: } catch (Exception ex) {
240: Tools.ihmExceptionView(ex);
241: }
242: }
243: });
244:
245: JButton addButton = new JButton(">");
246: addButton.setToolTipText(Language.getInstance().getText(
247: "Ajouter_à_la_sélection"));
248: addButton.addActionListener(new ActionListener() {
249: public void actionPerformed(ActionEvent e) {
250: try {
251: for (int i = 0; i < testSelectedNodes.size(); i++) {
252: Object nodeValue = ((DefaultMutableTreeNode) testSelectedNodes
253: .get(i)).getUserObject();
254: testSelectedNode = ((DefaultMutableTreeNode) testSelectedNodes
255: .get(i));
256: if (nodeValue instanceof Family) {
257: addNodeToNode(testSelectedNode,
258: temporaryChosenRootNode);
259: } else if (nodeValue instanceof TestList) {
260: DefaultMutableTreeNode familyNode = findFamilyNodeInChosenTree(((TestList) nodeValue)
261: .getFamilyFromModel()
262: .getNameFromModel());
263: if (familyNode != null) {
264: addNodeToNode(testSelectedNode,
265: familyNode);
266: } else {
267: DefaultMutableTreeNode newFamilyNode = addObject(
268: temporaryChosenRootNode,
269: ((TestList) nodeValue)
270: .getFamilyFromModel(),
271: true);
272: addNodeToNode(testSelectedNode,
273: newFamilyNode);
274: }
275: } else if (nodeValue instanceof Test) {
276: DefaultMutableTreeNode testListNode = findTestListNodeInChosenTree(
277: ((Test) nodeValue)
278: .getTestListFromModel()
279: .getNameFromModel(),
280: ((Test) nodeValue)
281: .getTestListFromModel()
282: .getFamilyFromModel()
283: .getNameFromModel());
284: if (testListNode != null) {
285: addNodeToNode(testSelectedNode,
286: testListNode);
287: } else {
288: DefaultMutableTreeNode familyNode = findFamilyNodeInChosenTree(((Test) nodeValue)
289: .getTestListFromModel()
290: .getFamilyFromModel()
291: .getNameFromModel());
292: if (familyNode != null) {
293: DefaultMutableTreeNode newListNode = addObject(
294: familyNode,
295: ((Test) nodeValue)
296: .getTestListFromModel(),
297: true);
298: addNodeToNode(testSelectedNode,
299: newListNode);
300: } else {
301: DefaultMutableTreeNode newFamilyNode = addObject(
302: temporaryChosenRootNode,
303: ((Test) nodeValue)
304: .getTestListFromModel()
305: .getFamilyFromModel(),
306: true);
307: DefaultMutableTreeNode newList = addObject(
308: newFamilyNode,
309: ((Test) nodeValue)
310: .getTestListFromModel(),
311: true);
312: addNodeToNode(testSelectedNode,
313: newList);
314: }
315: }
316: }
317: }
318: } catch (Exception ex) {
319: ex.printStackTrace();
320: errorMessage += Language.getInstance().getText(
321: "Probleme_lors_de_la_selection_des_tests");
322: showErrorMessage();
323: }
324: }
325: });
326:
327: JButton removeButton = new JButton("<");
328: removeButton.setToolTipText(Language.getInstance().getText(
329: "Retirer_de_la_sélection"));
330: removeButton.addActionListener(new ActionListener() {
331: public void actionPerformed(ActionEvent e) {
332: try {
333: int i = chosenSelectedNodes.size() - 1;
334: boolean continu = true;
335: while (i >= 0 && continu) {
336: Object nodeValue = ((DefaultMutableTreeNode) chosenSelectedNodes
337: .get(i)).getUserObject();
338: DefaultMutableTreeNode node = (DefaultMutableTreeNode) chosenSelectedNodes
339: .get(i);
340: if (nodeValue instanceof Campaign
341: || nodeValue instanceof Execution
342: || nodeValue instanceof Family
343: || nodeValue instanceof TestList
344: || nodeValue instanceof Test) {
345: ((DefaultTreeModel) chosenTree.getModel())
346: .removeNodeFromParent(node);
347: removeFromModel(node);
348: i = chosenSelectedNodes.size() - 1;
349: } else {
350: continu = false;
351: }
352: }
353: } catch (Exception ex) {
354: ex.printStackTrace();
355: errorMessage += Language.getInstance().getText(
356: "Probleme_lors_de_la_selection_des_tests");
357: showErrorMessage();
358: }
359: }
360: });
361:
362: JPanel buttonSet = new JPanel();
363: buttonSet.setLayout(new BoxLayout(buttonSet, BoxLayout.Y_AXIS));
364: buttonSet.add(addButton);
365: buttonSet.add(Box.createRigidArea(new Dimension(1, 25)));
366: buttonSet.add(removeButton);
367:
368: JScrollPane chosenScrollPane = new JScrollPane(chosenTree);
369: chosenScrollPane.setBorder(BorderFactory
370: .createTitledBorder(Language.getInstance().getText(
371: "Sélection")));
372: chosenScrollPane.setPreferredSize(new Dimension(300, 450));
373:
374: JScrollPane testScrollPane = new JScrollPane(testTree);
375: testScrollPane.setBorder(BorderFactory
376: .createTitledBorder(Language.getInstance().getText(
377: "Tests")));
378: testScrollPane.setPreferredSize(new Dimension(300, 450));
379:
380: JPanel windowPanel = new JPanel();
381: windowPanel.setLayout(new BoxLayout(windowPanel,
382: BoxLayout.X_AXIS));
383: windowPanel.add(testScrollPane);
384: windowPanel.add(Box.createRigidArea(new Dimension(20, 50)));
385: windowPanel.add(buttonSet);
386: windowPanel.add(Box.createRigidArea(new Dimension(20, 50)));
387: windowPanel.add(chosenScrollPane);
388:
389: JButton validate = new JButton(Language.getInstance().getText(
390: "Valider"));
391: validate.setToolTipText(Language.getInstance().getText(
392: "Valider"));
393: validate.addActionListener(new ActionListener() {
394: public void actionPerformed(ActionEvent e) {
395: try {
396: updateList();
397: if (temporaryTestList.size() == 0) {
398: JOptionPane
399: .showMessageDialog(
400: ImportTestChooser2.this ,
401: Language
402: .getInstance()
403: .getText(
404: "Vous_devez_sélectionner_au_moins_un_test_à_importer"),
405: Language.getInstance().getText(
406: "Erreur_!"),
407: JOptionPane.ERROR_MESSAGE);
408: } else {
409: if (idialog != null) {
410: ImportTestChooser2.this .idialog
411: .setInitSelection(true);
412: if (temporaryFamilyList != null) {
413: idialog
414: .setFamilySelectionList(temporaryFamilyList);
415: }
416: if (temporaryTestListList != null) {
417: idialog
418: .setSuiteSelectionList(temporaryTestListList);
419: }
420: if (temporaryTestList != null) {
421: idialog
422: .setTestSelectionList(temporaryTestList);
423: }
424: idialog
425: .setChosenRoot((DefaultMutableTreeNode) chosenTreeModel
426: .getRoot());
427: idialog.setSelectionDesTests(true);
428: } else if (cdialog != null) {
429: ImportTestChooser2.this .cdialog
430: .setInitSelection(true);
431: if (temporaryFamilyList != null) {
432: cdialog
433: .setFamilySelectionList(temporaryFamilyList);
434: }
435: if (temporaryTestListList != null) {
436: cdialog
437: .setSuiteSelectionList(temporaryTestListList);
438: }
439: if (temporaryTestList != null) {
440: cdialog
441: .setTestSelectionList(temporaryTestList);
442: }
443: cdialog
444: .setChosenRoot((DefaultMutableTreeNode) chosenTreeModel
445: .getRoot());
446: cdialog.setSelectionDesTests(true);
447: } else if (idialog2 != null) {
448: ImportTestChooser2.this .idialog2
449: .setInitSelection(true);
450: if (temporaryFamilyList != null) {
451: idialog2
452: .setFamilySelectionList(temporaryFamilyList);
453: }
454: if (temporaryTestListList != null) {
455: idialog2
456: .setSuiteSelectionList(temporaryTestListList);
457: }
458: if (temporaryTestList != null) {
459: idialog2
460: .setTestSelectionList(temporaryTestList);
461: }
462: idialog2
463: .setChosenRoot((DefaultMutableTreeNode) chosenTreeModel
464: .getRoot());
465: idialog2.setSelectionDesTests(true);
466: }
467: ImportTestChooser2.this .dispose();
468: }
469: } catch (Exception ex) {
470: ex.printStackTrace();
471: errorMessage += Language.getInstance().getText(
472: "Probleme_lors_de_la_selection_des_tests");
473: showErrorMessage();
474: }
475: }
476: });
477:
478: JButton cancel = new JButton(Language.getInstance().getText(
479: "Annuler"));
480: cancel
481: .setToolTipText(Language.getInstance().getText(
482: "Annuler"));
483: cancel.addActionListener(new ActionListener() {
484: public void actionPerformed(ActionEvent e) {
485: try {
486: ImportTestChooser2.this .dispose();
487: } catch (Exception ex) {
488: Tools.ihmExceptionView(ex);
489: }
490: }
491: });
492:
493: JPanel secondButtonSet = new JPanel();
494: secondButtonSet.add(validate);
495: secondButtonSet.add(cancel);
496:
497: JPanel center = new JPanel();
498: center.add(windowPanel);
499:
500: JPanel page = new JPanel();
501: page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
502: page.add(center);
503: page.add(secondButtonSet);
504:
505: Container contentPaneFrame = this .getContentPane();
506: contentPaneFrame.add(page, BorderLayout.CENTER);
507: this .setTitle(Language.getInstance().getText(
508: "Ajouter_des_tests_à_la_sélection"));
509: //this.setLocation(300,200);
510: centerScreen();
511: }
512:
513: void centerScreen() {
514: Dimension dim = getToolkit().getScreenSize();
515: this .pack();
516: Rectangle abounds = getBounds();
517: setLocation((dim.width - abounds.width) / 2,
518: (dim.height - abounds.height) / 2);
519: this .setVisible(true);
520: requestFocus();
521: }
522:
523: /**
524: * @param doc
525: * @return
526: */
527: private DynamicTree createTestDynamicTree(Document doc)
528: throws Exception {
529: DynamicTree testDynamicTree = new DynamicTree(Language
530: .getInstance().getText("Plan_de_tests"), FAMILY);
531: DefaultMutableTreeNode rootNode = testDynamicTree.getRoot();
532: List<Node> familyList = doc.selectNodes("//Famille");
533: Iterator<Node> itFamille = familyList.iterator();
534: while (itFamille.hasNext()) {
535: Element familyElem = (Element) itFamille.next();
536: String familyName = familyElem.elementText("Nom");
537: FamilyWrapper f = new FamilyWrapper();
538: f.setName(familyName);
539: Family family = new Family(f);
540: DefaultMutableTreeNode familyNode = testDynamicTree
541: .addObject(rootNode, family, false);
542: temporaryFamilyList.add(family);
543: List<Node> suiteList = familyElem
544: .selectNodes(".//SuiteTest");
545: Iterator<Node> itSuite = suiteList.iterator();
546: while (itSuite.hasNext()) {
547: Element suiteElem = (Element) itSuite.next();
548: String suiteName = suiteElem.elementText("Nom");
549: SuiteWrapper s = new SuiteWrapper();
550: s.setName(suiteName);
551: TestList sList = new TestList(s);
552: DefaultMutableTreeNode suiteNode = testDynamicTree
553: .addObject(familyNode, sList, false);
554: temporaryTestListList.add(sList);
555: family.addTestListInModel(sList);
556: //sList.setFamily(family);
557: List<Node> testList = suiteElem.selectNodes(".//Test");
558: Iterator<Node> itTest = testList.iterator();
559: while (itTest.hasNext()) {
560: Element testElem = (Element) itTest.next();
561: String testName = testElem.elementText("Nom");
562: if (testElem.element("TestAuto") == null) {
563: ManualTestWrapper t = new ManualTestWrapper();
564: t.setName(testName);
565: ManualTest mTest = new ManualTest(t);
566: testDynamicTree.addObject(suiteNode, mTest,
567: false);
568: temporaryTestList.add(mTest);
569: sList.addTestInModel(mTest);
570: //mTest.setTestList(sList);
571: } else {
572: AutomaticTestWrapper a = new AutomaticTestWrapper();
573: a.setName(testName);
574: AutomaticTest aTest = new AutomaticTest(a);
575: testDynamicTree.addObject(suiteNode, aTest);
576: temporaryTestList.add(aTest);
577: sList.addTestInModel(aTest);
578: //aTest.setTestList(sList);
579: }
580: }
581: }
582: }
583: return testDynamicTree;
584: }
585:
586: /**
587: * Méthode qui initialise l'arbre temporaire à partir de la racine passé
588: * en paramètre.
589: * @param root la racine du nouvel arbre temporaire
590: */
591: public void initTemporaryTree(DefaultMutableTreeNode root)
592: throws Exception {
593: for (int i = 0; i < root.getChildCount(); i++) {
594: addNodeToNode((DefaultMutableTreeNode) root.getChildAt(i),
595: temporaryChosenRootNode);
596: }
597: } // Fin de la méthode initTemporaryTree/1
598:
599: /**
600: * Méthode Récursive qui ajoute un noeud à un autre noeud. Tous les fils du
601: * noeud à ajouter sont aussi ajouter récursivement.
602: * @param nodeToBeAdded le noeud à ajouter
603: * @param nodeToReceive le noeud qui reçoit
604: */
605: private void addNodeToNode(DefaultMutableTreeNode nodeToBeAdded,
606: DefaultMutableTreeNode nodeToReceive) throws Exception {
607: DefaultMutableTreeNode newNode = null;
608: for (int j = 0; j < nodeToReceive.getChildCount(); j++) {
609: if (((DefaultMutableTreeNode) nodeToReceive.getChildAt(j))
610: .getUserObject().equals(
611: nodeToBeAdded.getUserObject())) {
612: newNode = (DefaultMutableTreeNode) nodeToReceive
613: .getChildAt(j);
614: }
615: }
616: if (newNode == null) {
617: newNode = new DefaultMutableTreeNode(nodeToBeAdded
618: .getUserObject());
619: chosenTreeModel.insertNodeInto(newNode, nodeToReceive,
620: nodeToReceive.getChildCount());
621: chosenTree.scrollPathToVisible(new TreePath(newNode
622: .getPath()));
623: if (nodeToBeAdded.getUserObject() instanceof Family) {
624: temporaryFamilyList.add((Family) nodeToBeAdded
625: .getUserObject());
626: } else if (nodeToBeAdded.getUserObject() instanceof TestList) {
627: temporaryTestListList.add((TestList) nodeToBeAdded
628: .getUserObject());
629: } else if (nodeToBeAdded.getUserObject() instanceof Test) {
630: temporaryTestList.add((Test) nodeToBeAdded
631: .getUserObject());
632: }
633: }
634: for (int i = 0; i < nodeToBeAdded.getChildCount(); i++) {
635: addNodeToNode((DefaultMutableTreeNode) nodeToBeAdded
636: .getChildAt(i), newNode);
637: }
638: } // Fin de la méthode addNodeToNode/2
639:
640: /**
641: * Méthode qui retourne le noeud correspondant à une famille si le nom passé
642: * en paramètre est le nom d'une famille présente dans l'arbre des sélections
643: * @param familyName un nom
644: * @return le noeud correspondant à une famille si le nom passé
645: * en paramètre est le nom d'une famille présente dans l'arbre des sélections,
646: * <code>null</code> sinon.
647: */
648: public DefaultMutableTreeNode findFamilyNodeInChosenTree(
649: String familyName) throws Exception {
650: DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
651: .getRoot();
652: for (int j = 0; j < root.getChildCount(); j++) {
653: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
654: .getChildAt(j);
655: if (familyNode.getUserObject() instanceof Family
656: && ((Family) familyNode.getUserObject())
657: .getNameFromModel().equals(familyName)) {
658: return familyNode;
659: }
660: }
661: return null;
662: } // Fin de la méthode findFamilyNode/1
663:
664: /**
665: * Méthode qui retourne le noeud correspondant à une suite si le nom passé
666: * en paramètre est le nom d'une suite présente dans l'arbre des sélections
667: * @param testListName un nom
668: * @return le noeud correspondant à une famille si le nom passé
669: * en paramètre est le nom d'une famille présente dans l'arbre des sélections,
670: * <code>null</code> sinon.
671: */
672: public DefaultMutableTreeNode findTestListNodeInChosenTree(
673: String testListName, String familyName) throws Exception {
674: DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
675: .getRoot();
676: for (int j = 0; j < root.getChildCount(); j++) {
677: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
678: .getChildAt(j);
679: if (familyNode.getUserObject() instanceof Family
680: && ((Family) familyNode.getUserObject())
681: .getNameFromModel().equals(familyName)) {
682: for (int k = 0; k < familyNode.getChildCount(); k++) {
683: DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
684: .getChildAt(k);
685: if (testListNode.getUserObject() instanceof TestList
686: && ((TestList) testListNode.getUserObject())
687: .getNameFromModel().equals(
688: testListName)) {
689: return testListNode;
690: }
691: }
692: }
693: }
694: return null;
695: } // Fin de la méthode findFamilyNode/1
696:
697: /**
698: * Méthode d'ajout d'un noeud dans l'arbre sous le parent.
699: * @param parent le parent
700: * @param child le noeud à ajouter
701: * @param shouldBeVisible visible ou non
702: * @return le nouveau noeud de l'arbre
703: */
704: public DefaultMutableTreeNode addObject(
705: DefaultMutableTreeNode parent, Object child,
706: boolean shouldBeVisible) throws Exception {
707:
708: DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
709: child);
710: if (parent == null) {
711: parent = temporaryChosenRootNode;
712: }
713: // Insertion du noeud
714: chosenTreeModel.insertNodeInto(childNode, parent, parent
715: .getChildCount());
716:
717: // on s'assure que le noeud est visible
718: if (shouldBeVisible) {
719: chosenTree.scrollPathToVisible(new TreePath(childNode
720: .getPath()));
721: }
722: return childNode;
723: } // Fin de la classe addObject/3
724:
725: /**
726: * Supprime du modèle les éléments retirés de la sélection.
727: * @param node le noeud à partir duquel on retire les éléments
728: */
729: private void removeFromModel(DefaultMutableTreeNode node)
730: throws Exception {
731: for (int i = 0; i < node.getChildCount(); i++) {
732: removeFromModel((DefaultMutableTreeNode) node.getChildAt(i));
733: }
734: if (node.getUserObject() instanceof Family) {
735: temporaryFamilyList.remove(node.getUserObject());
736: } else if (node.getUserObject() instanceof TestList) {
737: temporaryTestListList.remove(node.getUserObject());
738: } else if (node.getUserObject() instanceof Test) {
739: temporaryTestList.remove(node.getUserObject());
740: }
741: } // Fin de la méthode removeFromModel/1
742:
743: public void updateList() throws Exception {
744: temporaryTestList = new ArrayList<Test>();
745: temporaryTestListList = new ArrayList<TestList>();
746: temporaryFamilyList = new ArrayList<Family>();
747: DefaultMutableTreeNode root = (DefaultMutableTreeNode) chosenTreeModel
748: .getRoot();
749: for (int j = 0; j < root.getChildCount(); j++) {
750: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
751: .getChildAt(j);
752: if (familyNode.getUserObject() instanceof Family) {
753: temporaryFamilyList.add((Family) familyNode
754: .getUserObject());
755: for (int k = 0; k < familyNode.getChildCount(); k++) {
756: DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
757: .getChildAt(k);
758: if (testListNode.getUserObject() instanceof TestList) {
759: temporaryTestListList
760: .add((TestList) testListNode
761: .getUserObject());
762: for (int l = 0; l < testListNode
763: .getChildCount(); l++) {
764: DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) testListNode
765: .getChildAt(l);
766: if (testNode.getUserObject() instanceof Test) {
767: temporaryTestList.add((Test) testNode
768: .getUserObject());
769: }
770: }
771: }
772: }
773: }
774: }
775: }
776:
777: /**
778: * Méthode qui affiche les messages d'erreur
779: * @return
780: */
781: public void showErrorMessage() {
782: JOptionPane
783: .showMessageDialog(ImportTestChooser2.this ,
784: errorMessage, Language.getInstance().getText(
785: "Erreur_!"), JOptionPane.ERROR_MESSAGE);
786: ImportTestChooser2.this.dispose();
787: }
788: }
|