001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.main;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Dimension;
028: import java.awt.GridLayout;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.Iterator;
034: import java.util.Set;
035:
036: import javax.swing.BorderFactory;
037: import javax.swing.JButton;
038: import javax.swing.JOptionPane;
039: import javax.swing.JPanel;
040: import javax.swing.JScrollPane;
041: import javax.swing.JTable;
042: import javax.swing.ListSelectionModel;
043: import javax.swing.event.ListSelectionEvent;
044: import javax.swing.event.ListSelectionListener;
045:
046: import org.objectweb.salome_tmf.api.Api;
047: import org.objectweb.salome_tmf.api.ApiConstants;
048: import org.objectweb.salome_tmf.api.Permission;
049: import org.objectweb.salome_tmf.data.Campaign;
050: import org.objectweb.salome_tmf.data.DataSet;
051: import org.objectweb.salome_tmf.data.Execution;
052: import org.objectweb.salome_tmf.ihm.languages.Language;
053: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
054: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
055: import org.objectweb.salome_tmf.ihm.models.TableSorter;
056: import org.objectweb.salome_tmf.ihm.tools.Tools;
057: import org.objectweb.salome_tmf.plugins.UICompCst;
058:
059: public class DataSetView extends JPanel implements ActionListener {
060:
061: /**
062: *
063: */
064: static JButton addButton;
065:
066: /**
067: *
068: */
069: static JButton deleteButton;
070:
071: /**
072: *
073: */
074: static JButton modifyButton;
075:
076: /**
077: *
078: */
079: static JButton purgeButton;
080:
081: /**
082: *
083: */
084: MyTableModel dataSetTableModel;
085: TableSorter sorter;
086:
087: /**
088: *
089: */
090: JTable dataSetTable;
091:
092: /**
093: * Mod?le de s?lection pour la table des environnements
094: */
095: ListSelectionModel rowSM;
096:
097: /**************************************************************************/
098: /** CONSTRUCTEUR ***/
099: /**************************************************************************/
100:
101: /**
102: * Constructeur de la vue
103: *
104: */
105: public DataSetView() {
106: addButton = new JButton(Language.getInstance().getText(
107: "Ajouter"));
108: deleteButton = new JButton(Language.getInstance().getText(
109: "Supprimer"));
110: modifyButton = new JButton(Language.getInstance().getText(
111: "Modifier"));
112: dataSetTableModel = new MyTableModel();
113: dataSetTable = new JTable();
114: DataModel.setDataSetTableModel(dataSetTableModel);
115:
116: addButton.setToolTipText(Language.getInstance().getText(
117: "Ajouter_un_jeu_de_données"));
118: addButton.addActionListener(this );
119:
120: modifyButton.setToolTipText(Language.getInstance().getText(
121: "Modifier_le_jeu_de_données"));
122: modifyButton.setEnabled(false);
123: modifyButton.addActionListener(this );
124:
125: deleteButton.setToolTipText(Language.getInstance().getText(
126: "Supprimer_un_jeu_de_données"));
127: deleteButton.setEnabled(false);
128: deleteButton.addActionListener(this );
129:
130: purgeButton = new JButton(Language.getInstance().getText(
131: "Purge"));
132: purgeButton.setToolTipText(Language.getInstance().getText(
133: "Supprimer_les_jeux_de_données_non_utilisés"));
134: purgeButton.addActionListener(this );
135:
136: //JPanel allButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
137: JPanel allButtons = new JPanel(new GridLayout(1, 4));
138: allButtons.add(addButton);
139: allButtons.add(modifyButton);
140: allButtons.add(deleteButton);
141: allButtons.add(purgeButton);
142: allButtons.setBorder(BorderFactory.createRaisedBevelBorder());
143:
144: // Mapping entre objets graphiques et constantes
145: SalomeTMFContext.getInstance().addToUIComponentsMap(
146: UICompCst.CAMP_DATASET_BUTTONS_PANEL, allButtons);
147: // Add this component as static component
148: UICompCst.staticUIComps
149: .add(UICompCst.CAMP_DATASET_BUTTONS_PANEL);
150:
151: // La liste des attachements
152:
153: dataSetTableModel.addColumnNameAndColumn(Language.getInstance()
154: .getText("Nom"));
155: dataSetTableModel.addColumnNameAndColumn(Language.getInstance()
156: .getText("Description"));
157:
158: sorter = new TableSorter(dataSetTableModel);
159: dataSetTable.setModel(sorter);
160: sorter.setTableHeader(dataSetTable.getTableHeader());
161:
162: dataSetTable.setPreferredScrollableViewportSize(new Dimension(
163: 600, 200));
164: dataSetTable
165: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
166:
167: // Mapping entre objets graphiques et constantes
168: SalomeTMFContext.getInstance().addToUIComponentsMap(
169: UICompCst.CAMP_DATASETS_TABLE, dataSetTable);
170: // Add this component as static component
171: UICompCst.staticUIComps.add(UICompCst.CAMP_DATASETS_TABLE);
172:
173: JScrollPane tablePane = new JScrollPane(dataSetTable);
174:
175: rowSM = dataSetTable.getSelectionModel();
176: rowSM.addListSelectionListener(new ListSelectionListener() {
177: public void valueChanged(ListSelectionEvent e) {
178: if (e.getValueIsAdjusting())
179: return;
180:
181: int selectedRow = dataSetTable.getSelectedRow();
182: if (selectedRow != -1) {
183: if (Permission.canUpdateCamp()
184: || Permission.canExecutCamp())
185: modifyButton.setEnabled(true);
186: if (Permission.canExecutCamp()
187: || Permission.canExecutCamp())
188: deleteButton.setEnabled(true);
189: } else {
190: deleteButton.setEnabled(false);
191: modifyButton.setEnabled(false);
192: }
193:
194: }
195: });
196:
197: this .setLayout(new BorderLayout());
198: this .add(allButtons, BorderLayout.NORTH);
199: this .add(tablePane, BorderLayout.CENTER);
200: } // Fin du constructeur DataSetView/0
201:
202: /**
203: * Permet d'activer ou non les boutons en fonction des permissions accord?es
204: * ? l'utilisateur
205: */
206: public static void giveAccessToIhmDataSetView() {
207: if (!Permission.canDeleteCamp() && !Permission.canExecutCamp()) {
208: }
209: if (!Permission.canCreateCamp() && !Permission.canExecutCamp()) {
210: addButton.setEnabled(false);
211: }
212: if (!Permission.canUpdateCamp() && !Permission.canExecutCamp()) {
213: modifyButton.setEnabled(false);
214: purgeButton.setEnabled(false);
215: }
216: if (!Permission.canExecutCamp()) {
217: deleteButton.setEnabled(false);
218: purgeButton.setEnabled(false);
219: }
220: } // Fin de la m?thode giveAccessToIhmDataSetView
221:
222: //Action Event
223: public void actionPerformed(ActionEvent evt) {
224: if (evt.getSource().equals(addButton)) {
225: addPerformed();
226: } else if (evt.getSource().equals(modifyButton)) {
227: modifyPerformed();
228: } else if (evt.getSource().equals(deleteButton)) {
229: deletePerformed();
230: } else if (evt.getSource().equals(purgeButton)) {
231: purgePerformed();
232: }
233: }
234:
235: void addPerformed() {
236: AskNewDataSet askNewDataSet = new AskNewDataSet();
237: if (askNewDataSet.getDataSet() != null) {
238: int transNumber = -1;
239: try {
240: DataSet dataSet = askNewDataSet.getDataSet();
241: // BdD
242: transNumber = Api.beginTransaction(11,
243: ApiConstants.INSERT_DATA_SET);
244: //dataSet.add2DB(DataModel.getCurrentCampaign());
245: DataModel.getCurrentCampaign().addDataSetInDBAndModel(
246: dataSet);
247: //dataSet.addToBddAndModel(DataModel.getCurrentCampaign());
248: Set keysSet = dataSet.getParametersHashMapFromModel()
249: .keySet();
250: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
251: String name = (String) iter.next();
252: String value = dataSet
253: .getParameterValueFromModel(name);
254: if (value == null)
255: value = "";
256: //dataSet.addParamValue2DB(value,ProjectData.getCurrentProject().getParameter(name));
257: dataSet.addParamValueToDBAndModel(value, DataModel
258: .getCurrentProject().getParameterFromModel(
259: name));
260: }
261: Api.commitTrans(transNumber);
262: transNumber = -1;
263: // IHM
264: ArrayList data = new ArrayList();
265: data.add(dataSet.getNameFromModel());
266: data.add(dataSet.getDescriptionFromModel());
267: dataSetTableModel.addRow(data);
268: //DataModel.getCurrentCampaign().addDataSet(dataSet);
269:
270: } catch (Exception exception) {
271: Api.forceRollBackTrans(transNumber);
272: Tools.ihmExceptionView(exception);
273: }
274: }
275: }
276:
277: void modifyPerformed() {
278: int selectedRow = dataSetTable.getSelectedRow();
279: if (selectedRow != -1) {
280: //DataSet dataSet = DataModel.getCurrentCampaign().getDataSet((String)dataSetTableModel.getValueAt(selectedRow,0));
281: DataSet dataSet = DataModel.getCurrentCampaign()
282: .getDataSetFromModel(
283: (String) sorter.getValueAt(selectedRow, 0));
284: String oldDataSetName = dataSet.getNameFromModel();
285: String oldDataSetDescription = dataSet
286: .getDescriptionFromModel();
287: HashMap oldParmaHashMap = (HashMap) dataSet
288: .getParametersHashMapFromModel().clone();
289: AskNewDataSet askNewDataSet = new AskNewDataSet(dataSet);
290: if (askNewDataSet.getDataSet() != null) {
291: int transNumber = -1;
292: try {
293: DataSet dataset = askNewDataSet.getDataSet();
294:
295: // BdD
296: transNumber = Api.beginTransaction(11,
297: ApiConstants.UPDATE_DATA_SET);
298: String newName = dataset.getNameFromModel();
299: dataset.updateInModel(oldDataSetName, dataset
300: .getDescriptionFromModel());
301: dataset.updateInDBAndModel(newName, dataset
302: .getDescriptionFromModel());
303:
304: Set keysSet = oldParmaHashMap.keySet();
305: //Set keysSet = askNewDataSet.getDataSet().getParametersHashMapFromModel().keySet();
306: for (Iterator iter = keysSet.iterator(); iter
307: .hasNext();) {
308: String name = (String) iter.next();
309: String value = askNewDataSet.getDataSet()
310: .getParameterValueFromModel(name);
311: if (value == null)
312: value = "";
313: //dataset.updateParamValueInDB(ProjectData.getCurrentProject().getParameter(name), value, "");
314: dataset
315: .updateParamValueInDBAndModel(DataModel
316: .getCurrentProject()
317: .getParameterFromModel(name),
318: value, "");
319: }
320:
321: Api.commitTrans(transNumber);
322: transNumber = -1;
323: // IHM
324: sorter.setValueAt(askNewDataSet.getDataSet()
325: .getNameFromModel(), selectedRow, 0);
326: sorter.setValueAt(askNewDataSet.getDataSet()
327: .getDescriptionFromModel(), selectedRow, 1);
328:
329: } catch (Exception exception) {
330: Api.forceRollBackTrans(transNumber);
331: Tools.ihmExceptionView(exception);
332: dataSet.updateInModel(oldDataSetName,
333: oldDataSetDescription);
334: dataSet
335: .setParametersHashMapInModel(oldParmaHashMap);
336: }
337: }
338: }
339: }
340:
341: void deletePerformed() {
342: int selectedRow = dataSetTable.getSelectedRow();
343: if (selectedRow != -1) {
344: String message = "";
345: String text = "";
346: ArrayList concernedExecutions = DataModel
347: .getCurrentProject().getExecutionsOfDataSetInCamp(
348: DataModel.getCurrentCampaign(),
349: (String) sorter.getValueAt(selectedRow, 0));
350: if (concernedExecutions.size() > 0) {
351: for (int i = 0; i < concernedExecutions.size(); i++) {
352: message = message
353: + "* "
354: + ((Execution) concernedExecutions.get(i))
355: .getCampagneFromModel()
356: .getNameFromModel()
357: + "/"
358: + ((Execution) concernedExecutions.get(i))
359: .getNameFromModel() + "\n";
360: }
361:
362: //text = "Le jeu de donn?es <" + (String)dataSetTableModel.getValueAt(selectedRow,0) + "> est utilis? pour les ex?cutions :\n" + message;
363: text = Language.getInstance().getText(
364: "Le_jeu_de_données_<")
365: + (String) sorter.getValueAt(selectedRow, 0)
366: + Language
367: .getInstance()
368: .getText(
369: ">_est_utilisé_pour_les_exécutions_:\n")
370: + message;
371: text = text
372: + Language
373: .getInstance()
374: .getText(
375: "Sa_supression_entrainera_la_suppression_de_toutes_ces_exécutions.\n");
376: }
377: Object[] options = { Language.getInstance().getText("Oui"),
378: Language.getInstance().getText("Non") };
379: int choice = -1;
380: //int actionCase = -1;
381: choice = JOptionPane
382: .showOptionDialog(
383: DataSetView.this ,
384: //text + "Etes vous s?r de vouloir supprimer le jeu de donn?es <" + (String)dataSetTableModel.getValueAt(selectedRow,0) + "> ?",
385: text
386: + Language
387: .getInstance()
388: .getText(
389: "Etes_vous_sûr_de_vouloir_supprimer_le_jeu_de_données_<")
390: + (String) sorter.getValueAt(
391: selectedRow, 0) + "> ?",
392: Language.getInstance().getText(
393: "Attention_!"),
394: JOptionPane.YES_NO_OPTION,
395: JOptionPane.QUESTION_MESSAGE, null,
396: options, options[1]);
397: if (choice == JOptionPane.YES_OPTION) {
398:
399: try {
400: // BdD
401: DataModel
402: .getCurrentCampaign()
403: .deleteDataSetInDBAndModel(
404: (DataModel.getCurrentCampaign()
405: .getDataSetFromModel((String) dataSetTableModel
406: .getValueAt(
407: selectedRow,
408: 0))));
409:
410: // IHM
411: //DataModel.getCurrentCampaign().removeDataSetInModel((String)sorter.getValueAt(selectedRow,0));
412: dataSetTableModel.removeData(sorter
413: .modelIndex(selectedRow));
414: for (int i = 0; i < concernedExecutions.size(); i++) {
415: Campaign camp = ((Execution) concernedExecutions
416: .get(i)).getCampagneFromModel();
417: //camp.deleteExecutionInModel((Execution)concernedExecutions.get(i));
418: if (DataModel.getCurrentCampaign().equals(camp)) {
419: DataModel
420: .getExecutionTableModel()
421: .removeRow(
422: ((Execution) concernedExecutions
423: .get(i))
424: .getNameFromModel());
425: DataModel.getExecutionResultTableModel()
426: .clearTable();
427: }
428: }
429:
430: } catch (Exception exception) {
431: Tools.ihmExceptionView(exception);
432: }
433: }
434: }
435: }
436:
437: void purgePerformed() {
438: for (int i = DataModel.getCurrentCampaign()
439: .getDataSetListFromModel().size() - 1; i >= 0; i--) {
440: DataSet dataSet = (DataSet) DataModel.getCurrentCampaign()
441: .getDataSetListFromModel().get(i);
442: boolean toBeDeleted = true;
443: for (int j = 0; j < DataModel.getCurrentCampaign()
444: .getExecutionListFromModel().size(); j++) {
445: Execution exec = (Execution) DataModel
446: .getCurrentCampaign()
447: .getExecutionListFromModel().get(j);
448: if (exec.getDataSetFromModel().equals(dataSet))
449: toBeDeleted = false;
450: }
451: if (toBeDeleted) {
452: try {
453: // BdD
454: DataModel.getCurrentCampaign()
455: .deleteDataSetInDBAndModel(dataSet);
456:
457: // IHM
458: //DataModel.getCurrentCampaign().getDataSetListFromModel().remove(i);
459: dataSetTableModel.removeRow(dataSet
460: .getNameFromModel());
461:
462: } catch (Exception exception) {
463: Tools.ihmExceptionView(exception);
464: }
465: }
466:
467: }
468: }
469: } // Fin de la classe DataSetView
|