001: /*
002: * Created on Jul 29, 2005
003: *
004: * TODO To change the template for this generated file go to
005: * Window - Preferences - Java - Code Style - Code Templates
006: */
007: package salomeTMF_plug.weighting;
008:
009: import java.awt.BorderLayout;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.Dimension;
013: import java.awt.event.ActionEvent;
014: import java.awt.event.ActionListener;
015: import java.sql.PreparedStatement;
016: import java.sql.SQLException;
017: import java.util.Properties;
018:
019: import javax.swing.BorderFactory;
020: import javax.swing.Box;
021: import javax.swing.BoxLayout;
022: import javax.swing.JButton;
023: import javax.swing.JComboBox;
024: import javax.swing.JDialog;
025: import javax.swing.JLabel;
026: import javax.swing.JPanel;
027:
028: import org.objectweb.salome_tmf.api.Api;
029: import org.objectweb.salome_tmf.api.api2db.DataSet;
030: import org.objectweb.salome_tmf.data.Test;
031: import org.objectweb.salome_tmf.ihm.SalomeTMF;
032:
033: import salomeTMF_plug.weighting.languages.Language;
034:
035: /**
036: * @author capg2710
037: *
038: * TODO To change the template for this generated type comment go to
039: * Window - Preferences - Java - Code Style - Code Templates
040: */
041: public class modifyTestWeight extends JDialog {
042:
043: Properties stmts = null;
044: Test test = null;
045: JComboBox weigntList = null;
046:
047: public modifyTestWeight(Test test, Properties stmts) {
048:
049: super (SalomeTMF.ptrFrame, true);
050:
051: this .stmts = stmts;
052: this .test = test;
053:
054: weigntList = new JComboBox();
055:
056: weigntList.addItem(Language.getInstance().getText("faible"));
057: weigntList.addItem(Language.getInstance().getText("moyen"));
058: weigntList.addItem(Language.getInstance().getText("élevé"));
059:
060: try {
061: // On execute la requete
062: PreparedStatement prep = Api.DB.prepareStatement(stmts
063: .getProperty("SelectTestWeight"));
064: prep.setInt(1, test.getIdBDD());
065: DataSet stmtRes = new DataSet(prep.executeQuery());
066: // Ajoute les element un par un au resultat
067: if (stmtRes.hasMoreElements()) {
068: weigntList.setSelectedItem(stmtRes.getResults()
069: .getString("champs1"));
070: }
071: } catch (SQLException e) {
072: e.printStackTrace();
073: org.objectweb.salome_tmf.api.Api.addException(
074: "SelectTestWeight", null, e);
075: } catch (Exception ex) {
076: ex.printStackTrace();
077: org.objectweb.salome_tmf.api.Api.addException(null, null,
078: ex);
079: }
080:
081: JPanel page = new JPanel();
082:
083: JLabel text = new JLabel(Language.getInstance().getText(
084: "Poids_du_test:_"));
085:
086: JPanel giveName = new JPanel();
087:
088: giveName.setLayout(new BoxLayout(giveName, BoxLayout.X_AXIS));
089: giveName.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
090: 10));
091: giveName.add(Box.createHorizontalGlue());
092: giveName.add(text);
093: giveName.add(Box.createRigidArea(new Dimension(10, 0)));
094: giveName.add(weigntList);
095:
096: JPanel textPanel = new JPanel();
097: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
098: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
099: textPanel.add(giveName);
100: text.setAlignmentX(Component.LEFT_ALIGNMENT);
101:
102: JButton okButton = new JButton(Language.getInstance().getText(
103: "Valider"));
104: okButton.setToolTipText(Language.getInstance().getText(
105: "Valider"));
106: okButton.addActionListener(new ActionListener() {
107: public void actionPerformed(ActionEvent e) {
108: int _num = -1;
109: try {
110: _num = org.objectweb.salome_tmf.api.Api
111: .beginTrans();
112:
113: // Mise a jour de la suite de test
114: PreparedStatement prep = Api.DB
115: .prepareStatement(modifyTestWeight.this .stmts
116: .getProperty("UpdateTestWeight"));
117: prep.setString(1, (String) weigntList
118: .getSelectedItem());
119: prep.setInt(2, modifyTestWeight.this .test
120: .getIdBDD());
121: prep.executeUpdate();
122:
123: } catch (SQLException E) {
124: E.printStackTrace();
125: org.objectweb.salome_tmf.api.Api.addException(
126: "updateFamily", null, E);
127: } catch (Exception ex) {
128: ex.printStackTrace();
129: org.objectweb.salome_tmf.api.Api.addException(null,
130: null, ex);
131: }
132: org.objectweb.salome_tmf.api.Api.commitTrans(_num);
133:
134: modifyTestWeight.this .dispose();
135: }
136: });
137:
138: JButton cancelButton = new JButton(Language.getInstance()
139: .getText("Annuler"));
140: cancelButton.setToolTipText(Language.getInstance().getText(
141: "Annuler"));
142: cancelButton.addActionListener(new ActionListener() {
143: public void actionPerformed(ActionEvent e) {
144: modifyTestWeight.this .dispose();
145: }
146: });
147:
148: JPanel buttonPanel = new JPanel();
149: buttonPanel.setLayout(new BorderLayout());
150: buttonPanel.add(okButton, BorderLayout.NORTH);
151: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
152:
153: page.add(textPanel, BorderLayout.WEST);
154: page.add(Box.createRigidArea(new Dimension(40, 10)),
155: BorderLayout.CENTER);
156: page.add(buttonPanel, BorderLayout.EAST);
157:
158: Container contentPaneFrame = this .getContentPane();
159: contentPaneFrame.add(page, BorderLayout.CENTER);
160:
161: this .setLocation(400, 300);
162: this .setTitle(Language.getInstance().getText(
163: "Modifier_le_poids_du_test:_")
164: + test.getName());
165: this .pack();
166: this .setVisible(true);
167: }
168:
169: }
|