001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.event.ActionEvent;
004: import java.awt.event.ActionListener;
005:
006: import javax.swing.JMenuItem;
007: import javax.swing.JPopupMenu;
008: import javax.swing.JSeparator;
009:
010: import org.objectweb.salome_tmf.api.Api;
011: import org.objectweb.salome_tmf.api.ApiConstants;
012: import org.objectweb.salome_tmf.api.Permission;
013: import org.objectweb.salome_tmf.data.Campaign;
014: import org.objectweb.salome_tmf.data.SimpleData;
015: import org.objectweb.salome_tmf.ihm.languages.Language;
016: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
017: import org.objectweb.salome_tmf.ihm.models.DynamicTree;
018:
019: public class PopupMenuFactory {
020: static JMenuItem importToCampMenuItem = null;
021: static JMenuItem delTestMenuItem = null;
022: static JMenuItem delCampMenuItem = null;
023: static JMenuItem synchronizaMenuItem = null;
024: static JMenuItem reloadCampMenuItem = null;
025: static JMenuItem viewMenuItem = null;
026: static JMenuItem assignMenuItem;
027:
028: static JMenuItem copieMenuItem = null;
029: static JMenuItem collerMenuItem = null;
030:
031: static JMenuItem copieCampMenuItem = null;
032: static JMenuItem collerCampMenuItem = null;
033:
034: static SimpleData toCopie = null;
035: static SimpleData toCampCopie = null;
036:
037: /**
038: * Methode qui cree un menu PopUp pour le clic droit de la souris sur
039: * l'arbre des suites
040: * @return un menu PopUp
041: */
042: public static JPopupMenu createTreePopUpForList() {
043: //Creation du menu PopUp de la table
044: JPopupMenu popup = new JPopupMenu();
045:
046: JMenuItem newFamilyMenuItem = new JMenuItem(Language
047: .getInstance().getText("Nouvelle_famille"));
048: newFamilyMenuItem.addActionListener(new ActionListener() {
049: public void actionPerformed(ActionEvent e) {
050: DataModel.addNewFamily();
051: }
052: });
053: popup.add(newFamilyMenuItem);
054:
055: JMenuItem newListMenuItem = new JMenuItem(Language
056: .getInstance().getText("Nouvelle_suite"));
057: newListMenuItem.addActionListener(new ActionListener() {
058: public void actionPerformed(ActionEvent e) {
059: DataModel.addNewTestList();
060: }
061: });
062: popup.add(newListMenuItem);
063:
064: JMenuItem newTestMenuItem = new JMenuItem(Language
065: .getInstance().getText("Nouveau_test"));
066: newTestMenuItem.addActionListener(new ActionListener() {
067: public void actionPerformed(ActionEvent e) {
068: DataModel.addNewTest();
069: }
070: });
071: popup.add(newTestMenuItem);
072:
073: JMenuItem reloadtMenuItem = new JMenuItem(Language
074: .getInstance().getText("Rafraichir"));
075: reloadtMenuItem.setEnabled(true);
076: reloadtMenuItem.addActionListener(new ActionListener() {
077: public void actionPerformed(ActionEvent e) {
078: DataModel.reloadData();
079:
080: }
081: });
082: //importToCampMenuItem = importMenuItem;
083: popup.add(reloadtMenuItem);
084:
085: delTestMenuItem = new JMenuItem(Language.getInstance().getText(
086: "Supprimer"));
087: delTestMenuItem.addActionListener(new ActionListener() {
088: public void actionPerformed(ActionEvent e) {
089: DataModel.deleteInTestTree();
090: }
091: });
092: popup.add(delTestMenuItem);
093:
094: // V?rification des droits de l'utilisateur
095: if (!Permission.canDeleteTest()) {
096: delTestMenuItem.setEnabled(false);
097: }
098: if (!Permission.canCreateTest()) {
099: newFamilyMenuItem.setEnabled(false);
100: newTestMenuItem.setEnabled(false);
101: newListMenuItem.setEnabled(false);
102: }
103:
104: JSeparator sep = new JSeparator();
105: popup.add(sep);
106:
107: copieMenuItem = new JMenuItem(Language.getInstance().getText(
108: "Copier"));
109: copieMenuItem.addActionListener(new ActionListener() {
110: public void actionPerformed(ActionEvent e) {
111: //DataModel.deleteInTestTree();
112: DynamicTree pDynamicTree = SalomeTMFPanels
113: .getTestDynamicTree();
114: Object fromTree = pDynamicTree.getSelectedNode()
115: .getUserObject();
116: if (fromTree instanceof SimpleData) {
117: toCopie = (SimpleData) fromTree;
118: collerMenuItem.setEnabled(true);
119: } else {
120: toCopie = null;
121: collerMenuItem.setEnabled(false);
122: }
123:
124: }
125: });
126: popup.add(copieMenuItem);
127:
128: collerMenuItem = new JMenuItem(Language.getInstance().getText(
129: "Coller"));
130: collerMenuItem.addActionListener(new ActionListener() {
131: public void actionPerformed(ActionEvent e) {
132: // DataModel.deleteInTestTree();
133: //e.getSource().setCursor(new Cursor(Cursor.WAIT_CURSOR));
134:
135: DynamicTree pDynamicTree = SalomeTMFPanels
136: .getTestDynamicTree();
137: SimpleData from = null;
138: Object fromTree = pDynamicTree.getSelectedNode()
139: .getUserObject();
140: if (fromTree instanceof SimpleData) {
141: from = (SimpleData) fromTree;
142: }
143:
144: collerMenuItem.setEnabled(false);
145: int transcode = -1;
146: try {
147: pDynamicTree.setCursorWait();
148: transcode = Api.beginTransaction(101,
149: ApiConstants.INSERT_TEST);
150: DataModel.makeCopie(toCopie, from);
151: Api.commitTrans(transcode);
152: pDynamicTree.setCursorNormal();
153: } catch (Exception ex) {
154: Api.forceRollBackTrans(transcode);
155: pDynamicTree.setCursorNormal();
156: }
157: toCopie = null;
158:
159: }
160: });
161: collerMenuItem.setEnabled(false);
162: popup.add(collerMenuItem);
163: return popup;
164: } // Fin de la m?thode createTreePopUpForList
165:
166: /**
167: * M?thode qui cr?e un menu PopUp pour le clic droit de la souris sur
168: * l'arbre des campagnes
169: * @return un menu PopUp
170: */
171: public static JPopupMenu createTreePopUpForCampagne() {
172:
173: //Creation du menu PopUp de la table
174: JPopupMenu popup = new JPopupMenu();
175:
176: JMenuItem newMenuItem = new JMenuItem(Language.getInstance()
177: .getText("Nouvelle_campagne"));
178: newMenuItem.addActionListener(new ActionListener() {
179: public void actionPerformed(ActionEvent e) {
180: DataModel.addNewCampagne();
181: }
182: });
183: popup.add(newMenuItem);
184:
185: assignMenuItem = new JMenuItem(Language.getInstance().getText(
186: "Assign_to"));
187: assignMenuItem.addActionListener(new ActionListener() {
188: public void actionPerformed(ActionEvent e) {
189: new AskChooseAssignedUser();
190: }
191: });
192: popup.add(assignMenuItem);
193:
194: copieCampMenuItem = new JMenuItem(Language.getInstance()
195: .getText("Copier")
196: + " " + Language.getInstance().getText("Campagne"));
197: copieCampMenuItem.addActionListener(new ActionListener() {
198: public void actionPerformed(ActionEvent e) {
199: DynamicTree pDynamicTree = SalomeTMFPanels
200: .getCampaignDynamicTree();
201: Object fromTree = pDynamicTree.getSelectedNode()
202: .getUserObject();
203: if (fromTree instanceof Campaign) {
204: toCampCopie = (SimpleData) fromTree;
205: collerCampMenuItem.setEnabled(true);
206: } else {
207: toCampCopie = null;
208: collerCampMenuItem.setEnabled(false);
209: }
210:
211: }
212: });
213: popup.add(copieCampMenuItem);
214:
215: collerCampMenuItem = new JMenuItem(Language.getInstance()
216: .getText("Coller")
217: + " " + Language.getInstance().getText("Campagne"));
218: collerCampMenuItem.addActionListener(new ActionListener() {
219: public void actionPerformed(ActionEvent e) {
220: // DataModel.deleteInTestTree();
221: //e.getSource().setCursor(new Cursor(Cursor.WAIT_CURSOR));
222:
223: DynamicTree pDynamicTree = SalomeTMFPanels
224: .getCampaignDynamicTree();
225: SimpleData fromCamp = null;
226: Object fromTree = pDynamicTree.getSelectedNode()
227: .getUserObject();
228: if (fromTree instanceof Campaign) {
229: fromCamp = (SimpleData) fromTree;
230: }
231:
232: collerCampMenuItem.setEnabled(false);
233: int transcode = -1;
234: try {
235: pDynamicTree.setCursorWait();
236: transcode = Api.beginTransaction(101,
237: ApiConstants.INSERT_CAMPAIGN);
238: DataModel.makeCopie(toCampCopie, fromCamp);
239:
240: Api.commitTrans(transcode);
241: pDynamicTree.setCursorNormal();
242: } catch (Exception ex) {
243: Api.forceRollBackTrans(transcode);
244: pDynamicTree.setCursorNormal();
245: }
246: toCampCopie = null;
247:
248: }
249: });
250: collerCampMenuItem.setEnabled(false);
251: popup.add(collerCampMenuItem);
252:
253: reloadCampMenuItem = new JMenuItem(Language.getInstance()
254: .getText("Rafraichir")
255: + " " + Language.getInstance().getText("Campagne"));
256: reloadCampMenuItem.setEnabled(true);
257: reloadCampMenuItem.addActionListener(new ActionListener() {
258: public void actionPerformed(ActionEvent e) {
259: DataModel.reloadCampaign(false);
260:
261: }
262: });
263: //importToCampMenuItem = importMenuItem;
264: popup.add(reloadCampMenuItem);
265:
266: synchronizaMenuItem = new JMenuItem(Language.getInstance()
267: .getText("Synchroniser_testplan"));
268: synchronizaMenuItem.setEnabled(true);
269: synchronizaMenuItem.addActionListener(new ActionListener() {
270: public void actionPerformed(ActionEvent e) {
271: DataModel.synchronizeCampaign(DataModel
272: .getCurrentCampaign());
273:
274: }
275: });
276: //importToCampMenuItem = importMenuItem;
277: popup.add(synchronizaMenuItem);
278:
279: JMenuItem importMenuItem = new JMenuItem(Language.getInstance()
280: .getText("Importer")
281: + " " + Language.getInstance().getText("Tests"));
282: importMenuItem.setEnabled(false);
283: importMenuItem.addActionListener(new ActionListener() {
284: public void actionPerformed(ActionEvent e) {
285: DataModel.importTestsToCampaign();
286: }
287: });
288: importToCampMenuItem = importMenuItem;
289: popup.add(importMenuItem);
290:
291: delCampMenuItem = new JMenuItem(Language.getInstance().getText(
292: "Supprimer"));
293: delCampMenuItem.addActionListener(new ActionListener() {
294: public void actionPerformed(ActionEvent e) {
295: DataModel.deleteInCampaignTree();
296: }
297: });
298: popup.add(delCampMenuItem);
299:
300: JSeparator jSeparator = new JSeparator();
301: popup.add(jSeparator);
302:
303: viewMenuItem = new JMenuItem(Language.getInstance().getText(
304: "Visualiser"));
305: viewMenuItem.setEnabled(false);
306: viewMenuItem.addActionListener(new ActionListener() {
307: public void actionPerformed(ActionEvent e) {
308: DynamicTree pDynamicTree = SalomeTMFPanels
309: .getCampaignDynamicTree();
310: try {
311: DataModel.view((SimpleData) pDynamicTree
312: .getSelectedNode().getUserObject());
313: } catch (Exception ex) {
314: ex.printStackTrace();
315: }
316: }
317: });
318: popup.add(viewMenuItem);
319:
320: // V?rification des droits
321: if (!Permission.canDeleteCamp()) {
322: delCampMenuItem.setEnabled(false);
323:
324: }
325: if (!Permission.canCreateCamp()) {
326: newMenuItem.setEnabled(false);
327: importMenuItem.setEnabled(false);
328: }
329: if (!Permission.canUpdateCamp()) {
330: assignMenuItem.setEnabled(false);
331: }
332:
333: return popup;
334: } // Fin de la m?thode createTreePopUpForCampagne/0
335:
336: public static JMenuItem getImportToCampMenuItem() {
337: return importToCampMenuItem;
338: }
339:
340: public static JMenuItem getviewMenuItem() {
341: return viewMenuItem;
342: }
343:
344: public static JMenuItem getDelTestMenuItem() {
345: return delTestMenuItem;
346: }
347:
348: public static JMenuItem getDelCampMenuItem() {
349: return delCampMenuItem;
350: }
351:
352: public static JMenuItem getAssignCampMenuItem() {
353: return assignMenuItem;
354: }
355:
356: public static void setRootCampAction(boolean isRoot) {
357: if (isRoot) {
358: importToCampMenuItem.setEnabled(false);
359: delCampMenuItem.setEnabled(false);
360: assignMenuItem.setEnabled(false);
361: synchronizaMenuItem.setEnabled(false);
362: copieCampMenuItem.setEnabled(false);
363: reloadCampMenuItem.setEnabled(false);
364: } else {
365: importToCampMenuItem.setEnabled(true);
366: delCampMenuItem.setEnabled(true);
367: assignMenuItem.setEnabled(true);
368: synchronizaMenuItem.setEnabled(true);
369: copieCampMenuItem.setEnabled(true);
370: reloadCampMenuItem.setEnabled(true);
371: }
372: }
373:
374: }
|