0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Mikael MARCHE, Fayçal SOUGRATI, Vincent PAUTRET
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.ihm.models;
0025:
0026: import java.awt.Cursor;
0027: import java.awt.GridLayout;
0028: import java.awt.Toolkit;
0029: import java.util.Vector;
0030:
0031: import javax.swing.JPanel;
0032: import javax.swing.JPopupMenu;
0033: import javax.swing.JScrollPane;
0034: import javax.swing.JTree;
0035: import javax.swing.ScrollPaneConstants;
0036: import javax.swing.event.TreeSelectionEvent;
0037: import javax.swing.event.TreeSelectionListener;
0038: import javax.swing.tree.DefaultMutableTreeNode;
0039: import javax.swing.tree.MutableTreeNode;
0040: import javax.swing.tree.TreePath;
0041: import javax.swing.tree.TreeSelectionModel;
0042:
0043: import org.objectweb.salome_tmf.api.ApiConstants;
0044: import org.objectweb.salome_tmf.api.Permission;
0045: import org.objectweb.salome_tmf.data.Campaign;
0046: import org.objectweb.salome_tmf.data.DataConstants;
0047: import org.objectweb.salome_tmf.data.Family;
0048: import org.objectweb.salome_tmf.data.ManualTest;
0049: import org.objectweb.salome_tmf.data.SimpleData;
0050: import org.objectweb.salome_tmf.data.Test;
0051: import org.objectweb.salome_tmf.data.TestList;
0052: import org.objectweb.salome_tmf.ihm.main.PopupMenuFactory;
0053: import org.objectweb.salome_tmf.ihm.main.SalomeTMFPanels;
0054: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
0055:
0056: /**
0057: * @author teaml039
0058: */
0059: /**
0060: * Classe repr?sentant un arbre modfiable dynamiquement
0061: * @author teaml039
0062: * @version 0.1
0063: */
0064: public class DynamicTree extends JPanel implements ApiConstants,
0065: DataConstants {
0066:
0067: /**
0068: * La racine de l'arbre
0069: */
0070: protected DefaultMutableTreeNode rootNode;
0071:
0072: /**
0073: * Mod?le de l'arbre
0074: */
0075: protected TestTreeModel treeModel;
0076:
0077: /**
0078: * L'arbre
0079: */
0080: protected JTree tree;
0081:
0082: /**
0083: *
0084: */
0085: //private Toolkit toolkit = Toolkit.getDefaultToolkit();
0086: /**
0087: * Le noeud selectionn?
0088: */
0089: private DefaultMutableTreeNode selectedNode;
0090:
0091: /**
0092: * Type de l'arbre "campagne" ou "suite"
0093: */
0094: private int treeType;
0095:
0096: String campaignName;
0097:
0098: String familyName;
0099:
0100: String testName;
0101:
0102: String testListName;
0103:
0104: SimpleData oldData = null;
0105:
0106: /**************************************************************************/
0107: /** CONSTRUCTEUR ***/
0108: /**************************************************************************/
0109: /**
0110: * Le constructeur de l'arbre
0111: */
0112: public DynamicTree(String rootName, int type) {
0113: super (new GridLayout(1, 0));
0114:
0115: // Le support graphique sur lequel est fond? l'arbre
0116: TreeRenderer renderer = new TreeRenderer();
0117:
0118: treeType = type;
0119:
0120: // la racine de l'arbre de test
0121: rootNode = new DefaultMutableTreeNode(rootName);
0122:
0123: tree = new JTree();
0124: treeModel = new TestTreeModel(rootNode, tree, null);
0125: tree.setModel(treeModel);
0126: //treeModel.addTreeModelListener(new MyTreeModelListener());
0127:
0128: //tree = new JTree(treeModel);
0129: //tree.setEditable(true);
0130: tree.setCellRenderer(renderer);
0131: tree.getSelectionModel().setSelectionMode(
0132: TreeSelectionModel.SINGLE_TREE_SELECTION);
0133: tree.setShowsRootHandles(true);
0134: tree.addTreeSelectionListener(new TreeSelectionListener() {
0135: public void valueChanged(TreeSelectionEvent e) {
0136: DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
0137: .getLastSelectedPathComponent();
0138: if (node == null) {
0139: selectedNode = null;
0140: return;
0141: } else {
0142: tree.setCursor(new Cursor(Cursor.WAIT_CURSOR));
0143: if (oldData != null) {
0144: oldData.clearCache();
0145: }
0146: if (getTreeType() == CAMPAIGN) {
0147: selectedNode = node;
0148: if (node.getUserObject() instanceof Test) {
0149: Test pTest = (Test) node.getUserObject();
0150: oldData = pTest;
0151: PopupMenuFactory.setRootCampAction(false);
0152: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0153: DataModel.setCurrentTest(pTest);
0154: DataModel.setCurrentTestList(pTest
0155: .getTestListFromModel());
0156: DataModel.setCurrentFamily(pTest
0157: .getTestListFromModel()
0158: .getFamilyFromModel());
0159: DataModel
0160: .setCurrentCampaign((Campaign) ((DefaultMutableTreeNode) node
0161: .getParent().getParent()
0162: .getParent())
0163: .getUserObject());
0164: if (Permission.canDeleteCamp()) {
0165: SalomeTMFPanels.getDelCampagne()
0166: .setEnabled(true);
0167: PopupMenuFactory.getDelCampMenuItem()
0168: .setEnabled(true);
0169: }
0170: SalomeTMFPanels.getAddTestInCampagne()
0171: .setEnabled(false);
0172: PopupMenuFactory.getImportToCampMenuItem()
0173: .setEnabled(false);
0174: PopupMenuFactory.getviewMenuItem()
0175: .setEnabled(true);
0176: SalomeTMFPanels.getRenameCampaignButton()
0177: .setEnabled(false);
0178: if (Permission.canUpdateCamp()) {
0179: SalomeTMFPanels.getOrderCampagne()
0180: .setEnabled(true);
0181: PopupMenuFactory
0182: .getAssignCampMenuItem()
0183: .setEnabled(true);
0184: }
0185: SalomeTMFPanels
0186: .setCampPanelWorkSpace(DataConstants.TEST);
0187:
0188: SalomeTMFPanels.setCampPanelDescription(
0189: DataConstants.TEST, pTest
0190: .getDescriptionFromModel());
0191: SalomeTMFPanels.setCampPanelDetailsForTest(
0192: pTest.getNameFromModel(), pTest
0193: .getConceptorFromModel(),
0194: pTest.getCreationDateFromModel()
0195: .toString(), DataModel
0196: .getCurrentCampaign()
0197: .getAssignedUserID(pTest));
0198: testName = pTest.getNameFromModel();
0199: } else if (node.getUserObject() instanceof Family) {
0200: Family pFamily = (Family) node
0201: .getUserObject();
0202: oldData = pFamily;
0203: PopupMenuFactory.setRootCampAction(false);
0204: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0205: DataModel.setCurrentFamily(pFamily);
0206: DataModel
0207: .setCurrentCampaign((Campaign) ((DefaultMutableTreeNode) node
0208: .getParent())
0209: .getUserObject());
0210: SalomeTMFPanels.getAddTestInCampagne()
0211: .setEnabled(false);
0212: PopupMenuFactory.getImportToCampMenuItem()
0213: .setEnabled(false);
0214: PopupMenuFactory.getviewMenuItem()
0215: .setEnabled(true);
0216: if (Permission.canDeleteCamp()) {
0217: SalomeTMFPanels.getDelCampagne()
0218: .setEnabled(true);
0219: PopupMenuFactory.getDelCampMenuItem()
0220: .setEnabled(true);
0221: }
0222: if (Permission.canUpdateCamp()) {
0223: SalomeTMFPanels.getOrderCampagne()
0224: .setEnabled(true);
0225: PopupMenuFactory
0226: .getAssignCampMenuItem()
0227: .setEnabled(true);
0228: }
0229: SalomeTMFPanels
0230: .setCampPanelWorkSpace(DataConstants.FAMILY);
0231: SalomeTMFPanels.setCampPanelDescription(
0232: DataConstants.FAMILY, pFamily
0233: .getDescriptionFromModel());
0234: SalomeTMFPanels.getRenameCampaignButton()
0235: .setEnabled(false);
0236: familyName = pFamily.getNameFromModel();
0237: } else if (node.getUserObject() instanceof TestList) {
0238: TestList pTestList = (TestList) node
0239: .getUserObject();
0240: oldData = pTestList;
0241: PopupMenuFactory.setRootCampAction(false);
0242: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0243: DataModel.setCurrentTestList(pTestList);
0244: DataModel.setCurrentFamily(pTestList
0245: .getFamilyFromModel());
0246: DataModel
0247: .setCurrentCampaign((Campaign) ((DefaultMutableTreeNode) node
0248: .getParent().getParent())
0249: .getUserObject());
0250: SalomeTMFPanels.getAddTestInCampagne()
0251: .setEnabled(false);
0252: PopupMenuFactory.getImportToCampMenuItem()
0253: .setEnabled(false);
0254: PopupMenuFactory.getviewMenuItem()
0255: .setEnabled(true);
0256: if (Permission.canDeleteCamp()) {
0257: SalomeTMFPanels.getDelCampagne()
0258: .setEnabled(true);
0259: PopupMenuFactory.getDelCampMenuItem()
0260: .setEnabled(true);
0261: }
0262: if (Permission.canUpdateCamp()) {
0263: SalomeTMFPanels.getOrderCampagne()
0264: .setEnabled(true);
0265: PopupMenuFactory
0266: .getAssignCampMenuItem()
0267: .setEnabled(true);
0268: }
0269: SalomeTMFPanels
0270: .setCampPanelWorkSpace(DataConstants.TESTLIST);
0271: SalomeTMFPanels.setCampPanelDescription(
0272: DataConstants.TESTLIST, pTestList
0273: .getDescriptionFromModel());
0274: SalomeTMFPanels.getRenameCampaignButton()
0275: .setEnabled(false);
0276: testListName = pTestList.getNameFromModel();
0277: } else if (node.getUserObject() instanceof Campaign) {
0278: Campaign pCamp = (Campaign) node
0279: .getUserObject();
0280: oldData = pCamp;
0281: PopupMenuFactory.setRootCampAction(false);
0282: if (Permission.canDeleteCamp()) {
0283: SalomeTMFPanels.getDelCampagne()
0284: .setEnabled(true);
0285: PopupMenuFactory.getDelCampMenuItem()
0286: .setEnabled(true);
0287: }
0288: PopupMenuFactory.getviewMenuItem()
0289: .setEnabled(false);
0290: if (Permission.canUpdateCamp())
0291: SalomeTMFPanels
0292: .getRenameCampaignButton()
0293: .setEnabled(true);
0294: if (Permission.canCreateCamp()) {
0295: SalomeTMFPanels.getAddTestInCampagne()
0296: .setEnabled(true);
0297: PopupMenuFactory
0298: .getImportToCampMenuItem()
0299: .setEnabled(true);
0300: }
0301: if (Permission.canUpdateCamp()) {
0302: SalomeTMFPanels.getOrderCampagne()
0303: .setEnabled(true);
0304: PopupMenuFactory
0305: .getAssignCampMenuItem()
0306: .setEnabled(true);
0307: }
0308: /* if (DataModel.isBeginDescriptionModification()) {
0309: DataModel.setCampaignChange(true);
0310: DataModel.setBeginDescriptionModification(false);
0311: }*/
0312:
0313: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0314: DataModel.setCurrentCampaign(pCamp);
0315: DataModel.initCampaign(pCamp);
0316: SalomeTMFPanels
0317: .setCampPanelWorkSpace(DataConstants.CAMPAIGN);
0318: campaignName = pCamp.getNameFromModel();
0319: } else {
0320: oldData = null;
0321: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0322: SalomeTMFPanels.getDelCampagne()
0323: .setEnabled(false);
0324: SalomeTMFPanels.getRenameCampaignButton()
0325: .setEnabled(false);
0326: SalomeTMFPanels.getOrderCampagne()
0327: .setEnabled(false);
0328: SalomeTMFPanels.getAddTestInCampagne()
0329: .setEnabled(false);
0330: PopupMenuFactory.setRootCampAction(true);
0331: /*PopupMenuFactory.getImportToCampMenuItem().setEnabled(false);
0332: PopupMenuFactory.getDelCampMenuItem().setEnabled(false);
0333: PopupMenuFactory.getAssignCampMenuItem().setEnabled(false);*/
0334: SalomeTMFPanels.setCampPanelWorkSpace(-1);
0335: }
0336: } else {
0337: selectedNode = node;
0338:
0339: if (node.getUserObject() instanceof Test) {
0340: Test pTest = (Test) node.getUserObject();
0341: oldData = pTest;
0342: if (Permission.canDeleteTest()) {
0343: SalomeTMFPanels.getDelTestOrTestList()
0344: .setEnabled(true);
0345: PopupMenuFactory.getDelTestMenuItem()
0346: .setEnabled(true);
0347: }
0348: if (Permission.canUpdateTest())
0349: SalomeTMFPanels.getRenameTestButton()
0350: .setEnabled(true);
0351: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0352: DataModel.setCurrentTest(pTest);
0353: DataModel.initTest(pTest);
0354: testName = pTest.getNameFromModel();
0355: if (pTest instanceof ManualTest) {
0356: SalomeTMFPanels
0357: .setTestPanelWorkSpace(DataConstants.MANUAL_TEST);
0358: } else {
0359: SalomeTMFPanels
0360: .setTestPanelWorkSpace(DataConstants.AUTOMATIC_TEST);
0361: }
0362: /* if (DataModel.isBeginDescriptionModification()) {
0363: DataModel.setTestChange(true);
0364: DataModel.setBeginDescriptionModification(false);
0365: }*/
0366:
0367: } else if (node.getUserObject() instanceof Family) {
0368: Family pFamily = (Family) node
0369: .getUserObject();
0370: oldData = pFamily;
0371: //if (!((Family)node.getUserObject()).getName().equals(DEFAULT_FAMILY_NAME)) {
0372: if (Permission.canUpdateTest())
0373: SalomeTMFPanels.getRenameTestButton()
0374: .setEnabled(true);
0375: if (Permission.canDeleteTest()) {
0376: SalomeTMFPanels.getDelTestOrTestList()
0377: .setEnabled(true);
0378: PopupMenuFactory.getDelTestMenuItem()
0379: .setEnabled(true);
0380: }
0381: /*} else {
0382: SalomeTMF.getRenameTestButton().setEnabled(false);
0383: SalomeTMF.getDelTestOrTestList().setEnabled(false);
0384: TestMethods.getDelTestMenuItem().setEnabled(false);
0385: }*/
0386: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0387: DataModel.setCurrentFamily(pFamily);
0388: DataModel.initFamily(pFamily);
0389: SalomeTMFPanels
0390: .setTestPanelWorkSpace(DataConstants.FAMILY);
0391: familyName = pFamily.getNameFromModel();
0392: /* if (DataModel.isBeginDescriptionModification()) {
0393: DataModel.setFamilyChange(true);
0394: DataModel.setBeginDescriptionModification(false);
0395: }*/
0396:
0397: } else if (node.getUserObject() instanceof TestList) {
0398: TestList pTestList = (TestList) node
0399: .getUserObject();
0400: oldData = pTestList;
0401: if (Permission.canUpdateTest())
0402: SalomeTMFPanels.getRenameTestButton()
0403: .setEnabled(true);
0404: if (Permission.canDeleteTest()) {
0405: SalomeTMFPanels.getDelTestOrTestList()
0406: .setEnabled(true);
0407: PopupMenuFactory.getDelTestMenuItem()
0408: .setEnabled(true);
0409: }
0410: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0411: DataModel.setCurrentTestList(pTestList);
0412: DataModel.initTestList(pTestList);
0413: SalomeTMFPanels
0414: .setTestPanelWorkSpace(DataConstants.TESTLIST);
0415: testListName = pTestList.getNameFromModel();
0416: /*if (DataModel.isBeginDescriptionModification()) {
0417: DataModel.setTestListChange(true);
0418: DataModel.setBeginDescriptionModification(false);
0419: }*/
0420:
0421: } else {
0422: oldData = null;
0423: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0424: SalomeTMFPanels.getRenameTestButton()
0425: .setEnabled(false);
0426: SalomeTMFPanels.getDelTestOrTestList()
0427: .setEnabled(false);
0428: PopupMenuFactory.getDelTestMenuItem()
0429: .setEnabled(false);
0430: SalomeTMFPanels.setTestPanelWorkSpace(-1); //remove all
0431: }
0432: }
0433: if (getTreeType() == CAMPAIGN) {
0434: SalomeTMFPanels.reValidateCampainPanel();
0435: } else {
0436: SalomeTMFPanels.reValidateTestPanel();
0437: }
0438: }
0439: tree.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0440: }
0441: });
0442:
0443: JScrollPane scrollPane = new JScrollPane(tree,
0444: ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
0445: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
0446: add(scrollPane);
0447: } // Fin du constructeur DynamicTree/0
0448:
0449: /**
0450: * Supprime tout de l'arbre, sauf la racine
0451: */
0452: public void clear() {
0453: rootNode.removeAllChildren();
0454: treeModel.reload();
0455: //treeModel.reload();
0456: } // Fin de la m?thode clear/0
0457:
0458: /**
0459: * Suppression du noeud courant.
0460: */
0461: public void removeCurrentNode() {
0462: TreePath currentSelection = tree.getSelectionPath();
0463: if (currentSelection != null) {
0464: DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) (currentSelection
0465: .getLastPathComponent());
0466: MutableTreeNode parent = (MutableTreeNode) (currentNode
0467: .getParent());
0468: if (parent != null) {
0469: treeModel.removeNodeFromParent(currentNode);
0470: if (parent instanceof DefaultMutableTreeNode) {
0471: refreshNode((DefaultMutableTreeNode) parent);
0472: }
0473: //tree.scrollPathToVisible(new TreePath(((DefaultMutableTreeNode)parent).getPath()));
0474: return;
0475: }
0476: }
0477: // Si aucune s?lection ou si la racine est s?lectionn?e
0478: // toolkit.beep();
0479: } // Fin de la classe removeCurrentNode/0
0480:
0481: public void setCursorWait() {
0482: tree.setCursor(new Cursor(Cursor.WAIT_CURSOR));
0483: }
0484:
0485: public void setCursorNormal() {
0486: tree.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
0487: }
0488:
0489: public void removeNode(DefaultMutableTreeNode node) {
0490: treeModel.removeNodeFromParent(node);
0491: }
0492:
0493: public void removeChildFromNode(DefaultMutableTreeNode node) {
0494: Vector nodeToRemove = new Vector();
0495: for (int i = 0; i < node.getChildCount(); i++) {
0496: DefaultMutableTreeNode pNode = (DefaultMutableTreeNode) node
0497: .getChildAt(i);
0498: nodeToRemove.add(pNode);
0499: }
0500: int size = nodeToRemove.size();
0501: for (int i = 0; i < size; i++) {
0502: DefaultMutableTreeNode pNode = (DefaultMutableTreeNode) nodeToRemove
0503: .get(i);
0504: treeModel.removeNodeFromParent(pNode);
0505: }
0506: }
0507:
0508: /**
0509: * Cherche de mani?re r?cursive et supprime le noeud correspond ? celui
0510: * pass? en param?tre. A l'appel le premier param?tre est le noeud de
0511: * d?but de la recherche.
0512: * @param currentNode le noeud courant
0513: * @param node le noeud ? retirer.
0514: */
0515: public void searchAndRemove(DefaultMutableTreeNode currentNode,
0516: DefaultMutableTreeNode node) {
0517: if (currentNode.equals(node)) {
0518: MutableTreeNode parent = (MutableTreeNode) (currentNode
0519: .getParent());
0520: if (parent != null) {
0521: treeModel.removeNodeFromParent(currentNode);
0522: }
0523: } else {
0524: for (int i = 0; i < currentNode.getChildCount(); i++) {
0525: searchAndRemove((DefaultMutableTreeNode) currentNode
0526: .getChildAt(i), node);
0527: }
0528: }
0529: } // Fin de la m?thode searchAndRemove/2
0530:
0531: /**
0532: * M?thode d'ajout d'un noeud dans l'arbre
0533: * @param child l'objet ajout? dans l'arbre
0534: * @return le nouveau noeud de l'arbre
0535: */
0536: public DefaultMutableTreeNode addObject(Object child) {
0537: DefaultMutableTreeNode parentNode = null;
0538: TreePath parentPath = tree.getSelectionPath();
0539:
0540: if (parentPath == null) {
0541: parentNode = rootNode;
0542: } else {
0543: parentNode = (DefaultMutableTreeNode) (parentPath
0544: .getLastPathComponent());
0545: }
0546: return addObject(parentNode, child, true);
0547: } // Fin de la classe addObject/1
0548:
0549: /**
0550: * M?thode d'ajout d'un noeud invisible sous un parent
0551: * @param parent le parent
0552: * @param child le noeud ajout?
0553: * @return le nouveau noeud de l'arbre
0554: */
0555: public DefaultMutableTreeNode addObject(
0556: DefaultMutableTreeNode parent, Object child) {
0557: return addObject(parent, child, false);
0558: } // Fin de la classe addObject/2
0559:
0560: /**
0561: * M?thode d'ajout d'un noeud dans l'arbre sous le parent.
0562: * @param parent le parent
0563: * @param child le noeud ? ajouter
0564: * @param shouldBeVisible visible ou non
0565: * @return le nouveau noeud de l'arbre
0566: */
0567: public DefaultMutableTreeNode addObject(
0568: DefaultMutableTreeNode parent, Object child,
0569: boolean shouldBeVisible) {
0570: // System.out.println("Ajout de : " + child + " ? " + parent);
0571: DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
0572: child);
0573: return addNode(parent, childNode, shouldBeVisible);
0574:
0575: } // Fin de la classe addObject/3
0576:
0577: public DefaultMutableTreeNode addNode(
0578: DefaultMutableTreeNode parent,
0579: DefaultMutableTreeNode childNode, boolean shouldBeVisible) {
0580: // System.out.println("Ajout de : " + child + " ? " + parent);
0581: if (parent == null) {
0582: parent = rootNode;
0583: }
0584: // Insertion du noeud
0585: treeModel.insertNodeInto(childNode, parent, parent
0586: .getChildCount());
0587:
0588: // on s'assure que le noeud est visible
0589: if (shouldBeVisible) {
0590: tree.scrollPathToVisible(new TreePath(childNode.getPath()));
0591: }
0592:
0593: return childNode;
0594: } // Fin de la classe addObject/3
0595:
0596: /**
0597: * M?thode qui retourne le noeud de l'arbre qui est s?lectionn?
0598: * @return un noeud de l'arbre
0599: */
0600: public DefaultMutableTreeNode getSelectedNode() {
0601: return selectedNode;
0602: } // Fin de la m?thode getSelectedNode/0
0603:
0604: /**
0605: * Retourne la racine de l'arbre
0606: * @return la racine de l'arbre
0607: */
0608: public DefaultMutableTreeNode getRoot() {
0609: return rootNode;
0610: } // Fin de la m?thode getRoot/0
0611:
0612: /**
0613: * Retourne le type de l'arbre : "campagne" ou "suite"
0614: * @return le type de l'arbre
0615: */
0616: public int getTreeType() {
0617: return treeType;
0618: } // Fin de la m?thode getTreeType/0
0619:
0620: /**
0621: * Retourne le noeud correspondant ? la famille dont le nom est pass? en
0622: * param?tre. Retourne <code>null</code>, si le nom ne correspond pas ? une
0623: * famille.
0624: * @param familyName un nom
0625: * @return le noeud correspondant ? la famille dont le nom est pass? en
0626: * param?tre. Retourne <code>null</code>, si le nom ne correspond pas ? une
0627: * famille.
0628: */
0629: public DefaultMutableTreeNode findRemoveFamilyNode(
0630: String familyName, boolean toRemove) {
0631: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0632: .getRoot();
0633: for (int i = 0; i < root.getChildCount(); i++) {
0634: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
0635: .getChildAt(i);
0636: if (familyNode.getUserObject() instanceof Family
0637: && ((Family) familyNode.getUserObject())
0638: .getNameFromModel().equals(familyName)) {
0639: if (toRemove) {
0640: familyNode.removeFromParent();
0641: }
0642: return familyNode;
0643: }
0644: }
0645: return null;
0646: } // Fin de la m?thode findFamilyNode/1
0647:
0648: /**
0649: * Retourne le noeud correspondant ? la suite de tests dont le nom est
0650: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0651: * correspond pas ? une suite de tests
0652: * @param testListName un nom
0653: * @param familyName un nom de famille
0654: * @param toRemove pour indiquer que le noeud doit ?tre supprim?
0655: * @return le noeud correspondant ? la suite de tests dont le nom est
0656: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0657: * correspond pas ? une suite de tests.
0658: */
0659: public DefaultMutableTreeNode findRemoveTestListNode(
0660: String testListName, String familyName, boolean toRemove) {
0661: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0662: .getRoot();
0663: for (int i = 0; i < root.getChildCount(); i++) {
0664: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
0665: .getChildAt(i);
0666: if (familyNode.getUserObject() instanceof Family
0667: && ((Family) familyNode.getUserObject())
0668: .getNameFromModel().equals(familyName)) {
0669: for (int j = 0; j < familyNode.getChildCount(); j++) {
0670: DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
0671: .getChildAt(j);
0672: if (testListNode.getUserObject() instanceof TestList
0673: && ((TestList) testListNode.getUserObject())
0674: .getNameFromModel().equals(
0675: testListName)) {
0676: if (toRemove) {
0677: testListNode.removeFromParent();
0678: }
0679: return testListNode;
0680: }
0681: }
0682: }
0683: }
0684: return null;
0685: } // Fin de la m?thode findFamilyNode/1
0686:
0687: /**
0688: * Retourne le noeud correspondant ? la suite de tests dont le nom est
0689: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0690: * correspond pas ? une suite de tests
0691: * @param testListName un nom
0692: * @param toRemove pour supprimer le noeud une fois trouv?
0693: * @return le noeud correspondant ? la suite de tests dont le nom est
0694: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0695: * correspond pas ? une suite de tests.
0696: */
0697: public DefaultMutableTreeNode findRemoveTestNode(String testName,
0698: String testListName, String familyName, boolean toRemove) {
0699: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0700: .getRoot();
0701: for (int i = 0; i < root.getChildCount(); i++) {
0702: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) root
0703: .getChildAt(i);
0704: if (familyNode.getUserObject() instanceof Family
0705: && ((Family) familyNode.getUserObject())
0706: .getNameFromModel().equals(familyName)) {
0707: for (int j = 0; j < familyNode.getChildCount(); j++) {
0708: DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
0709: .getChildAt(j);
0710: if (testListNode.getUserObject() instanceof TestList
0711: && ((TestList) testListNode.getUserObject())
0712: .getNameFromModel().equals(
0713: testListName)) {
0714: for (int k = 0; k < testListNode
0715: .getChildCount(); k++) {
0716: DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) testListNode
0717: .getChildAt(k);
0718: if (testNode.getUserObject() instanceof Test
0719: && ((Test) testNode.getUserObject())
0720: .getNameFromModel().equals(
0721: testName)) {
0722: if (toRemove) {
0723: testNode.removeFromParent();
0724: }
0725: return testNode;
0726: }
0727: }
0728:
0729: }
0730: }
0731: }
0732: }
0733: return null;
0734: } // Fin de la m?thode findFamilyNode/1
0735:
0736: /**
0737: * Retourne le noeud correspondant ? la campagne dont le nom est pass? en
0738: * param?tre. Retourne <code>null</code>, si le nom ne correspond pas ? une
0739: * campagne.
0740: * Si le bool?en est mis ? vrai, le noeud est supprim? de l'arbre.
0741: * @param familyName un nom
0742: * @param toRemove vrai pour supprimer le noeud, faux sinon.
0743: * @return le noeud correspondant ? la campagne dont le nom est pass? en
0744: * param?tre. Retourne <code>null</code>, si le nom ne correspond pas ? une
0745: * campagne.
0746: */
0747: public DefaultMutableTreeNode findRemoveCampaignNode(
0748: String campaignName, boolean toRemove) {
0749: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0750: .getRoot();
0751: for (int i = 0; i < root.getChildCount(); i++) {
0752: DefaultMutableTreeNode campaignNode = (DefaultMutableTreeNode) root
0753: .getChildAt(i);
0754: if (campaignNode.getUserObject() instanceof Campaign
0755: && ((Campaign) campaignNode.getUserObject())
0756: .getNameFromModel().equals(campaignName)) {
0757: if (toRemove) {
0758: campaignNode.removeFromParent();
0759: }
0760: return campaignNode;
0761: }
0762: }
0763: return null;
0764: } // Fin de la m?thode findFamilyNode/1
0765:
0766: /**
0767: * Retourne le noeud correspondant ? la suite de tests dont le nom est
0768: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0769: * correspond pas ? une suite de tests
0770: * @param testListName un nom
0771: * @return le noeud correspondant ? la suite de tests dont le nom est
0772: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0773: * correspond pas ? une suite de tests.
0774: */
0775: public DefaultMutableTreeNode findRemoveFamilyNodeInCampagneTree(
0776: String familyName, String campaignName, boolean toRemove) {
0777: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0778: .getRoot();
0779: for (int i = 0; i < root.getChildCount(); i++) {
0780: DefaultMutableTreeNode campaignNode = (DefaultMutableTreeNode) root
0781: .getChildAt(i);
0782: if (campaignNode.getUserObject() instanceof Campaign
0783: && ((Campaign) campaignNode.getUserObject())
0784: .getNameFromModel().equals(campaignName)) {
0785: for (int j = 0; j < campaignNode.getChildCount(); j++) {
0786: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) campaignNode
0787: .getChildAt(j);
0788: if (familyNode.getUserObject() instanceof Family
0789: && ((Family) familyNode.getUserObject())
0790: .getNameFromModel().equals(
0791: familyName)) {
0792: if (toRemove) {
0793: familyNode.removeFromParent();
0794: }
0795: return familyNode;
0796: }
0797: }
0798: }
0799: }
0800: return null;
0801: } // Fin de la m?thode findFamilyNode/1
0802:
0803: /**
0804: * Retourne le noeud correspondant ? la suite de tests dont le nom est
0805: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0806: * correspond pas ? une suite de tests
0807: * @param testListName un nom
0808: * @return le noeud correspondant ? la suite de tests dont le nom est
0809: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0810: * correspond pas ? une suite de tests.
0811: */
0812: public DefaultMutableTreeNode findRemoveTestListNodeInCampagneTree(
0813: String testListName, String familyName,
0814: String campaignName, boolean toRemove) {
0815: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0816: .getRoot();
0817: for (int i = 0; i < root.getChildCount(); i++) {
0818: DefaultMutableTreeNode campaignNode = (DefaultMutableTreeNode) root
0819: .getChildAt(i);
0820: if (campaignNode.getUserObject() instanceof Campaign
0821: && ((Campaign) campaignNode.getUserObject())
0822: .getNameFromModel().equals(campaignName)) {
0823: for (int j = 0; j < campaignNode.getChildCount(); j++) {
0824: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) campaignNode
0825: .getChildAt(j);
0826: if (familyNode.getUserObject() instanceof Family
0827: && ((Family) familyNode.getUserObject())
0828: .getNameFromModel().equals(
0829: familyName)) {
0830: for (int k = 0; k < familyNode.getChildCount(); k++) {
0831: DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
0832: .getChildAt(k);
0833: if (testListNode.getUserObject() instanceof TestList
0834: && ((TestList) testListNode
0835: .getUserObject())
0836: .getNameFromModel().equals(
0837: testListName)) {
0838: if (toRemove) {
0839: testListNode.removeFromParent();
0840: }
0841: return testListNode;
0842: }
0843: }
0844: }
0845: }
0846: }
0847: }
0848: return null;
0849: } // Fin de la m?thode findFamilyNode/1
0850:
0851: /**
0852: * Retourne le noeud correspondant au test dont le nom est
0853: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0854: * correspond pas ? un test
0855: * @param testName un nom de test
0856: * @param testListName un nom de suite de tests
0857: * @param familyName un nom de famille
0858: * @param campaignName un nom de campagne
0859: * @param toRemove pour indiquer s'il doit ?tre supprim?
0860: * @return le noeud correspondant au test dont le nom est
0861: * pass? en param?tre. Retourne <code>null</code>, si le nom ne
0862: * correspond pas ? un test.
0863: */
0864: public DefaultMutableTreeNode findRemoveTestNodeInCampagneTree(
0865: String testName, String testListName, String familyName,
0866: String campaignName, boolean toRemove) {
0867: DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel
0868: .getRoot();
0869: for (int i = 0; i < root.getChildCount(); i++) {
0870: DefaultMutableTreeNode campaignNode = (DefaultMutableTreeNode) root
0871: .getChildAt(i);
0872: if (campaignNode.getUserObject() instanceof Campaign
0873: && ((Campaign) campaignNode.getUserObject())
0874: .getNameFromModel().equals(campaignName)) {
0875: for (int j = 0; j < campaignNode.getChildCount(); j++) {
0876: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) campaignNode
0877: .getChildAt(j);
0878: if (familyNode.getUserObject() instanceof Family
0879: && ((Family) familyNode.getUserObject())
0880: .getNameFromModel().equals(
0881: familyName)) {
0882: for (int k = 0; k < familyNode.getChildCount(); k++) {
0883: DefaultMutableTreeNode testListNode = (DefaultMutableTreeNode) familyNode
0884: .getChildAt(k);
0885: if (testListNode.getUserObject() instanceof TestList
0886: && ((TestList) testListNode
0887: .getUserObject())
0888: .getNameFromModel().equals(
0889: testListName)) {
0890: for (int h = 0; h < testListNode
0891: .getChildCount(); h++) {
0892: DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) testListNode
0893: .getChildAt(h);
0894: if (testNode.getUserObject() instanceof Test
0895: && ((Test) testNode
0896: .getUserObject())
0897: .getNameFromModel()
0898: .equals(testName)) {
0899: if (toRemove) {
0900: testNode.removeFromParent();
0901: }
0902: return testNode;
0903: }
0904: }
0905: }
0906: }
0907: }
0908: }
0909: }
0910: }
0911: return null;
0912: } // Fin de la m?thode findFamilyNode/1
0913:
0914: /**
0915: * Retourne le mod?le de donn?es de l'arbre
0916: * @return le mod?le de donn?es de l'arbre
0917: */
0918: public TestTreeModel getModel() {
0919: return treeModel;
0920: } // Fin de la m?thode getModel/0
0921:
0922: public void refreshNode(DefaultMutableTreeNode node) {
0923: if (node != null) {
0924: treeModel.reload(node);
0925: }
0926: }
0927:
0928: public void refreshCurent() {
0929: if (selectedNode != null) {
0930: treeModel.reload(selectedNode);
0931: }
0932: }
0933:
0934: /**
0935: * Rend visible le chemin jusqu'au noeud pass? en param?tre
0936: * @param node un noeud
0937: */
0938: public void scrollPathToVisible(DefaultMutableTreeNode node) {
0939: tree.scrollPathToVisible(new TreePath(node.getPath()));
0940: } // Fin de la m?thode scrollPathToVisible/1
0941:
0942: public void makeVisible(DefaultMutableTreeNode node) {
0943: tree.makeVisible(new TreePath(node.getPath()));
0944: }
0945:
0946: public void resetToRoot() {
0947: tree.scrollPathToVisible(new TreePath(rootNode.getPath()));
0948: if (getTreeType() == CAMPAIGN) {
0949: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0950: SalomeTMFPanels.getDelCampagne().setEnabled(false);
0951: SalomeTMFPanels.getRenameCampaignButton().setEnabled(false);
0952: SalomeTMFPanels.getOrderCampagne().setEnabled(false);
0953: SalomeTMFPanels.getAddTestInCampagne().setEnabled(false);
0954: /*PopupMenuFactory.getImportToCampMenuItem().setEnabled(false);
0955: PopupMenuFactory.getDelCampMenuItem().setEnabled(false);*/
0956: PopupMenuFactory.setRootCampAction(true);
0957: SalomeTMFPanels.setCampPanelWorkSpace(-1);
0958: } else {
0959: //DataModel.setOldCaretDescription(DataModel.getCaretDescriptionValue());
0960: SalomeTMFPanels.getRenameTestButton().setEnabled(false);
0961: SalomeTMFPanels.getDelTestOrTestList().setEnabled(false);
0962: PopupMenuFactory.getDelTestMenuItem().setEnabled(false);
0963: SalomeTMFPanels.setTestPanelWorkSpace(-1); //remove all
0964: }
0965: }
0966:
0967: /**************************************************************************/
0968: /** CLASSE INTERNE ***/
0969: /**************************************************************************/
0970:
0971: /**
0972: * Classe repr?sentant le listener associ? ? l'arbre
0973: * @author teaml039
0974: * @version 0.1
0975: */
0976: // class MyTreeModelListener implements TreeModelListener {
0977: /**
0978: * Apppel? lorsque les noeuds sont modifi?s
0979: * @param e un ?v?nement sur l'arbre
0980: */
0981: /* public void treeNodesChanged(TreeModelEvent e) {
0982:
0983:
0984: } // Fin de la m?thode treeNodesChanged/1
0985:
0986: public void treeNodesInserted(TreeModelEvent e) {
0987: }
0988: public void treeNodesRemoved(TreeModelEvent e) {
0989: }
0990: public void treeStructureChanged(TreeModelEvent e) {
0991: }
0992: } // Fin de la classe MyTreeModelListener
0993: */
0994:
0995: /**
0996: * @return
0997: */
0998: public JTree getTree() {
0999: return tree;
1000: }
1001:
1002: public void givePopupMenuToTree() {
1003: // Menu PopUp pour la souris
1004: JPopupMenu popUp;
1005: if (getTreeType() == CAMPAIGN) {
1006: popUp = PopupMenuFactory.createTreePopUpForCampagne();
1007: } else {
1008: popUp = PopupMenuFactory.createTreePopUpForList();
1009: }
1010: tree.addMouseListener(new PopupListener(popUp, tree));
1011: }
1012:
1013: } // Fin de la classe DynamicTree
|