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.Container;
028: import java.awt.Dimension;
029: import java.awt.FlowLayout;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: import javax.swing.BorderFactory;
034: import javax.swing.JButton;
035: import javax.swing.JDialog;
036: import javax.swing.JPanel;
037: import javax.swing.JScrollPane;
038: import javax.swing.JTable;
039: import javax.swing.ListSelectionModel;
040: import javax.swing.event.ListSelectionEvent;
041: import javax.swing.event.ListSelectionListener;
042:
043: import org.objectweb.salome_tmf.data.Parameter;
044: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
045: import org.objectweb.salome_tmf.ihm.languages.Language;
046: import org.objectweb.salome_tmf.ihm.models.TableSorter;
047:
048: public class ParameterInsertionView extends JDialog implements
049: IHMConstants {
050:
051: /**
052: *
053: */
054: JTable parametersTable;
055:
056: /**
057: * Mod?le de s?lection pour la table des param?tres
058: */
059: ListSelectionModel rowSM;
060:
061: Parameter parameter;
062:
063: JButton okButton;
064:
065: TableSorter sorter;
066:
067: /**************************************************************************/
068: /** CONSTRUCTEUR ***/
069: /**************************************************************************/
070:
071: public ParameterInsertionView() {
072:
073: super (SalomeTMF.ptrFrame, true);
074:
075: parametersTable = new JTable();
076: JButton newParameterButton = new JButton(Language.getInstance()
077: .getText("Nouveau"));
078: newParameterButton.setToolTipText(Language.getInstance()
079: .getText("Ajouter_un_nouveau_paramètre"));
080: newParameterButton.addActionListener(new ActionListener() {
081: public void actionPerformed(ActionEvent e) {
082: ParameterView.addNewParameter(true);
083: }
084: });
085:
086: JButton useParameterButton = new JButton(Language.getInstance()
087: .getText("Utiliser"));
088: useParameterButton.setToolTipText(Language.getInstance()
089: .getText("Utiliser_un_paramètre_existant"));
090: useParameterButton.addActionListener(new ActionListener() {
091: public void actionPerformed(ActionEvent e) {
092: ParameterView.usingParameter();
093: }
094: });
095:
096: sorter = new TableSorter(DataModel.getTestParameterTableModel());
097: parametersTable.setModel(sorter);
098: sorter.setTableHeader(parametersTable.getTableHeader());
099:
100: parametersTable
101: .setPreferredScrollableViewportSize(new Dimension(600,
102: 200));
103: parametersTable
104: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
105: JScrollPane tableScrollPane = new JScrollPane(parametersTable);
106: tableScrollPane.setBorder(BorderFactory.createEmptyBorder(20,
107: 0, 30, 0));
108:
109: okButton = new JButton(Language.getInstance()
110: .getText("Valider"));
111: okButton.setEnabled(false);
112: okButton.addActionListener(new ActionListener() {
113: public void actionPerformed(ActionEvent e) {
114: int selectedRow = parametersTable.getSelectedRow();
115: if (selectedRow != -1) {
116: //parameter = DataModel.getCurrentTest().getParameter((String)DataModel.getTestParameterTableModel().getValueAt(selectedRow, 0));
117: parameter = DataModel.getCurrentTest()
118: .getParameter(
119: (String) sorter.getValueAt(
120: selectedRow, 0));
121: ParameterInsertionView.this .dispose();
122: }
123:
124: }
125: });
126:
127: JButton cancelButton = new JButton(Language.getInstance()
128: .getText("Annuler"));
129: cancelButton.addActionListener(new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: ParameterInsertionView.this .dispose();
132: }
133: });
134:
135: JPanel buttonsPanel = new JPanel(new FlowLayout(
136: FlowLayout.CENTER));
137: buttonsPanel.add(okButton);
138: buttonsPanel.add(cancelButton);
139:
140: JPanel upButtonPanel = new JPanel(new FlowLayout(
141: FlowLayout.CENTER));
142: upButtonPanel.add(newParameterButton);
143: upButtonPanel.add(useParameterButton);
144:
145: JPanel tablePanel = new JPanel(new BorderLayout());
146: tablePanel.add(upButtonPanel, BorderLayout.NORTH);
147: tablePanel.add(tableScrollPane, BorderLayout.CENTER);
148:
149: rowSM = parametersTable.getSelectionModel();
150: rowSM.addListSelectionListener(new ListSelectionListener() {
151: public void valueChanged(ListSelectionEvent e) {
152: if (e.getValueIsAdjusting())
153: return;
154:
155: int selectedRow = parametersTable.getSelectedRow();
156: if (selectedRow != -1) {
157: okButton.setEnabled(true);
158: } else {
159: okButton.setEnabled(false);
160: }
161: }
162: });
163:
164: Container contentPaneFrame = this .getContentPane();
165: contentPaneFrame.add(tablePanel, BorderLayout.CENTER);
166: contentPaneFrame.add(buttonsPanel, BorderLayout.SOUTH);
167:
168: // initData();
169:
170: this .setLocation(350, 200);
171: this .setTitle(Language.getInstance().getText(
172: "Ajouter_un_paramètre"));
173: this .pack();
174: this .setVisible(true);
175: } // Fin du constructeur ParameterInsertionView/0
176:
177: /**
178: *
179: *
180: */
181: /*private void initData() {
182: for (int i = 0; i < DataModel.getCurrentTest().getParameterList().size(); i++) {
183: DataModel.getTestParameterTableModel().addValueAt(((Parameter)DataModel.getCurrentTest().getParameterList().get(i)).getName(), i ,0);
184: DataModel.getTestParameterTableModel().addValueAt(((Parameter)DataModel.getCurrentTest().getParameterList().get(i)).getDescription(), i ,1);
185: }
186: } // Fin de la m?thode initData/0
187: */
188: public Parameter getParameter() {
189: return parameter;
190: }
191: } // Fin de la m?thode ParameterInsertionView
|