package com.vgo.movie.ecran;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import com.vgo.movie.data.DatabaseDAO;
import com.vgo.movie.domain.Generique;
import com.vgo.movie.domain.Movie;
import com.vgo.movie.util.Libelle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BulkInsertSelection extends javax.swing.JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private Main localParent;
private JLabel jLabelNomFilm;
private JLabel jLabelLangue;
private JComboBox jComboBoxLangue;
private JButton jButtonPasser;
private JComboBox jComboBoxQualite;
private JComboBox jComboBoxCompression;
private JButton jButtonValider;
private JTextField jTextFieldNumMedia;
private JLabel jLabelQualite;
private JLabel jLabelCompression;
private JComboBox jComboBoxTypeMedia;
private JTextField jTextNomFilm;
private boolean validationEnCours;
private int nbMovieInserted = 0;
/**
* Auto-generated main method to display this JDialog
*/
public BulkInsertSelection(Main parent) {
super(parent);
localParent = parent;
initGUI();
initLibelle();
}
private void initGUI() {
try {
{
getContentPane().setLayout(null);
{
jLabelNomFilm = new JLabel();
getContentPane().add(jLabelNomFilm);
jLabelNomFilm.setBounds(12, 28, 91, 28);
}
{
jTextNomFilm = new JTextField();
getContentPane().add(jTextNomFilm);
jTextNomFilm.setBounds(133, 28, 476, 28);
}
{
ComboBoxModel jComboBoxTypeMediaModel = new DefaultComboBoxModel(
new String[] { });
jComboBoxTypeMedia = new JComboBox();
getContentPane().add(jComboBoxTypeMedia);
jComboBoxTypeMedia.setModel(jComboBoxTypeMediaModel);
jComboBoxTypeMedia.setBounds(20, 193, 138, 28);
jComboBoxTypeMedia.setVisible(false);
remplirListeMedia();
}
{
jLabelLangue = new JLabel();
getContentPane().add(jLabelLangue);
jLabelLangue.setBounds(9, 59, 112, 28);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] {});
jComboBoxLangue = new JComboBox();
getContentPane().add(jComboBoxLangue);
jComboBoxLangue.setModel(jComboBox1Model);
jComboBoxLangue.setBounds(133, 59, 476, 28);
remplirListeLangue();
}
{
jLabelCompression = new JLabel();
getContentPane().add(jLabelCompression);
jLabelCompression.setBounds(8, 91, 112, 28);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] {});
jComboBoxCompression = new JComboBox();
getContentPane().add(jComboBoxCompression);
jComboBoxCompression.setModel(jComboBox1Model);
jComboBoxCompression.setBounds(133, 91, 476, 28);
remplirListeCompression();
}
{
jLabelQualite = new JLabel();
getContentPane().add(jLabelQualite);
jLabelQualite.setBounds(8, 122, 112, 28);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new String[] {});
jComboBoxQualite = new JComboBox();
getContentPane().add(jComboBoxQualite);
jComboBoxQualite.setModel(jComboBox1Model);
jComboBoxQualite.setBounds(133, 122, 476, 28);
remplirListeQualite();
}
{
jTextFieldNumMedia = new JTextField();
getContentPane().add(jTextFieldNumMedia);
jTextFieldNumMedia.setBounds(200, 196, 62, 22);
jTextFieldNumMedia.setVisible(false);
}
{
jButtonValider = new JButton();
getContentPane().add(jButtonValider);
jButtonValider.setBounds(315, 174, 294, 30);
jButtonValider.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButtonValiderActionPerformed(evt);
}
});
}
{
jButtonPasser = new JButton();
getContentPane().add(jButtonPasser);
jButtonPasser.setBounds(12, 174, 294, 30);
jButtonPasser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButtonPasserActionPerformed(evt);
}
});
}
}
this.setSize(631, 257);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initLibelle(){
jLabelNomFilm.setText(Libelle.getLibelle("nomFilm"));
jLabelLangue.setText(Libelle.getLibelle("langue"));
jLabelCompression.setText(Libelle.getLibelle("compression"));
jLabelQualite.setText(Libelle.getLibelle("qualite"));
jButtonValider.setText(Libelle.getLibelle("valideFilm"));
jButtonPasser.setText(Libelle.getLibelle("passerFilm"));
}
private void remplirListeQualite(){
try {
List tmpList = DatabaseDAO.selectAllQualites();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxQualite.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeQualite"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void remplirListeLangue(){
try {
List tmpList = DatabaseDAO.selectAllLangues();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxLangue.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeLangue"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void remplirListeCompression(){
try {
List tmpList = DatabaseDAO.selectAllCompressions();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxCompression.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeCompression"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
private void remplirListeMedia(){
try {
List tmpList = DatabaseDAO.selectAllMedias();
Iterator tmpIterator = tmpList.listIterator();
while(tmpIterator.hasNext()){
jComboBoxTypeMedia.addItem(((Generique)tmpIterator.next()).getCode());
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitialisationListeTypeMedia"),
Libelle.getLibelle("erreur") ,
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
}
public JComboBox getJComboBoxCompression() {
return jComboBoxCompression;
}
public JComboBox getJComboBoxLangue() {
return jComboBoxLangue;
}
public JComboBox getJComboBoxQualite() {
return jComboBoxQualite;
}
public JComboBox getJComboBoxTypeMedia() {
return jComboBoxTypeMedia;
}
public JTextField getJTextNomFilm() {
return jTextNomFilm;
}
public JTextField getJTextFieldNumMedia() {
return jTextFieldNumMedia;
}
private void jButtonValiderActionPerformed(ActionEvent evt) {
nbMovieInserted++;
//Insertion du film en base et dans la liste
Movie tmpMovie = new Movie();
if(jTextNomFilm.getText().trim().equals("")){
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurNomFilmVide") ,
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
else{
tmpMovie.setNom(jTextNomFilm.getText());
tmpMovie.setType((String)jComboBoxTypeMedia.getSelectedItem());
tmpMovie.setLangue((String)jComboBoxLangue.getSelectedItem());
tmpMovie.setCompression((String)jComboBoxCompression.getSelectedItem());
tmpMovie.setQualite((String)jComboBoxQualite.getSelectedItem());
tmpMovie.setIdMedia(new Integer(jTextFieldNumMedia.getText().trim()));
}
/*A ce stade le film peut �tre ajout�*/
try {
DatabaseDAO.insertMovie(tmpMovie);
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInsertionFilms"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
try {
tmpMovie = (Movie)DatabaseDAO.recupDernierFilm();
Object[] data = {new Integer(tmpMovie.getId()),
tmpMovie.getNom(),
tmpMovie.getType(),
new Integer(tmpMovie.getIdMedia()),
tmpMovie.getStatut(),
tmpMovie.getLangue(),
tmpMovie.getCompression(),
tmpMovie.getQualite()};
localParent.getListFilmModel().addRow(data);
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurRecupInfoFilmInsert"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
this.setValidationEnCours(false);
}
private void jButtonPasserActionPerformed(ActionEvent evt) {
this.setValidationEnCours(false);
//tant pis pour celui ci
}
public boolean isValidationEnCours() {
return validationEnCours;
}
public void setValidationEnCours(boolean validationEnCours) {
jButtonValider.setEnabled(validationEnCours);
jButtonPasser.setEnabled(validationEnCours);
this.validationEnCours = validationEnCours;
}
public int getNbMovieInserted() {
return nbMovieInserted;
}
}