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