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