1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
| package com.application.ib;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Combo;
import com.mysql.jdbc.Statement;
public class FormView extends ViewPart {
public static final String View_ID = "com.application.ib.FormView";
private FormToolkit toolkit;
private ScrolledForm form;
private Combo comboDevise = null;
protected CoursChange coursChange;
private Statement st;
private ResultSet resultSet;
public FormView() {
// TODO Auto-generated constructor stub
}
@Override
public void createPartControl(final Composite parent) {
toolkit = new FormToolkit(getFormColors(parent.getDisplay()));
form = toolkit.createScrolledForm(parent);
//setté les caractèristiques du form
form.setFont(new Font(null, "Arial",14,SWT.BOLD));
form.setText("Devises : Cours de changes");
toolkit.decorateFormHeading(form.getForm());
GridLayout layout = new GridLayout();
form.getBody().setLayout(layout);
layout.numColumns = 2;
GridData gd = new GridData();
gd.horizontalSpan = 2;
Label labelDevise = new Label(form.getBody(), SWT.NULL);
labelDevise.setText("Devise:");
gd = new GridData();
gd.horizontalSpan = 2;
createDevise();
Label labelDate = new Label(form.getBody(), SWT.NULL);
labelDate.setText("Date:");
final Text textDate = new Text(form.getBody(), SWT.BORDER);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
textDate.setText(dateFormat.format(new Date()));
Label labelValue = new Label(form.getBody(), SWT.NULL);
labelValue.setText("Valeur:");
final Text textValue = new Text(form.getBody(), SWT.BORDER);
Button bValider = new Button(form.getBody(), SWT.BUTTON1);
bValider.setText("Valider");
bValider.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
//labelDevise.setText("button clicked");
}
//événement onClick du bouton valider.
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
try {
Date dateDb = stringToDate(textDate.getText(),"dd/MM/yyyy HH:mm:ss");
System.out.println("Date choisi : "+dateDb);
System.out.println("taux : "+textValue.getText());
coursChange = new CoursChange(comboDevise.getText(), dateDb, Double.parseDouble(textValue.getText()));
}
catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("button clocked" + coursChange);
ConnectBd formCon = new ConnectBd();
String queryInsert = "insert into Ib_appli values('"+coursChange.getdevise()+"','"+coursChange.getDate()+"',"+coursChange.getTaux()+")";
System.out.println("query :"+queryInsert );
try {
formCon.getStatement().executeUpdate(queryInsert);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//insérer dans la BD
//mettre à jour le tableau de TableView
}
});
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
form.setFocus();
}
public FormColors getFormColors(final Display display){
final Color COLOR_START = new Color(null, 128, 128, 128);
final Color COLOR_END = new Color(null, 255, 255, 255);
final Color COLOR_HEADING = new Color(null, 102, 102, 102);
FormColors formColors = new FormColors(display);
//setté les couleurs du gradient
formColors.createColor(IFormColors.H_GRADIENT_START, COLOR_START.getRGB());
formColors.createColor(IFormColors.H_GRADIENT_END, COLOR_END.getRGB());
formColors.createColor(IFormColors.H_BOTTOM_KEYLINE1, COLOR_END.getRGB());
formColors.createColor(IFormColors.H_BOTTOM_KEYLINE2, COLOR_START.getRGB());
//setté la couleur du titre
formColors.createColor(IFormColors.TITLE, COLOR_HEADING.getRGB());
return formColors;
}
public static Date stringToDate(String sDate, String sFormat) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
sdf.setLenient(false);
System.out.println("Date: " + sdf.parse(sDate));
return sdf.parse(sDate);
}
/**
* This method initializes comboDevise
*
*/
private void createDevise() {
comboDevise = new Combo(form.getBody(), SWT.NONE);
comboDevise.add("Euros");
comboDevise.add("USD");
comboDevise.select(0);
}
} |