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