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 Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.ihm;
0025:
0026: import java.awt.BorderLayout;
0027: import java.awt.Color;
0028: import java.awt.Container;
0029: import java.awt.Dimension;
0030: import java.awt.FlowLayout;
0031: import java.awt.GridLayout;
0032: import java.awt.event.ActionEvent;
0033: import java.awt.event.ActionListener;
0034: import java.util.ArrayList;
0035: import java.util.HashMap;
0036: import java.util.HashSet;
0037: import java.util.Iterator;
0038:
0039: import javax.swing.BorderFactory;
0040: import javax.swing.Box;
0041: import javax.swing.BoxLayout;
0042: import javax.swing.ButtonGroup;
0043: import javax.swing.DefaultComboBoxModel;
0044: import javax.swing.DefaultListModel;
0045: import javax.swing.Icon;
0046: import javax.swing.JButton;
0047: import javax.swing.JComboBox;
0048: import javax.swing.JDialog;
0049: import javax.swing.JList;
0050: import javax.swing.JPanel;
0051: import javax.swing.JRadioButton;
0052: import javax.swing.JScrollPane;
0053: import javax.swing.ListSelectionModel;
0054: import javax.swing.event.ListSelectionEvent;
0055: import javax.swing.event.ListSelectionListener;
0056: import javax.swing.tree.DefaultMutableTreeNode;
0057:
0058: import org.objectweb.salome_tmf.data.Campaign;
0059: import org.objectweb.salome_tmf.data.CampaignData;
0060: import org.objectweb.salome_tmf.data.Family;
0061: import org.objectweb.salome_tmf.data.Test;
0062: import org.objectweb.salome_tmf.data.TestList;
0063: import org.objectweb.salome_tmf.data.TestPlanData;
0064: import org.objectweb.salome_tmf.ihm.languages.Language;
0065: import org.objectweb.salome_tmf.ihm.models.TestListFamilyCampaignTreeNode;
0066: import org.objectweb.salome_tmf.ihm.models.TestTreeModel;
0067: import org.objectweb.salome_tmf.ihm.tools.Tools;
0068:
0069: /**
0070: * Classe qui d?finit la fen?tre pour ordonner les suites de tests
0071: */
0072: public class TestOrdering extends JDialog implements IHMConstants {
0073:
0074: /**
0075: * Ancien mod?le de donn?es avant organisation
0076: */
0077: DefaultListModel listModel;
0078:
0079: HashSet familyHashSet;
0080:
0081: DefaultComboBoxModel testListComboModel;
0082:
0083: HashSet campaignHashSet;
0084:
0085: JList list;
0086: /**
0087: * Mod?le de donn?es pour le choix
0088: */
0089: private DefaultComboBoxModel comboModel;
0090:
0091: /**
0092: * Liste d?roulante pour le choix des suites ou des tests.
0093: */
0094: JComboBox choiceComboBox;
0095:
0096: JButton upButton;
0097:
0098: JButton downButton;
0099:
0100: /**
0101: * La cl? est une famille, la valeur une arrayList avec des suites de tests
0102: * de cette famille
0103: */
0104: HashMap testListMap;
0105:
0106: /**
0107: * La cl? est une suite de tests, la valeur une ArrayList avec les tests de
0108: * cette suite.
0109: */
0110: HashMap testMap;
0111:
0112: TestTreeModel workingModel;
0113:
0114: JRadioButton familyButton;
0115: JRadioButton testListButton;
0116: JRadioButton testButton;
0117: JRadioButton campagneButton;
0118:
0119: DefaultMutableTreeNode familySelected;
0120:
0121: DefaultMutableTreeNode testListSelected;
0122: JScrollPane usersListScrollPane;
0123:
0124: boolean useCampaign;
0125:
0126: /**
0127: * Pour indiquer si l'ordre des campagnes a ?t? modifi? dans l'arbre des
0128: * campagnes
0129: */
0130: boolean campaignOrderModified;
0131:
0132: /**
0133: * Indique si l'ordre des familles a ?t? modifi? dans l'arbre des tests
0134: */
0135: boolean familyOrderModified;
0136:
0137: /**
0138: * Liste des familles dont l'ordre des suites a ?t? modifi? dans l'arbre des
0139: * tests
0140: */
0141: ArrayList familiesTestListOrderModified;
0142:
0143: /**
0144: * Liste des suites dont l'ordre des tests a ?t? modifi? dans l'arbre des
0145: * tests
0146: */
0147: ArrayList testListTestOrderModified;
0148:
0149: /**
0150: * Liste des campagnes dont l'ordre des familles a ?t? modifi? dans l'arbre
0151: * des campagnes
0152: */
0153: ArrayList campaignFamilyOrderModified;
0154:
0155: /**
0156: * Liste des campagnes dont l'ordre des suites a ?t? modifi? dans l'arbre des
0157: * campagnes
0158: */
0159: ArrayList campaignFamiliesTestListOrderModified;
0160:
0161: /**
0162: * Liste des campagnes dont l'ordre des tests a ?t? modifi? dans l'arbre des
0163: * campagnes
0164: */
0165: ArrayList campaignFamiliesTestListTestOrderModified;
0166:
0167: /******************************************************************************/
0168: /** CONSTRUCTEUR ***/
0169: /******************************************************************************/
0170:
0171: /**
0172: * Constructeur de la fen?tre
0173: * @param listModel le mod?le de liste
0174: */
0175: public TestOrdering(TestTreeModel testTreeModel,
0176: boolean withCampaign) {
0177:
0178: super (SalomeTMF.ptrFrame, true);
0179:
0180: testListComboModel = new DefaultComboBoxModel();
0181: campaignHashSet = new HashSet();
0182: comboModel = new DefaultComboBoxModel();
0183: choiceComboBox = new JComboBox(comboModel);
0184: upButton = new JButton();
0185: downButton = new JButton();
0186: familyButton = new JRadioButton(Language.getInstance().getText(
0187: "Familles"));
0188: testListButton = new JRadioButton(Language.getInstance()
0189: .getText("Suites"));
0190: testButton = new JRadioButton(Language.getInstance().getText(
0191: "Tests"));
0192: campagneButton = new JRadioButton(Language.getInstance()
0193: .getText("Campagnes"));
0194:
0195: campaignOrderModified = false;
0196:
0197: familyOrderModified = false;
0198:
0199: familiesTestListOrderModified = new ArrayList();
0200: testListTestOrderModified = new ArrayList();
0201:
0202: campaignFamilyOrderModified = new ArrayList();
0203:
0204: campaignFamiliesTestListOrderModified = new ArrayList();
0205:
0206: campaignFamiliesTestListTestOrderModified = new ArrayList();
0207:
0208: familyHashSet = new HashSet();
0209:
0210: campagneButton.addActionListener(new ActionListener() {
0211: public void actionPerformed(ActionEvent e) {
0212: DefaultMutableTreeNode root = (DefaultMutableTreeNode) workingModel
0213: .getRoot();
0214: listModel.clear();
0215: comboModel.removeAllElements();
0216: choiceComboBox.setEnabled(false);
0217: usersListScrollPane.setBorder(BorderFactory
0218: .createTitledBorder(Language.getInstance()
0219: .getText("Campagnes")));
0220: for (int i = 0; i < root.getChildCount(); i++) {
0221: listModel.addElement(root.getChildAt(i));
0222: }
0223: }
0224: });
0225:
0226: familyButton.addActionListener(new ActionListener() {
0227: public void actionPerformed(ActionEvent e) {
0228: if (useCampaign) {
0229: choiceComboBox.setEnabled(true);
0230: comboModel.removeAllElements();
0231: for (Iterator iter = campaignHashSet.iterator(); iter
0232: .hasNext();) {
0233: comboModel.addElement(iter.next());
0234: }
0235: } else {
0236: DefaultMutableTreeNode root = (DefaultMutableTreeNode) workingModel
0237: .getRoot();
0238: listModel.clear();
0239: comboModel.removeAllElements();
0240: choiceComboBox.setEnabled(false);
0241: for (int i = 0; i < root.getChildCount(); i++) {
0242: listModel.addElement(root.getChildAt(i));
0243: }
0244: }
0245: usersListScrollPane.setBorder(BorderFactory
0246: .createTitledBorder(Language.getInstance()
0247: .getText("Familles")));
0248: }
0249: });
0250:
0251: testListButton.addActionListener(new ActionListener() {
0252: public void actionPerformed(ActionEvent e) {
0253: choiceComboBox.setEnabled(true);
0254: listModel.clear();
0255: comboModel.removeAllElements();
0256: usersListScrollPane.setBorder(BorderFactory
0257: .createTitledBorder(Language.getInstance()
0258: .getText("Suites")));
0259: for (Iterator iter = familyHashSet.iterator(); iter
0260: .hasNext();) {
0261: TestListFamilyCampaignTreeNode tlf = (TestListFamilyCampaignTreeNode) iter
0262: .next();
0263: if (!containsValue(tlf)) {
0264: comboModel.addElement(tlf);
0265: }
0266:
0267: }
0268: }
0269: });
0270:
0271: testButton.addActionListener(new ActionListener() {
0272: public void actionPerformed(ActionEvent e) {
0273: choiceComboBox.setEnabled(true);
0274: listModel.clear();
0275: comboModel.removeAllElements();
0276: usersListScrollPane.setBorder(BorderFactory
0277: .createTitledBorder(Language.getInstance()
0278: .getText("Tests")));
0279: //DefaultMutableTreeNode root = (DefaultMutableTreeNode)workingModel.getRoot();
0280: for (int i = 0; i < testListComboModel.getSize(); i++) {
0281: comboModel.addElement(testListComboModel
0282: .getElementAt(i));
0283: }
0284: }
0285: });
0286:
0287: //Grouper les boutons radio
0288: ButtonGroup choiceGroup = new ButtonGroup();
0289: if (withCampaign) {
0290: choiceGroup.add(campagneButton);
0291: }
0292: choiceGroup.add(familyButton);
0293: choiceGroup.add(testListButton);
0294: choiceGroup.add(testButton);
0295:
0296: //Put the radio buttons in a column in a panel.
0297: JPanel radioPanel = new JPanel(new GridLayout(1, 0));
0298: if (withCampaign) {
0299: radioPanel.add(campagneButton);
0300: }
0301: radioPanel.add(familyButton);
0302: radioPanel.add(testListButton);
0303: radioPanel.add(testButton);
0304:
0305: // Combo Panel
0306: JPanel comboPanel = new JPanel(
0307: new FlowLayout(FlowLayout.CENTER));
0308: comboPanel.add(choiceComboBox);
0309: choiceComboBox.setEnabled(false);
0310:
0311: choiceComboBox.addActionListener(new ActionListener() {
0312: public void actionPerformed(ActionEvent e) {
0313: listModel.clear();
0314: TestListFamilyCampaignTreeNode selectedNode = ((TestListFamilyCampaignTreeNode) choiceComboBox
0315: .getSelectedItem());
0316: ;
0317: if (selectedNode != null) {
0318: if (familyButton.isSelected() && useCampaign) {
0319: for (int i = 0; i < selectedNode
0320: .getCampaignNode().getChildCount(); i++) {
0321: listModel.addElement(selectedNode
0322: .getCampaignNode().getChildAt(i));
0323: }
0324: } else if (testListButton.isSelected()) {
0325: for (int i = 0; i < selectedNode
0326: .getFamilyNode().getChildCount(); i++) {
0327: listModel.addElement(selectedNode
0328: .getFamilyNode().getChildAt(i));
0329: }
0330: } else if (testButton.isSelected()) {
0331: for (int i = 0; i < selectedNode
0332: .getTestListNode().getChildCount(); i++) {
0333: listModel.addElement(selectedNode
0334: .getTestListNode().getChildAt(i));
0335: }
0336: }
0337: }
0338: }
0339: });
0340:
0341: JPanel choicePanel = new JPanel();
0342: choicePanel.setLayout(new BoxLayout(choicePanel,
0343: BoxLayout.Y_AXIS));
0344: choicePanel.add(radioPanel);
0345: choicePanel.add(comboPanel);
0346: choicePanel.setBorder(BorderFactory
0347: .createLineBorder(Color.BLACK));
0348:
0349: Icon icon = Tools.createAppletImageIcon(PATH_TO_ARROW_UP_ICON,
0350: "");
0351: upButton.setIcon(icon);
0352: upButton.setEnabled(false);
0353: upButton.setToolTipText(Language.getInstance().getText(
0354: "Monter_d'un_cran"));
0355: upButton.addActionListener(new ActionListener() {
0356: public void actionPerformed(ActionEvent e) {
0357: int selectedIndex = list.getSelectedIndex();
0358: if (selectedIndex != -1) {
0359: Object objToGoUp = listModel
0360: .getElementAt(selectedIndex);
0361: Object objToGoDown = listModel
0362: .getElementAt(selectedIndex - 1);
0363: listModel
0364: .setElementAt(objToGoUp, selectedIndex - 1);
0365: listModel.setElementAt(objToGoDown, selectedIndex);
0366: list.setSelectedIndex(selectedIndex - 1);
0367: DefaultMutableTreeNode nodeToGoUp = null;
0368: DefaultMutableTreeNode nodeToGoDown = null;
0369: if (campagneButton.isSelected()) {
0370:
0371: try {
0372: ((Campaign) ((DefaultMutableTreeNode) objToGoUp)
0373: .getUserObject())
0374: .updateOrderInDB(false);
0375:
0376: // IHM
0377: nodeToGoUp = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) workingModel
0378: .getRoot())
0379: .getChildAt(selectedIndex);
0380: Campaign pCamp = (Campaign) nodeToGoUp
0381: .getUserObject();
0382:
0383: workingModel
0384: .removeNodeFromParent(nodeToGoUp);
0385: workingModel
0386: .insertNodeInto(
0387: nodeToGoUp,
0388: ((DefaultMutableTreeNode) workingModel
0389: .getRoot()),
0390: selectedIndex - 1);
0391: CampaignData.getCampaignList()
0392: .remove(pCamp);
0393: CampaignData.getCampaignList().add(
0394: (selectedIndex - 1), pCamp);
0395: campaignOrderModified = true;
0396:
0397: } catch (Exception exception) {
0398: exception.printStackTrace();
0399: Tools
0400: .ihmExceptionView(exception
0401: .toString());
0402: }
0403: } else if (familyButton.isSelected()) {
0404: if (useCampaign) {
0405: nodeToGoDown = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0406: .getSelectedItem())
0407: .getCampaignNode().getChildAt(
0408: selectedIndex - 1);
0409: nodeToGoUp = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0410: .getSelectedItem())
0411: .getCampaignNode().getChildAt(
0412: selectedIndex);
0413: ArrayList oldTestList = ((Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0414: .getSelectedItem())
0415: .getCampaignNode()).getUserObject())
0416: .getTestList();
0417: ArrayList oldSuiteList = ((Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0418: .getSelectedItem())
0419: .getCampaignNode()).getUserObject())
0420: .getTestListList();
0421: int firstTestIndex = oldTestList
0422: .indexOf(((DefaultMutableTreeNode) ((DefaultMutableTreeNode) nodeToGoDown
0423: .getFirstChild())
0424: .getFirstChild())
0425: .getUserObject());
0426: int firstSuiteIndex = oldSuiteList
0427: .indexOf(((DefaultMutableTreeNode) nodeToGoDown
0428: .getFirstChild())
0429: .getUserObject());
0430:
0431: try {
0432: // BdD
0433: Campaign camp = (Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0434: .getSelectedItem())
0435: .getCampaignNode())
0436: .getUserObject();
0437: Family pFamilyUp = (Family) nodeToGoUp
0438: .getUserObject();
0439: //Family pFamilyDown = (Family)nodeToGoUp.getUserObject();
0440:
0441: camp.updateTestFamilyOrderInDB(
0442: pFamilyUp.getIdBdd(), false);
0443:
0444: // IHM
0445: for (int j = 0; j < pFamilyUp
0446: .getTestListList().size(); j++) {
0447: TestList testList = (TestList) pFamilyUp
0448: .getTestListList().get(j);
0449: camp.getTestListList().remove(
0450: pFamilyUp.getTestListList()
0451: .get(j));
0452: for (int k = 0; k < testList
0453: .getTestList().size(); k++) {
0454: camp.getTestList().remove(
0455: testList.getTestList()
0456: .get(k));
0457:
0458: }
0459: }
0460: int addIndex = firstTestIndex;
0461: for (int j = 0; j < pFamilyUp
0462: .getTestListList().size(); j++) {
0463: TestList testList = (TestList) pFamilyUp
0464: .getTestListList().get(j);
0465: camp.getTestListList().add(
0466: (j + firstSuiteIndex),
0467: pFamilyUp.getTestListList()
0468: .get(j));
0469: for (int k = 0; k < testList
0470: .getTestList().size(); k++) {
0471: camp.getTestList().add(
0472: (k + addIndex),
0473: testList.getTestList()
0474: .get(k));
0475: addIndex++;
0476: }
0477: }
0478:
0479: workingModel
0480: .removeNodeFromParent(nodeToGoUp);
0481: workingModel
0482: .insertNodeInto(
0483: nodeToGoUp,
0484: ((TestListFamilyCampaignTreeNode) choiceComboBox
0485: .getSelectedItem())
0486: .getCampaignNode(),
0487: selectedIndex - 1);
0488: campaignFamilyOrderModified.add(camp);
0489: camp.getFamilyList().remove(pFamilyUp);
0490: camp.getFamilyList().add(
0491: (selectedIndex - 1), pFamilyUp);
0492: } catch (Exception exception) {
0493: exception.printStackTrace();
0494: Tools.ihmExceptionView(exception
0495: .toString());
0496: }
0497:
0498: } else {
0499:
0500: try {
0501: //Decrementation du selectionné
0502: ((Family) ((DefaultMutableTreeNode) objToGoUp)
0503: .getUserObject())
0504: .updateOrderInBddAndModel(false);
0505:
0506: //IHM
0507: nodeToGoUp = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) workingModel
0508: .getRoot())
0509: .getChildAt(selectedIndex);
0510: Family pFamilyUp = (Family) nodeToGoUp
0511: .getUserObject();
0512: workingModel
0513: .removeNodeFromParent(nodeToGoUp);
0514: workingModel
0515: .insertNodeInto(
0516: nodeToGoUp,
0517: ((DefaultMutableTreeNode) workingModel
0518: .getRoot()),
0519: selectedIndex - 1);
0520: TestPlanData.getFamilyList().remove(
0521: pFamilyUp);
0522: TestPlanData.getFamilyList().add(
0523: (selectedIndex - 1), pFamilyUp);
0524: familyOrderModified = true;
0525: } catch (Exception exception) {
0526: exception.printStackTrace();
0527: Tools.ihmExceptionView(exception
0528: .toString());
0529: }
0530: }
0531: } else if (testListButton.isSelected()) {
0532: nodeToGoUp = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0533: .getSelectedItem()).getFamilyNode()
0534: .getChildAt(selectedIndex);
0535: nodeToGoDown = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0536: .getSelectedItem()).getFamilyNode()
0537: .getChildAt(selectedIndex - 1);
0538: if (((TestListFamilyCampaignTreeNode) choiceComboBox
0539: .getSelectedItem()).getCampaignNode() == null) {
0540:
0541: try {
0542: ((TestList) nodeToGoUp.getUserObject())
0543: .updateOrderInBddAndModel(false);
0544:
0545: //IHM
0546: workingModel
0547: .removeNodeFromParent(nodeToGoUp);
0548: Family pFamily = (Family) ((TestListFamilyCampaignTreeNode) choiceComboBox
0549: .getSelectedItem())
0550: .getFamilyNode()
0551: .getUserObject();
0552: workingModel
0553: .insertNodeInto(
0554: nodeToGoUp,
0555: ((TestListFamilyCampaignTreeNode) choiceComboBox
0556: .getSelectedItem())
0557: .getFamilyNode(),
0558: selectedIndex - 1);
0559: familiesTestListOrderModified
0560: .add(pFamily);
0561: pFamily.getTestListList().remove(
0562: nodeToGoUp.getUserObject());
0563: pFamily.getTestListList().add(
0564: (selectedIndex - 1),
0565: nodeToGoUp.getUserObject());
0566: } catch (Exception exception) {
0567: exception.printStackTrace();
0568: Tools.ihmExceptionView(exception
0569: .toString());
0570: }
0571: } else {
0572: ArrayList oldTestList = ((Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0573: .getSelectedItem())
0574: .getCampaignNode()).getUserObject())
0575: .getTestList();
0576: // On récupère l'indice du premier test de la suite qui descend
0577: int firstIndex = oldTestList
0578: .indexOf(((DefaultMutableTreeNode) nodeToGoDown
0579: .getFirstChild())
0580: .getUserObject());
0581: int i = 0;
0582: if (firstIndex != -1) {
0583:
0584: try {
0585: // BdD
0586: Campaign camp = (Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0587: .getSelectedItem())
0588: .getCampaignNode())
0589: .getUserObject();
0590: camp.updateTestSuiteOrderInDB(
0591: ((TestList) nodeToGoUp
0592: .getUserObject())
0593: .getIdBdd(), false);
0594:
0595: // IHM
0596: for (i = 0; i < ((TestList) nodeToGoUp
0597: .getUserObject())
0598: .getTestList().size(); i++) {
0599: camp
0600: .getTestList()
0601: .remove(
0602: ((TestList) nodeToGoUp
0603: .getUserObject())
0604: .getTestList()
0605: .get(i));
0606: }
0607: for (i = 0; i < ((TestList) nodeToGoUp
0608: .getUserObject())
0609: .getTestList().size(); i++) {
0610: camp
0611: .getTestList()
0612: .add(
0613: (i + firstIndex),
0614: ((TestList) nodeToGoUp
0615: .getUserObject())
0616: .getTestList()
0617: .get(i));
0618: }
0619:
0620: workingModel
0621: .removeNodeFromParent(nodeToGoUp);
0622: workingModel
0623: .insertNodeInto(
0624: nodeToGoUp,
0625: ((TestListFamilyCampaignTreeNode) choiceComboBox
0626: .getSelectedItem())
0627: .getFamilyNode(),
0628: selectedIndex - 1);
0629: campaignFamiliesTestListOrderModified
0630: .add(camp);
0631: camp.getTestListList().remove(
0632: nodeToGoUp.getUserObject());
0633: camp.getTestListList().add(
0634: (selectedIndex - 1),
0635: nodeToGoUp.getUserObject());
0636:
0637: } catch (Exception exception) {
0638: exception.printStackTrace();
0639: Tools.ihmExceptionView(exception
0640: .toString());
0641: }
0642:
0643: }
0644: }
0645: } else if (testButton.isSelected()) {
0646: nodeToGoUp = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0647: .getSelectedItem()).getTestListNode()
0648: .getChildAt(selectedIndex);
0649: nodeToGoDown = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0650: .getSelectedItem()).getTestListNode()
0651: .getChildAt(selectedIndex - 1);
0652: if (((TestListFamilyCampaignTreeNode) choiceComboBox
0653: .getSelectedItem()).getCampaignNode() == null) {
0654: try {
0655: TestList pSuite = (TestList) ((TestListFamilyCampaignTreeNode) choiceComboBox
0656: .getSelectedItem())
0657: .getTestListNode()
0658: .getUserObject();
0659: Test pTest = (Test) nodeToGoUp
0660: .getUserObject();
0661: //BDD
0662: pTest.updateOrderInBddAndModel(false);
0663:
0664: //IHM
0665: workingModel
0666: .removeNodeFromParent(nodeToGoUp);
0667: workingModel
0668: .insertNodeInto(
0669: nodeToGoUp,
0670: ((TestListFamilyCampaignTreeNode) choiceComboBox
0671: .getSelectedItem())
0672: .getTestListNode(),
0673: selectedIndex - 1);
0674: testListTestOrderModified
0675: .add(((TestListFamilyCampaignTreeNode) choiceComboBox
0676: .getSelectedItem())
0677: .getTestListNode()
0678: .getUserObject());
0679: pSuite.getTestList().remove(pTest);
0680: pSuite.getTestList().add(
0681: (selectedIndex - 1), pTest);
0682: } catch (Exception exception) {
0683: exception.printStackTrace();
0684: Tools.ihmExceptionView(exception
0685: .toString());
0686: }
0687: } else {
0688:
0689: try {
0690: // BdD
0691: Campaign camp = (Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0692: .getSelectedItem())
0693: .getCampaignNode())
0694: .getUserObject();
0695: camp.updateTestOrderInDB(
0696: ((Test) nodeToGoUp
0697: .getUserObject())
0698: .getIdBDD(), false);
0699:
0700: // IHM
0701: workingModel
0702: .removeNodeFromParent(nodeToGoUp);
0703: workingModel
0704: .insertNodeInto(
0705: nodeToGoUp,
0706: ((TestListFamilyCampaignTreeNode) choiceComboBox
0707: .getSelectedItem())
0708: .getTestListNode(),
0709: selectedIndex - 1);
0710: campaignFamiliesTestListTestOrderModified
0711: .add(camp);
0712: camp.getTestList().remove(
0713: nodeToGoUp.getUserObject());
0714: camp.getTestList().add(
0715: (selectedIndex - 1),
0716: nodeToGoUp.getUserObject());
0717:
0718: } catch (Exception exception) {
0719: exception.printStackTrace();
0720: Tools.ihmExceptionView(exception
0721: .toString());
0722: }
0723: }
0724: }
0725: }
0726: }
0727: });
0728:
0729: icon = Tools.createAppletImageIcon(PATH_TO_ARROW_DOWN_ICON, "");
0730: downButton.setIcon(icon);
0731: downButton.setEnabled(false);
0732: downButton.setToolTipText(Language.getInstance().getText(
0733: "Descendre_d'un_cran"));
0734: downButton.addActionListener(new ActionListener() {
0735: public void actionPerformed(ActionEvent e) {
0736: int selectedIndex = list.getSelectedIndex();
0737: if (selectedIndex != -1) {
0738: Object objToGoUp = listModel
0739: .getElementAt(selectedIndex + 1);
0740: Object objToGoDown = listModel
0741: .getElementAt(selectedIndex);
0742: listModel.setElementAt(objToGoUp, selectedIndex);
0743: listModel.setElementAt(objToGoDown,
0744: selectedIndex + 1);
0745: list.setSelectedIndex(selectedIndex + 1);
0746: DefaultMutableTreeNode nodeToGoUp = null;
0747: DefaultMutableTreeNode nodeToGoDown = null;
0748: if (campagneButton.isSelected()) {
0749: nodeToGoUp = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) workingModel
0750: .getRoot())
0751: .getChildAt(selectedIndex + 1);
0752:
0753: try {
0754: // BdD
0755: ((Campaign) ((DefaultMutableTreeNode) objToGoDown)
0756: .getUserObject())
0757: .updateOrderInDB(true);
0758:
0759: // IHM
0760: workingModel
0761: .removeNodeFromParent(nodeToGoUp);
0762: workingModel
0763: .insertNodeInto(
0764: nodeToGoUp,
0765: ((DefaultMutableTreeNode) workingModel
0766: .getRoot()),
0767: selectedIndex);
0768: CampaignData.getCampaignList().remove(
0769: nodeToGoUp.getUserObject());
0770: CampaignData.getCampaignList().add(
0771: (selectedIndex),
0772: nodeToGoUp.getUserObject());
0773: campaignOrderModified = true;
0774:
0775: } catch (Exception exception) {
0776: exception.printStackTrace();
0777: Tools
0778: .ihmExceptionView(exception
0779: .toString());
0780: }
0781:
0782: } else if (familyButton.isSelected()) {
0783: if (useCampaign) {
0784: nodeToGoDown = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0785: .getSelectedItem())
0786: .getCampaignNode().getChildAt(
0787: selectedIndex);
0788: nodeToGoUp = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0789: .getSelectedItem())
0790: .getCampaignNode().getChildAt(
0791: selectedIndex + 1);
0792: ArrayList oldTestList = ((Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0793: .getSelectedItem())
0794: .getCampaignNode()).getUserObject())
0795: .getTestList();
0796: ArrayList oldSuiteList = ((Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0797: .getSelectedItem())
0798: .getCampaignNode()).getUserObject())
0799: .getTestListList();
0800: int firstTestIndex = oldTestList
0801: .indexOf(((DefaultMutableTreeNode) ((DefaultMutableTreeNode) nodeToGoDown
0802: .getFirstChild())
0803: .getFirstChild())
0804: .getUserObject());
0805: int firstSuiteIndex = oldSuiteList
0806: .indexOf(((DefaultMutableTreeNode) nodeToGoDown
0807: .getFirstChild())
0808: .getUserObject());
0809:
0810: try {
0811: // BdD
0812: Campaign camp = (Campaign) ((TestListFamilyCampaignTreeNode) choiceComboBox
0813: .getSelectedItem())
0814: .getCampaignNode()
0815: .getUserObject();
0816: Family pFamilyDown = (Family) nodeToGoDown
0817: .getUserObject();
0818: Family pFamilyUp = (Family) nodeToGoUp
0819: .getUserObject();
0820:
0821: camp.updateTestFamilyOrderInDB(
0822: pFamilyDown.getIdBdd(), true);
0823:
0824: // IHM
0825: for (int k = 0; k < pFamilyUp
0826: .getTestListList().size(); k++) {
0827: TestList testList = (TestList) pFamilyUp
0828: .getTestListList().get(k);
0829: camp.getTestListList().remove(
0830: pFamilyUp.getTestListList()
0831: .get(k));
0832: camp.getTestListList().remove(
0833: pFamilyUp.getTestListList()
0834: .get(k));
0835: for (int j = 0; j < testList
0836: .getTestList().size(); j++) {
0837: camp.getTestList().remove(
0838: testList.getTestList()
0839: .get(j));
0840:
0841: }
0842: }
0843: int addIndex = firstTestIndex;
0844: for (int k = 0; k < pFamilyUp
0845: .getTestListList().size(); k++) {
0846: TestList testList = (TestList) pFamilyUp
0847: .getTestListList().get(k);
0848: camp.getTestListList().add(
0849: (k + firstSuiteIndex),
0850: pFamilyUp.getTestListList()
0851: .get(k));
0852: for (int j = 0; j < testList
0853: .getTestList().size(); j++) {
0854: camp.getTestList().add(
0855: (j + addIndex),
0856: testList.getTestList()
0857: .get(j));
0858: addIndex++;
0859: }
0860: }
0861:
0862: workingModel
0863: .removeNodeFromParent(nodeToGoUp);
0864: workingModel
0865: .insertNodeInto(
0866: nodeToGoUp,
0867: ((TestListFamilyCampaignTreeNode) choiceComboBox
0868: .getSelectedItem())
0869: .getCampaignNode(),
0870: selectedIndex);
0871: campaignFamilyOrderModified.add(camp);
0872: camp.getFamilyList().remove(pFamilyUp);
0873: camp.getFamilyList().add(
0874: (selectedIndex), pFamilyUp);
0875:
0876: } catch (Exception exception) {
0877: exception.printStackTrace();
0878: Tools.ihmExceptionView(exception
0879: .toString());
0880: }
0881:
0882: } else {
0883:
0884: try {
0885: //IHM
0886: ((Family) ((DefaultMutableTreeNode) objToGoDown)
0887: .getUserObject())
0888: .updateOrderInBddAndModel(true);
0889:
0890: //BDD
0891: nodeToGoUp = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) workingModel
0892: .getRoot())
0893: .getChildAt(selectedIndex + 1);
0894: workingModel
0895: .removeNodeFromParent(nodeToGoUp);
0896: workingModel
0897: .insertNodeInto(
0898: nodeToGoUp,
0899: ((DefaultMutableTreeNode) workingModel
0900: .getRoot()),
0901: selectedIndex);
0902: Family family = (Family) nodeToGoUp
0903: .getUserObject();
0904: TestPlanData.getFamilyList().remove(
0905: family);
0906: TestPlanData.getFamilyList().add(
0907: (selectedIndex), family);
0908: familyOrderModified = true;
0909: } catch (Exception exception) {
0910: exception.printStackTrace();
0911: Tools.ihmExceptionView(exception
0912: .toString());
0913: }
0914: }
0915: } else if (testListButton.isSelected()) {
0916: nodeToGoUp = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0917: .getSelectedItem()).getFamilyNode()
0918: .getChildAt(selectedIndex + 1);
0919: nodeToGoDown = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
0920: .getSelectedItem()).getFamilyNode()
0921: .getChildAt(selectedIndex);
0922: if (((TestListFamilyCampaignTreeNode) choiceComboBox
0923: .getSelectedItem()).getCampaignNode() == null) {
0924:
0925: try {
0926: //BDD
0927: Family pFamily = (Family) ((TestListFamilyCampaignTreeNode) choiceComboBox
0928: .getSelectedItem())
0929: .getFamilyNode()
0930: .getUserObject();
0931: ((TestList) nodeToGoDown
0932: .getUserObject())
0933: .updateOrderInBddAndModel(true);
0934:
0935: //IHM
0936: workingModel
0937: .removeNodeFromParent(nodeToGoUp);
0938: workingModel
0939: .insertNodeInto(
0940: nodeToGoUp,
0941: ((TestListFamilyCampaignTreeNode) choiceComboBox
0942: .getSelectedItem())
0943: .getFamilyNode(),
0944: selectedIndex);
0945: familiesTestListOrderModified
0946: .add(((TestListFamilyCampaignTreeNode) choiceComboBox
0947: .getSelectedItem())
0948: .getFamilyNode()
0949: .getUserObject());
0950: pFamily.getTestListList().remove(
0951: nodeToGoUp.getUserObject());
0952: pFamily.getTestListList().add(
0953: (selectedIndex),
0954: nodeToGoUp.getUserObject());
0955: } catch (Exception exception) {
0956: exception.printStackTrace();
0957: Tools.ihmExceptionView(exception
0958: .toString());
0959: }
0960: } else {
0961: ArrayList oldTestList = ((Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0962: .getSelectedItem())
0963: .getCampaignNode()).getUserObject())
0964: .getTestList();
0965: // On r?cup?re l'indice du premier test de la suite qui descend
0966: int firstIndex = oldTestList
0967: .indexOf(((DefaultMutableTreeNode) nodeToGoDown
0968: .getFirstChild())
0969: .getUserObject());
0970: int i = 0;
0971: if (firstIndex != -1) {
0972:
0973: try {
0974: // BdD
0975: Campaign camp = (Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
0976: .getSelectedItem())
0977: .getCampaignNode())
0978: .getUserObject();
0979: TestList pSuiteUp = (TestList) nodeToGoUp
0980: .getUserObject();
0981: camp.updateTestSuiteOrderInDB(
0982: ((TestList) nodeToGoDown
0983: .getUserObject())
0984: .getIdBdd(), true);
0985:
0986: // IHM
0987: for (i = 0; i < pSuiteUp
0988: .getTestList().size(); i++) {
0989: camp.getTestList().remove(
0990: pSuiteUp.getTestList()
0991: .get(i));
0992: }
0993: for (i = 0; i < pSuiteUp
0994: .getTestList().size(); i++) {
0995: camp.getTestList().add(
0996: (i + firstIndex),
0997: pSuiteUp.getTestList()
0998: .get(i));
0999: }
1000: workingModel
1001: .removeNodeFromParent(nodeToGoUp);
1002: workingModel
1003: .insertNodeInto(
1004: nodeToGoUp,
1005: ((TestListFamilyCampaignTreeNode) choiceComboBox
1006: .getSelectedItem())
1007: .getFamilyNode(),
1008: selectedIndex);
1009: campaignFamiliesTestListOrderModified
1010: .add(camp);
1011: camp.getTestListList().remove(
1012: pSuiteUp);
1013: camp.getTestListList().add(
1014: (selectedIndex), pSuiteUp);
1015:
1016: } catch (Exception exception) {
1017: Tools.ihmExceptionView(exception
1018: .toString());
1019: }
1020: }
1021: }
1022: } else if (testButton.isSelected()) {
1023: nodeToGoUp = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
1024: .getSelectedItem()).getTestListNode()
1025: .getChildAt(selectedIndex + 1);
1026: nodeToGoDown = (DefaultMutableTreeNode) ((TestListFamilyCampaignTreeNode) choiceComboBox
1027: .getSelectedItem()).getTestListNode()
1028: .getChildAt(selectedIndex);
1029: if (((TestListFamilyCampaignTreeNode) choiceComboBox
1030: .getSelectedItem()).getCampaignNode() == null) {
1031: try {
1032: //BDD
1033: Test pTestDown = (Test) nodeToGoDown
1034: .getUserObject();
1035: Test pTestUp = (Test) nodeToGoUp
1036: .getUserObject();
1037: TestList pSuite = (TestList) ((TestListFamilyCampaignTreeNode) choiceComboBox
1038: .getSelectedItem())
1039: .getTestListNode()
1040: .getUserObject();
1041: pTestDown
1042: .updateOrderInBddAndModel(true);
1043:
1044: //IHM
1045: workingModel
1046: .removeNodeFromParent(nodeToGoUp);
1047: workingModel
1048: .insertNodeInto(
1049: nodeToGoUp,
1050: ((TestListFamilyCampaignTreeNode) choiceComboBox
1051: .getSelectedItem())
1052: .getTestListNode(),
1053: selectedIndex);
1054: testListTestOrderModified.add(pSuite);
1055: pSuite.getTestList().remove(pTestUp);
1056: pSuite.getTestList().add(
1057: (selectedIndex), pTestUp);
1058:
1059: } catch (Exception exception) {
1060: exception.printStackTrace();
1061: Tools.ihmExceptionView(exception
1062: .toString());
1063: }
1064:
1065: } else {
1066:
1067: try {
1068: // BdD
1069: Campaign camp = (Campaign) (((TestListFamilyCampaignTreeNode) choiceComboBox
1070: .getSelectedItem())
1071: .getCampaignNode())
1072: .getUserObject();
1073: camp.updateTestOrderInDB(
1074: ((Test) nodeToGoDown
1075: .getUserObject())
1076: .getIdBDD(), true);
1077:
1078: // IHM
1079: workingModel
1080: .removeNodeFromParent(nodeToGoUp);
1081: workingModel
1082: .insertNodeInto(
1083: nodeToGoUp,
1084: ((TestListFamilyCampaignTreeNode) choiceComboBox
1085: .getSelectedItem())
1086: .getTestListNode(),
1087: selectedIndex);
1088: campaignFamiliesTestListTestOrderModified
1089: .add(camp);
1090: camp.getTestList().remove(
1091: nodeToGoUp.getUserObject());
1092: camp.getTestList().add((selectedIndex),
1093: nodeToGoUp.getUserObject());
1094:
1095: } catch (Exception exception) {
1096: exception.printStackTrace();
1097: Tools.ihmExceptionView(exception
1098: .toString());
1099: }
1100: }
1101: }
1102: }
1103: }
1104: });
1105:
1106: JPanel buttonSet = new JPanel();
1107: buttonSet.setLayout(new BoxLayout(buttonSet, BoxLayout.Y_AXIS));
1108: buttonSet.add(upButton);
1109: buttonSet.add(Box.createRigidArea(new Dimension(1, 25)));
1110: buttonSet.add(downButton);
1111:
1112: initData(testTreeModel, withCampaign);
1113:
1114: list = new JList(listModel);
1115: list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1116:
1117: list.setSelectedIndex(0);
1118: list.addListSelectionListener(new ListSelectionListener() {
1119: public void valueChanged(ListSelectionEvent e) {
1120: int selectedIndex = list.getSelectedIndex();
1121: if (selectedIndex != -1) {
1122: if (selectedIndex == 0) {
1123: upButton.setEnabled(false);
1124: if (selectedIndex == listModel.getSize() - 1) {
1125: downButton.setEnabled(false);
1126: } else {
1127: downButton.setEnabled(true);
1128: }
1129: } else if (selectedIndex == listModel.getSize() - 1) {
1130: upButton.setEnabled(true);
1131: downButton.setEnabled(false);
1132: } else if (selectedIndex == listModel.getSize()) {
1133: upButton.setEnabled(false);
1134: downButton.setEnabled(false);
1135: } else {
1136: upButton.setEnabled(true);
1137: downButton.setEnabled(true);
1138: }
1139: } else {
1140: upButton.setEnabled(false);
1141: downButton.setEnabled(false);
1142: }
1143: }
1144: });
1145: list.setVisibleRowCount(15);
1146: usersListScrollPane = new JScrollPane(list);
1147:
1148: usersListScrollPane.setBorder(BorderFactory
1149: .createTitledBorder(""));
1150: usersListScrollPane.setPreferredSize(new Dimension(350, 250));
1151: JButton validate = new JButton(Language.getInstance().getText(
1152: "Terminer"));
1153: validate.addActionListener(new ActionListener() {
1154: public void actionPerformed(ActionEvent e) {
1155: TestOrdering.this .dispose();
1156: }
1157: });
1158:
1159: JPanel secondButtonSet = new JPanel();
1160: secondButtonSet.add(validate);
1161:
1162: JPanel center = new JPanel();
1163: center.add(usersListScrollPane);
1164: center.add(buttonSet);
1165:
1166: JPanel page = new JPanel();
1167: page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
1168:
1169: page.add(choicePanel);
1170: page.add(Box.createRigidArea(new Dimension(1, 10)));
1171: page.add(center);
1172: page.add(secondButtonSet);
1173:
1174: Container contentPaneFrame = this .getContentPane();
1175: contentPaneFrame.add(page, BorderLayout.CENTER);
1176:
1177: this .setLocation(400, 200);
1178: this .setTitle(Language.getInstance().getText("Ordonner"));
1179: this .pack();
1180: this .setVisible(true);
1181:
1182: } // Fin du constructeur Ordering/1
1183:
1184: public void initData(TestTreeModel model, boolean withCampaign) {
1185: useCampaign = withCampaign;
1186: listModel = new DefaultListModel();
1187: workingModel = model;
1188: comboModel.removeAllElements();
1189: DefaultMutableTreeNode root = (DefaultMutableTreeNode) workingModel
1190: .getRoot();
1191: if (useCampaign) {
1192: for (int i = 0; i < root.getChildCount(); i++) {
1193: TestListFamilyCampaignTreeNode tlfcampaign = new TestListFamilyCampaignTreeNode();
1194: tlfcampaign
1195: .setCampaignNode((DefaultMutableTreeNode) root
1196: .getChildAt(i));
1197: campaignHashSet.add(tlfcampaign);
1198: for (int j = 0; j < ((DefaultMutableTreeNode) root
1199: .getChildAt(i)).getChildCount(); j++) {
1200: DefaultMutableTreeNode familyNode = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) root
1201: .getChildAt(i)).getChildAt(j);
1202: TestListFamilyCampaignTreeNode tlfamily = new TestListFamilyCampaignTreeNode();
1203: tlfamily
1204: .setCampaignNode((DefaultMutableTreeNode) root
1205: .getChildAt(i));
1206: tlfamily.setFamilyNode(familyNode);
1207: familyHashSet.add(tlfamily);
1208: for (int k = 0; k < familyNode.getChildCount(); k++) {
1209: TestListFamilyCampaignTreeNode tlfList = new TestListFamilyCampaignTreeNode();
1210: tlfList
1211: .setCampaignNode((DefaultMutableTreeNode) root
1212: .getChildAt(i));
1213: tlfList.setFamilyNode(familyNode);
1214: tlfList
1215: .setTestListNode((DefaultMutableTreeNode) familyNode
1216: .getChildAt(k));
1217: testListComboModel.addElement(tlfList);
1218: }
1219: }
1220: }
1221: } else {
1222: for (int i = 0; i < root.getChildCount(); i++) {
1223: for (int j = 0; j < ((DefaultMutableTreeNode) root
1224: .getChildAt(i)).getChildCount(); j++) {
1225: TestListFamilyCampaignTreeNode tlfFamily = new TestListFamilyCampaignTreeNode();
1226: tlfFamily
1227: .setFamilyNode((DefaultMutableTreeNode) root
1228: .getChildAt(i));
1229: familyHashSet.add(tlfFamily);
1230: TestListFamilyCampaignTreeNode tlfList = new TestListFamilyCampaignTreeNode();
1231: tlfList.setFamilyNode((DefaultMutableTreeNode) root
1232: .getChildAt(i));
1233: tlfList
1234: .setTestListNode((DefaultMutableTreeNode) ((DefaultMutableTreeNode) root
1235: .getChildAt(i)).getChildAt(j));
1236: testListComboModel.addElement(tlfList);
1237:
1238: }
1239: }
1240: }
1241:
1242: }
1243:
1244: private boolean containsValue(TestListFamilyCampaignTreeNode tlf) {
1245: //DefaultComboBoxModel box = comboModel;
1246: int size = comboModel.getSize();
1247: for (int i = 0; i < size; i++) {
1248: if (((TestListFamilyCampaignTreeNode) comboModel
1249: .getElementAt(i)).getFamilyNode().equals(
1250: tlf.getFamilyNode())) {
1251: return true;
1252: }
1253: }
1254: return false;
1255: }
1256: } // Fin de la classe Ordering
|