package com.vgo.movie.ecran;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
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.SwingUtilities;
import javax.swing.WindowConstants;
import com.vgo.movie.data.DatabaseDAO;
import com.vgo.movie.domain.Generique;
import com.vgo.movie.domain.GeneriqueRemplacement;
import com.vgo.movie.domain.Movie;
import com.vgo.movie.util.Libelle;
/**
* 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 RemplacementGenerique extends javax.swing.JDialog {
private static final long serialVersionUID = 1L;
private JLabel jLabelRemplacement1;
private JButton jButtonOk;
private JComboBox jComboBoxGenerique;
private JLabel jLabelRemplacement2;
private String localType;
private List localMovies;
private Movie localMovie;
private boolean miseAJourOk=false;
public boolean isMiseAJourOk() {
return miseAJourOk;
}
/**
* Auto-generated main method to display this JDialog
*/
public static void main(String[] args) {
}
public RemplacementGenerique(GestionGenerique frame, String tmpType, List tmpMovies, Movie tmpMovie, GestionGenerique parent) {
super(frame);
localType = tmpType;
localMovies = tmpMovies;
localMovie = tmpMovie;
initGUI();
initLibelle();
initComboBox();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
this.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent evt) {
rootWindowClosed(evt);
}
});
{
jLabelRemplacement1 = new JLabel();
getContentPane().add(jLabelRemplacement1);
jLabelRemplacement1.setText("Des films ont la valeur %1 comme %2, ");
jLabelRemplacement1.setBounds(7, 21, 301, 21);
}
{
jLabelRemplacement2 = new JLabel();
getContentPane().add(jLabelRemplacement2);
jLabelRemplacement2.setText("choisissez une valeur de remplacement :");
jLabelRemplacement2.setBounds(7, 42, 301, 21);
}
{
ComboBoxModel jComboBoxGeneriqueModel = new DefaultComboBoxModel(
new String[] {});
jComboBoxGenerique = new JComboBox();
getContentPane().add(jComboBoxGenerique);
jComboBoxGenerique.setModel(jComboBoxGeneriqueModel);
jComboBoxGenerique.setBounds(14, 77, 273, 28);
}
{
jButtonOk = new JButton();
getContentPane().add(jButtonOk);
jButtonOk.setText("Ok");
jButtonOk.setBounds(98, 126, 112, 28);
jButtonOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButtonOkActionPerformed(evt);
}
});
}
this.setSize(323, 209);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initLibelle(){
if(localType.equals("typeMedia")){
jLabelRemplacement1.setText(Libelle.getLibelle("remplacementLigne1",localMovie.getType(),Libelle.getLibelle("titreColonneType")));
}
if(localType.equals("compression")){
jLabelRemplacement1.setText(Libelle.getLibelle("remplacementLigne1",localMovie.getCompression(),Libelle.getLibelle("titreColonneCompression")));
}
if(localType.equals("langue")){
jLabelRemplacement1.setText(Libelle.getLibelle("remplacementLigne1",localMovie.getLangue(),Libelle.getLibelle("titreColonneLangue")));
}
if(localType.equals("qualite")){
jLabelRemplacement1.setText(Libelle.getLibelle("remplacementLigne1",localMovie.getQualite(),Libelle.getLibelle("titreColonneQualite")));
}
jLabelRemplacement2.setText(Libelle.getLibelle("remplacementLigne2"));
jButtonOk.setText(Libelle.getLibelle("ok"));
}
private void initComboBox(){
List tmpListIn = null;
try{
if(localType.equals("typeMedia")){
tmpListIn = DatabaseDAO.selectAllMedias();
}
if(localType.equals("compression")){
tmpListIn = DatabaseDAO.selectAllCompressions();
}
if(localType.equals("langue")){
tmpListIn = DatabaseDAO.selectAllLangues();
}
if(localType.equals("qualite")){
tmpListIn = DatabaseDAO.selectAllQualites();
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitListe"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
Iterator tmpIterator = tmpListIn.listIterator();
Generique tmpGenerique;
while(tmpIterator.hasNext()){
tmpGenerique = (Generique)tmpIterator.next();
if((localType.equals("typeMedia") && !tmpGenerique.getCode().equals(localMovie.getType()))
||
(localType.equals("compression") && !tmpGenerique.getCode().equals(localMovie.getCompression()))
||
(localType.equals("langue") && !tmpGenerique.getCode().equals(localMovie.getLangue()))
||
(localType.equals("qualite") && !tmpGenerique.getCode().equals(localMovie.getQualite()))
){
jComboBoxGenerique.addItem(tmpGenerique.getCode());
}
}
}
private void jButtonOkActionPerformed(ActionEvent evt) {
GeneriqueRemplacement tmpRemplacement = new GeneriqueRemplacement();
tmpRemplacement.setNouveauCode((String)jComboBoxGenerique.getSelectedItem());
try {
if(localType.equals("typeMedia")){
tmpRemplacement.setAncienCode(localMovie.getType());
DatabaseDAO.updateAllMovieTypes(tmpRemplacement);
}
if(localType.equals("compression")){
tmpRemplacement.setAncienCode(localMovie.getCompression());
DatabaseDAO.updateAllCompressions(tmpRemplacement);
}
if(localType.equals("langue")){
tmpRemplacement.setAncienCode(localMovie.getLangue());
DatabaseDAO.updateAllLangues(tmpRemplacement);
}
if(localType.equals("qualite")){
tmpRemplacement.setAncienCode(localMovie.getQualite());
DatabaseDAO.updateAllQualites(tmpRemplacement);
}
} catch (SQLException e) {
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("erreurInitListe"),
Libelle.getLibelle("erreur"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null,
null,
null);
}
JOptionPane.showOptionDialog(
SwingUtilities.getWindowAncestor(this),
Libelle.getLibelle("filmsMisAJour", new Integer(this.localMovies.size()).toString()),
Libelle.getLibelle("information"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
null,
null);
this.miseAJourOk=true;
this.dispose();
}
private void rootWindowClosed(WindowEvent evt) {
GestionGenerique tmpGestion = (GestionGenerique)SwingUtilities.getWindowAncestor(this);
tmpGestion.retourFille();
}
public JComboBox getJComboBoxGenerique() {
return jComboBoxGenerique;
}
public Movie getLocalMovie() {
return localMovie;
}
public List getLocalMovies() {
return localMovies;
}
}