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;
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.api2ihm.AdminProject;
048: import org.objectweb.salome_tmf.data.Campaign;
049: import org.objectweb.salome_tmf.data.CampaignData;
050: import org.objectweb.salome_tmf.data.DataSet;
051: import org.objectweb.salome_tmf.data.Execution;
052: import org.objectweb.salome_tmf.data.ProjectData;
053: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
054: import org.objectweb.salome_tmf.ihm.languages.Language;
055: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
056: import org.objectweb.salome_tmf.ihm.models.TableSorter;
057: import org.objectweb.salome_tmf.ihm.tools.Tools;
058:
059: public class DataSetView extends JPanel {
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(new ActionListener() {
119: public void actionPerformed(ActionEvent e) {
120:
121: AskNewDataSet askNewDataSet = new AskNewDataSet();
122: if (askNewDataSet.getDataSet() != null) {
123: int transNumber = -1;
124: try {
125: DataSet dataSet = askNewDataSet.getDataSet();
126: // BdD
127: transNumber = Api
128: .beginTransaction(Api.INSERT_DATA_SET);
129: //dataSet.add2DB(DataModel.getCurrentCampaign());
130: dataSet.addToBddAndModel(DataModel
131: .getCurrentCampaign());
132: Set keysSet = dataSet.getParametersHashMap()
133: .keySet();
134: for (Iterator iter = keysSet.iterator(); iter
135: .hasNext();) {
136: String name = (String) iter.next();
137: String value = dataSet.getValue(name);
138: if (value == null)
139: value = "";
140: //dataSet.addParamValue2DB(value,ProjectData.getCurrentProject().getParameter(name));
141: dataSet.addParamValueToBddAndModel(value,
142: ProjectData.getCurrentProject()
143: .getParameter(name));
144: }
145: Api.commitTrans(transNumber);
146:
147: // IHM
148: ArrayList data = new ArrayList();
149: data.add(dataSet.getName());
150: data.add(dataSet.getDescription());
151: dataSetTableModel.addRow(data);
152: //DataModel.getCurrentCampaign().addDataSet(dataSet);
153:
154: } catch (Exception exception) {
155: Api.forceRollBackTrans(transNumber);
156: Tools.ihmExceptionView(exception.toString());
157: }
158: }
159: }
160: });
161:
162: modifyButton.setToolTipText(Language.getInstance().getText(
163: "Modifier_le_jeu_de_données"));
164: modifyButton.setEnabled(false);
165: modifyButton.addActionListener(new ActionListener() {
166: public void actionPerformed(ActionEvent e) {
167: int selectedRow = dataSetTable.getSelectedRow();
168: if (selectedRow != -1) {
169: //DataSet dataSet = DataModel.getCurrentCampaign().getDataSet((String)dataSetTableModel.getValueAt(selectedRow,0));
170: DataSet dataSet = DataModel.getCurrentCampaign()
171: .getDataSet(
172: (String) sorter.getValueAt(
173: selectedRow, 0));
174: String oldDataSetName = dataSet.getName();
175: String oldDataSetDescription = dataSet
176: .getDescription();
177: HashMap oldParmaHashMap = (HashMap) dataSet
178: .getParametersHashMap().clone();
179: AskNewDataSet askNewDataSet = new AskNewDataSet(
180: dataSet);
181: if (askNewDataSet.getDataSet() != null) {
182: int transNumber = -1;
183: try {
184: DataSet dataset = askNewDataSet
185: .getDataSet();
186:
187: // BdD
188: transNumber = Api
189: .beginTransaction(Api.UPDATE_DATA_SET);
190:
191: dataset.updateInBddAndModel(dataset
192: .getName(), dataset
193: .getDescription());
194: Set keysSet = askNewDataSet.getDataSet()
195: .getParametersHashMap().keySet();
196: for (Iterator iter = keysSet.iterator(); iter
197: .hasNext();) {
198: String name = (String) iter.next();
199: String value = askNewDataSet
200: .getDataSet().getValue(name);
201: if (value == null)
202: value = "";
203: //dataset.updateParamValueInDB(ProjectData.getCurrentProject().getParameter(name), value, "");
204: dataset.updateParamValueInBddAndModel(
205: ProjectData.getCurrentProject()
206: .getParameter(name),
207: value, "");
208: }
209:
210: Api.commitTrans(transNumber);
211:
212: // IHM
213: sorter.setValueAt(askNewDataSet
214: .getDataSet().getName(),
215: selectedRow, 0);
216: sorter.setValueAt(askNewDataSet
217: .getDataSet().getDescription(),
218: selectedRow, 1);
219:
220: } catch (Exception exception) {
221: Api.forceRollBackTrans(transNumber);
222: Tools
223: .ihmExceptionView(exception
224: .toString());
225: dataSet
226: .setDescription(oldDataSetDescription);
227: dataSet.setName(oldDataSetName);
228: dataSet
229: .setParametersHashMap(oldParmaHashMap);
230: }
231: }
232: }
233: }
234: });
235:
236: deleteButton.setToolTipText(Language.getInstance().getText(
237: "Supprimer_un_jeu_de_données"));
238: deleteButton.setEnabled(false);
239: deleteButton.addActionListener(new ActionListener() {
240: public void actionPerformed(ActionEvent e) {
241: int selectedRow = dataSetTable.getSelectedRow();
242: if (selectedRow != -1) {
243: String message = "";
244: String text = "";
245: ArrayList concernedExecutions = CampaignData
246: .getExecutionsOfDataSetInCamp(DataModel
247: .getCurrentCampaign(),
248: (String) sorter.getValueAt(
249: selectedRow, 0));
250: if (concernedExecutions.size() > 0) {
251: for (int i = 0; i < concernedExecutions.size(); i++) {
252: message = message
253: + "* "
254: + ((Execution) concernedExecutions
255: .get(i)).getCampagne()
256: .getName()
257: + "/"
258: + ((Execution) concernedExecutions
259: .get(i)).getName() + "\n";
260: }
261:
262: //text = "Le jeu de donn?es <" + (String)dataSetTableModel.getValueAt(selectedRow,0) + "> est utilis? pour les ex?cutions :\n" + message;
263: text = Language.getInstance().getText(
264: "Le_jeu_de_données_<")
265: + (String) sorter.getValueAt(
266: selectedRow, 0)
267: + Language
268: .getInstance()
269: .getText(
270: ">_est_utilisé_pour_les_exécutions_:\n")
271: + message;
272: text = text
273: + Language
274: .getInstance()
275: .getText(
276: "Sa_supression_entrainera_la_suppression_de_toutes_ces_exécutions.\n");
277: }
278: Object[] options = {
279: Language.getInstance().getText("Oui"),
280: Language.getInstance().getText("Non") };
281: int choice = -1;
282: //int actionCase = -1;
283: choice = JOptionPane
284: .showOptionDialog(
285: DataSetView.this ,
286: //text + "Etes vous s?r de vouloir supprimer le jeu de donn?es <" + (String)dataSetTableModel.getValueAt(selectedRow,0) + "> ?",
287: text
288: + Language
289: .getInstance()
290: .getText(
291: "Etes_vous_sûr_de_vouloir_supprimer_le_jeu_de_données_<")
292: + (String) sorter
293: .getValueAt(
294: selectedRow,
295: 0) + "> ?",
296: Language.getInstance().getText(
297: "Attention_!"),
298: JOptionPane.YES_NO_OPTION,
299: JOptionPane.QUESTION_MESSAGE, null,
300: options, options[1]);
301: if (choice == JOptionPane.YES_OPTION) {
302:
303: try {
304: // BdD
305: DataModel
306: .getCurrentCampaign()
307: .deleteDatasetFromCampInDB(
308: (DataModel
309: .getCurrentCampaign()
310: .getDataSet((String) dataSetTableModel
311: .getValueAt(
312: selectedRow,
313: 0)))
314: .getIdBdd());
315:
316: // IHM
317: DataModel.getCurrentCampaign()
318: .removeDataSet(
319: (String) sorter.getValueAt(
320: selectedRow, 0));
321: dataSetTableModel.removeData(sorter
322: .modelIndex(selectedRow));
323: for (int i = 0; i < concernedExecutions
324: .size(); i++) {
325: Campaign camp = ((Execution) concernedExecutions
326: .get(i)).getCampagne();
327: camp
328: .removeExecution((Execution) concernedExecutions
329: .get(i));
330: if (DataModel.getCurrentCampaign()
331: .equals(camp)) {
332: DataModel
333: .getExecutionTableModel()
334: .removeRow(
335: ((Execution) concernedExecutions
336: .get(i))
337: .getName());
338: DataModel
339: .getExecutionResultTableModel()
340: .clearTable();
341: }
342: }
343:
344: } catch (Exception exception) {
345: Tools
346: .ihmExceptionView(exception
347: .toString());
348: }
349: }
350: }
351: }
352: });
353:
354: purgeButton = new JButton(Language.getInstance().getText(
355: "Purge"));
356: purgeButton.setToolTipText(Language.getInstance().getText(
357: "Supprimer_les_jeux_de_données_non_utilisés"));
358: purgeButton.addActionListener(new ActionListener() {
359: public void actionPerformed(ActionEvent e) {
360: for (int i = DataModel.getCurrentCampaign()
361: .getDataSetList().size() - 1; i >= 0; i--) {
362: DataSet dataSet = (DataSet) DataModel
363: .getCurrentCampaign().getDataSetList().get(
364: i);
365: boolean toBeDeleted = true;
366: for (int j = 0; j < DataModel.getCurrentCampaign()
367: .getExecutionList().size(); j++) {
368: Execution exec = (Execution) DataModel
369: .getCurrentCampaign()
370: .getExecutionList().get(j);
371: if (exec.getDataSet().equals(dataSet))
372: toBeDeleted = false;
373: }
374: if (toBeDeleted) {
375: try {
376: // BdD
377: DataModel.getCurrentCampaign()
378: .deleteDatasetFromCampInDB(
379: dataSet.getIdBdd());
380:
381: // IHM
382: DataModel.getCurrentCampaign()
383: .getDataSetList().remove(i);
384: dataSetTableModel.removeRow(dataSet
385: .getName());
386:
387: } catch (Exception exception) {
388: Tools
389: .ihmExceptionView(exception
390: .toString());
391: }
392: }
393:
394: }
395:
396: }
397: });
398:
399: //JPanel allButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
400: JPanel allButtons = new JPanel(new GridLayout(1, 4));
401: allButtons.add(addButton);
402: allButtons.add(modifyButton);
403: allButtons.add(deleteButton);
404: allButtons.add(purgeButton);
405: allButtons.setBorder(BorderFactory.createRaisedBevelBorder());
406:
407: // Mapping entre objets graphiques et constantes
408: SalomeTMF.addToUIComponentsMap(
409: UICompCst.CAMP_DATASET_BUTTONS_PANEL, allButtons);
410: // Add this component as static component
411: UICompCst.staticUIComps
412: .add(UICompCst.CAMP_DATASET_BUTTONS_PANEL);
413:
414: // La liste des attachements
415:
416: dataSetTableModel.addColumnNameAndColumn(Language.getInstance()
417: .getText("Nom"));
418: dataSetTableModel.addColumnNameAndColumn(Language.getInstance()
419: .getText("Description"));
420:
421: sorter = new TableSorter(dataSetTableModel);
422: dataSetTable.setModel(sorter);
423: sorter.setTableHeader(dataSetTable.getTableHeader());
424:
425: dataSetTable.setPreferredScrollableViewportSize(new Dimension(
426: 600, 200));
427: dataSetTable
428: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
429:
430: // Mapping entre objets graphiques et constantes
431: SalomeTMF.addToUIComponentsMap(UICompCst.CAMP_DATASETS_TABLE,
432: dataSetTable);
433: // Add this component as static component
434: UICompCst.staticUIComps.add(UICompCst.CAMP_DATASETS_TABLE);
435:
436: JScrollPane tablePane = new JScrollPane(dataSetTable);
437:
438: rowSM = dataSetTable.getSelectionModel();
439: rowSM.addListSelectionListener(new ListSelectionListener() {
440: public void valueChanged(ListSelectionEvent e) {
441: if (e.getValueIsAdjusting())
442: return;
443:
444: int selectedRow = dataSetTable.getSelectedRow();
445: if (selectedRow != -1) {
446: if (AdminProject.canUpdateCamp()
447: || AdminProject.canExecutCamp())
448: modifyButton.setEnabled(true);
449: if (AdminProject.canExecutCamp()
450: || AdminProject.canExecutCamp())
451: deleteButton.setEnabled(true);
452: } else {
453: deleteButton.setEnabled(false);
454: modifyButton.setEnabled(false);
455: }
456:
457: }
458: });
459:
460: this .setLayout(new BorderLayout());
461: this .add(allButtons, BorderLayout.NORTH);
462: this .add(tablePane, BorderLayout.CENTER);
463: } // Fin du constructeur DataSetView/0
464:
465: /**
466: * Permet d'activer ou non les boutons en fonction des permissions accord?es
467: * ? l'utilisateur
468: */
469: public static void giveAccessToIhmDataSetView() {
470: if (!AdminProject.canDeleteCamp()
471: && !AdminProject.canExecutCamp()) {
472: }
473: if (!AdminProject.canCreateCamp()
474: && !AdminProject.canExecutCamp()) {
475: addButton.setEnabled(false);
476: }
477: if (!AdminProject.canUpdateCamp()
478: && !AdminProject.canExecutCamp()) {
479: modifyButton.setEnabled(false);
480: purgeButton.setEnabled(false);
481: }
482: if (!AdminProject.canExecutCamp()) {
483: deleteButton.setEnabled(false);
484: purgeButton.setEnabled(false);
485: }
486: } // Fin de la m?thode giveAccessToIhmDataSetView
487:
488: } // Fin de la classe DataSetView
|