001: package salomeTMF_plug.requirements.ihm;
002:
003: import java.awt.event.ActionEvent;
004: import java.awt.event.ActionListener;
005: import java.util.Vector;
006:
007: import javax.swing.JMenuItem;
008: import javax.swing.JOptionPane;
009: import javax.swing.JPopupMenu;
010: import javax.swing.tree.DefaultMutableTreeNode;
011: import javax.swing.tree.TreePath;
012:
013: import org.objectweb.salome_tmf.api.data.TestWrapper;
014: import org.objectweb.salome_tmf.ihm.languages.Language;
015: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
016:
017: import salomeTMF_plug.requirements.data.ReqFamily;
018: import salomeTMF_plug.requirements.data.ReqLeaf;
019: import salomeTMF_plug.requirements.data.Requirement;
020:
021: public class PopPopTreeMenu extends JPopupMenu {
022:
023: JMenuItem copieMenuItem = null;
024: JMenuItem couperMenuItem = null;
025: JMenuItem collerMenuItem = null;
026:
027: Requirement toCopie = null;
028: boolean couper = false;
029:
030: RequirementTree reqTree;
031:
032: public PopPopTreeMenu(RequirementTree _reqTree) {
033: super ();
034: reqTree = _reqTree;
035:
036: copieMenuItem = new JMenuItem(Language.getInstance().getText(
037: "Copier"));
038: copieMenuItem.addActionListener(new ActionListener() {
039: public void actionPerformed(ActionEvent e) {
040: //DataModel.deleteInTestTree();
041: toCopie = (Requirement) reqTree.getCurrentNode()
042: .getUserObject();
043: collerMenuItem.setEnabled(true);
044:
045: }
046: });
047: add(copieMenuItem);
048:
049: couperMenuItem = new JMenuItem(Language.getInstance().getText(
050: "Couper"));
051: couperMenuItem.addActionListener(new ActionListener() {
052: public void actionPerformed(ActionEvent e) {
053: //DataModel.deleteInTestTree();
054: toCopie = (Requirement) reqTree.getCurrentNode()
055: .getUserObject();
056: collerMenuItem.setEnabled(true);
057: couper = true;
058: }
059: });
060: add(couperMenuItem);
061:
062: collerMenuItem = new JMenuItem(Language.getInstance().getText(
063: "Coller"));
064: collerMenuItem.addActionListener(new ActionListener() {
065: public void actionPerformed(ActionEvent e) {
066: Requirement pDest = (Requirement) reqTree
067: .getCurrentNode().getUserObject();
068: if (pDest instanceof ReqFamily && toCopie != null) {
069:
070: ReqFamily reqDest = (ReqFamily) reqTree
071: .getCurrentNode().getUserObject();
072: Requirement newReq = toCopie.getCopie(reqDest);
073: DefaultMutableTreeNode nodeSource = reqTree
074: .findRequirementFromParent(toCopie);
075: DefaultMutableTreeNode nodeDest = reqTree
076: .findRequirementFromParent(reqDest);
077: /* Garde fou */
078: if (toCopie.getIdBdd() == reqDest.getIdBdd()) {
079: return;
080: }
081:
082: if (couper) {
083: try {
084: //BDD
085: toCopie.updateParentInDBAndModel(reqDest);
086:
087: //IHM
088: reqTree.treeModel
089: .removeNodeFromParent(nodeSource);
090: reqTree.insertNode(nodeDest, nodeSource);
091:
092: reqTree.setSelectionPath(new TreePath(
093: nodeSource.getPath()));
094: } catch (Exception ex) {
095: ex.printStackTrace();
096: }
097: } else {
098:
099: boolean copieLink = false;
100: if (newReq instanceof ReqLeaf) {
101: Object[] options = {
102: org.objectweb.salome_tmf.ihm.languages.Language
103: .getInstance().getText(
104: "Oui"),
105: org.objectweb.salome_tmf.ihm.languages.Language
106: .getInstance().getText(
107: "Non") };
108: int choice = -1;
109:
110: choice = SalomeTMFContext
111: .getInstance()
112: .askQuestion(
113: org.objectweb.salome_tmf.ihm.languages.Language
114: .getInstance()
115: .getText(
116: "Copie_link"),
117: "",
118: JOptionPane.QUESTION_MESSAGE,
119: options);
120:
121: if (choice == JOptionPane.YES_OPTION) {
122: copieLink = true;
123: } else {
124: copieLink = false;
125: }
126: }
127: try {
128: reqDest.pastInDBandModel(newReq, reqDest,
129: true);
130:
131: if (copieLink) {
132: Vector listTestWrapper = ((ReqLeaf) toCopie)
133: .getTestWrapperCoveredFromDB();
134: int size = listTestWrapper.size();
135: for (int i = 0; i < size; i++) {
136: TestWrapper pTestWrapper = (TestWrapper) listTestWrapper
137: .elementAt(i);
138: newReq.addTestCoverInDB(
139: pTestWrapper.getIdBDD(),
140: false);
141: }
142: }
143:
144: //IHM
145: reqTree.addRequirementToReqNodeInTree(
146: newReq, nodeDest, true);
147: //reqTree.deleteRequirementInModelAndDB(toCopie);
148: } catch (Exception ex) {
149: ex.printStackTrace();
150: }
151: }
152: } else {
153: return;
154: }
155:
156: collerMenuItem.setEnabled(false);
157:
158: toCopie = null;
159: couper = false;
160:
161: }
162: });
163: collerMenuItem.setEnabled(false);
164: add(collerMenuItem);
165:
166: } // Fin de la m?thode createTreePopUpForList
167:
168: }
|