Package com.vgo.movie.ecran

Source Code of com.vgo.movie.ecran.GestionGenerique

package com.vgo.movie.ecran;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableColumn;

import com.vgo.movie.data.DatabaseDAO;
import com.vgo.movie.domain.Generique;
import com.vgo.movie.domain.Movie;
import com.vgo.movie.listener.ListeFilmListener;
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 GestionGenerique extends javax.swing.JDialog {
  /**
   *
   */
  private static final long serialVersionUID = 1L;
  private JSplitPane jSplitPane1;
  private JList jListElements;
  private JPanel jPanelDetail;
  private JTextField jTextFieldId;
  private JButton jButtonValider;
  private JTextArea jTextAreaLibelle;
  private JLabel jLabel1;
  private JTextField jTextFieldCode;
  private JLabel jLabelCode;
  private Main localParent;
  private String localType;
  private String ancienCode = null;
  private String nouveauCode = null;

  private RemplacementGenerique fille;

  public GestionGenerique(Main parent, String type) {
    super(parent);
    localParent = parent;
    localType = type;
    initGUI();
    initLibelle();
  }

  private void initGUI() {
    try {
      {
        jSplitPane1 = new JSplitPane();
        getContentPane().add(jSplitPane1, BorderLayout.CENTER);
        {
          ListModel jListTypeMediaModel = new DefaultComboBoxModel(
              new String[] { });
          jListElements = new JList();
          jSplitPane1.add(jListElements, JSplitPane.LEFT);
          jListElements.setModel(jListTypeMediaModel);
          jListElements.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent evt) {
              jListGeneriqueKeyReleased(evt);
            }
          });
          jListElements
          .addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent evt) {
              jListGeneriqueValueChanged(evt);
            }
          });
        }
        {
          jPanelDetail = new JPanel();
          jSplitPane1.add(jPanelDetail, JSplitPane.RIGHT);
          jPanelDetail.setLayout(null);
          jPanelDetail.setPreferredSize(new java.awt.Dimension(546, 217));
          {
            jLabelCode = new JLabel();
            jPanelDetail.add(jLabelCode);
            jLabelCode.setBounds(14, 14, 56, 14);
          }
          {
            jTextFieldCode = new JTextField();
            jPanelDetail.add(getJTextFieldCode());
            jTextFieldCode.setBounds(77, 7, 308, 28);
          }
          {
            jLabel1 = new JLabel();
            jPanelDetail.add(jLabel1);
            jLabel1.setBounds(14, 56, 56, 14);
          }
          {
            jTextAreaLibelle = new JTextArea();
            jPanelDetail.add(getJTextAreaLibelle());
            jTextAreaLibelle.setBounds(77, 49, 308, 77);
            jTextAreaLibelle.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
          }
          {
            jButtonValider = new JButton();
            jPanelDetail.add(jButtonValider);
            jButtonValider.setBounds(210, 161, 154, 28);
            jButtonValider.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                jButtonValiderActionPerformed(evt);
              }
            });
          }
          {
            jTextFieldId = new JTextField();
            jPanelDetail.add(getJTextFieldId());
            jTextFieldId.setBounds(448, 63, 63, 28);
            jTextFieldId.setVisible(false);
          }
        }
        remplirListe();
      }
      this.setSize(564, 248);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void initLibelle() {
    jLabelCode.setText(Libelle.getLibelle("code"));
    jLabel1.setText(Libelle.getLibelle("libelle"));
    jButtonValider.setText(Libelle.getLibelle("bouttonAjouter"));   
  }

  private void remplirListe(){

    try {
      List tmpListIn = null;

      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();
      }       
      LinkedList<String> tmpListOut = new LinkedList<String>();

      Iterator tmpIterator = tmpListIn.listIterator();
      while (tmpIterator.hasNext()){
        tmpListOut.add(((Generique)tmpIterator.next()).getCode())
      }
      tmpListOut.add(new String(Libelle.getLibelle("nouveau")));

      jListElements.removeAll();
      jListElements.setListData(tmpListOut.toArray());     
      jListElements.setSelectedIndex(tmpListOut.size() - 1);
    } catch (SQLException e) {
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("erreurInitListe"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.ERROR_MESSAGE,
          null,
          null,
          null);
    }   
  }   

  public JTextField getJTextFieldCode() {
    return jTextFieldCode;
  }

  public JTextArea getJTextAreaLibelle() {
    return jTextAreaLibelle;
  }

  private void jListGeneriqueValueChanged(ListSelectionEvent evt) {
    if (!evt.getValueIsAdjusting()){
      Generique tmpBean = new Generique();
      tmpBean.setCode((String)jListElements.getSelectedValue());
      try{
        if(localType.equals("typeMedia")){
          tmpBean = (Generique)DatabaseDAO.getDetailTypeMedia(tmpBean);
        }
        if(localType.equals("compression")){
          tmpBean = (Generique)DatabaseDAO.getDetailCompression(tmpBean);
        }       
        if(localType.equals("langue")){
          tmpBean = (Generique)DatabaseDAO.getDetailLangue(tmpBean);
        }
        if(localType.equals("qualite")){
          tmpBean = (Generique)DatabaseDAO.getDetailQualite(tmpBean);
        }           

      } catch (SQLException e) {
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(this),
            Libelle.getLibelle("erreurRecupDetail"),
            Libelle.getLibelle("erreur"),
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            null,
            null);
     
      if(tmpBean == null){
        getJTextFieldCode().setText("");
        getJTextAreaLibelle().setText("");
        getJTextFieldId().setText("");
        getJButtonValider().setText(Libelle.getLibelle("bouttonAjouter"));

      }
      else{
        getJTextFieldCode().setText(tmpBean.getCode());
        getJTextAreaLibelle().setText(tmpBean.getLibelle());
        getJTextFieldId().setText(tmpBean.getId());
        getJButtonValider().setText(Libelle.getLibelle("bouttonModifier"));
      }

    }
  }

  public JButton getJButtonValider() {
    return jButtonValider;
  }

  public JTextField getJTextFieldId() {
    return jTextFieldId;
  }

  private void jButtonValiderActionPerformed(ActionEvent evt) {

    if(getJTextFieldCode().getText().trim().equals("")){
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("erreurCodeVide"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.ERROR_MESSAGE,
          null,
          null,
          null);     
    }
    else{
      Generique tmpBean = new Generique();
      tmpBean.setCode(getJTextFieldCode().getText());
      tmpBean.setLibelle(getJTextAreaLibelle().getText());
      tmpBean.setId(getJTextFieldId().getText());
      try {
        if(tmpBean.getId().trim().equals("")){
          if(localType.equals("typeMedia")){
            DatabaseDAO.insertTypeMedia(tmpBean);
          }
          if(localType.equals("compression")){
            DatabaseDAO.insertCompression(tmpBean);
          }         
          if(localType.equals("langue")){
            DatabaseDAO.insertLangue(tmpBean);
          }     
          if(localType.equals("qualite")){
            DatabaseDAO.insertQualite(tmpBean);
          }               

        }       
        else{
          if(localType.equals("typeMedia")){
            DatabaseDAO.updateTypeMedia(tmpBean);
          }
          if(localType.equals("compression")){
            DatabaseDAO.updateCompression(tmpBean);
          }       
          if(localType.equals("langue")){
            DatabaseDAO.updateLangue(tmpBean);
          }             
          if(localType.equals("qualite")){
            DatabaseDAO.updateQualite(tmpBean);
          }         
        }
        remplirListe();
        if(localType.equals("typeMedia")){
          localParent.remplirListeMedia();   
        }
        if(localType.equals("compression")){
          localParent.remplirListeCompression();   
        }   
        if(localType.equals("langue")){
          localParent.remplirListeLangue();   
        }         
        if(localType.equals("qualite")){
          localParent.remplirListeQualite();   
        }         
        TableColumn tmpColumn = null;
        JComboBox tmpComboBox = null;
        List tmpList = null;
        Iterator tmpIterator = null;

        if(localType.equals("typeMedia")){
          tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneType"));
          tmpList = DatabaseDAO.selectAllMedias()
        }
        if(localType.equals("compression")){
          tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneCompression"));
          tmpList = DatabaseDAO.selectAllCompressions()
        }   
        if(localType.equals("langue")){
          tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneLangue"));
          tmpList = DatabaseDAO.selectAllLangues()
       
        if(localType.equals("qualite")){
          tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneQualite"));
          tmpList = DatabaseDAO.selectAllQualites()
        }         

        tmpComboBox = new JComboBox();
        tmpIterator = tmpList.listIterator();
        while(tmpIterator.hasNext()){
          tmpComboBox.addItem(((Generique)tmpIterator.next()).getCode());
        }
        tmpColumn.setCellEditor(new DefaultCellEditor(tmpComboBox));

      }
      catch (SQLException e) {
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(this),
            Libelle.getLibelle("erreurMiseAJour"),
            Libelle.getLibelle("erreur"),
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            null,
            null);
      }
    }
  }

  private void jListGeneriqueKeyReleased(KeyEvent evt) {
    if(evt.getKeyCode() == 127 ){
      Generique tmpBean = new Generique();
      Movie tmpBeanMovie = new Movie();
      if(!((String)jListElements.getSelectedValue()).trim().toLowerCase().equals("nouveau ...")){
        if(jListElements.getLastVisibleIndex() > 1){
          try {
            tmpBean.setCode((String)jListElements.getSelectedValue());

            if(localType.equals("typeMedia")){
              tmpBeanMovie.setType(tmpBean.getCode());     
              List tmpList = DatabaseDAO.verifierTypeMedia(tmpBeanMovie);
              if(tmpList != null && tmpList.size() > 0){
                fille = new RemplacementGenerique(this,localType,tmpList,tmpBeanMovie, this);
                fille.setVisible(true)
                fille.setAlwaysOnTop(true);
              }
              else{
                DatabaseDAO.deleteTypeMedia(tmpBean)
                this.finSuppression();
              }
            }

            if(localType.equals("compression")){
              tmpBeanMovie.setCompression(tmpBean.getCode());     
              List tmpList = DatabaseDAO.verifierCompression(tmpBeanMovie);
              if(tmpList != null && tmpList.size() > 0){
                fille = new RemplacementGenerique(this,localType,tmpList,tmpBeanMovie, this);
                fille.setVisible(true);
                fille.setAlwaysOnTop(true);
              }
              else{
                DatabaseDAO.deleteCompression(tmpBean)
                this.finSuppression();
              }
            }   

            if(localType.equals("langue")){
              tmpBeanMovie.setLangue(tmpBean.getCode());     
              List tmpList = DatabaseDAO.verifierLangue(tmpBeanMovie);
              if(tmpList != null && tmpList.size() > 0){
                fille = new RemplacementGenerique(this,localType,tmpList,tmpBeanMovie, this);
                fille.setVisible(true);
                fille.setAlwaysOnTop(true);
              }
              else{
                DatabaseDAO.deleteLangue(tmpBean)
                this.finSuppression();
              }
            }         

            if(localType.equals("qualite")){
              tmpBeanMovie.setQualite(tmpBean.getCode());     
              List tmpList = DatabaseDAO.verifierQualite(tmpBeanMovie);
              if(tmpList != null && tmpList.size() > 0){
                fille = new RemplacementGenerique(this,localType,tmpList,tmpBeanMovie, this);
                fille.setVisible(true)
                fille.setAlwaysOnTop(true);
              }
              else{
                DatabaseDAO.deleteQualite(tmpBean)
                this.finSuppression();
              }
            }     

          } catch (SQLException e) {
            JOptionPane.showOptionDialog(
                SwingUtilities.getWindowAncestor(this),
                Libelle.getLibelle("erreurSuppression"),
                Libelle.getLibelle("erreur"),
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.ERROR_MESSAGE,
                null,
                null,
                null);
          }         
        }
        else{
          JOptionPane.showOptionDialog(
              SwingUtilities.getWindowAncestor(this),
              Libelle.getLibelle("erreurReste1Element"),
              Libelle.getLibelle("erreur"),
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.ERROR_MESSAGE,
              null,
              null,
              null);
        }
      }
    }
  }

  private void finSuppression(){
    try {
      remplirListe();

      if(localType.equals("typeMedia")){
        localParent.remplirListeMedia();   
      }
      if(localType.equals("compression")){
        localParent.remplirListeCompression();
      }         
      if(localType.equals("langue")){
        localParent.remplirListeLangue();
      }         
      if(localType.equals("qualite")){
        localParent.remplirListeQualite();
      }           

      TableColumn tmpColumn = null;
      JComboBox tmpComboBox = null;
      List tmpList = null;
      Iterator tmpIterator = null;

      if(localType.equals("typeMedia")){
        tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneType"));         
        tmpList = DatabaseDAO.selectAllMedias();
      }
      if(localType.equals("compression")){
        tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneCompression"));
        tmpList = DatabaseDAO.selectAllCompressions()
      }
      if(localType.equals("langue")){
        tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneLangue"));
        tmpList = DatabaseDAO.selectAllLangues()
     
      if(localType.equals("qualite")){
        tmpColumn = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneQualite"));
        tmpList = DatabaseDAO.selectAllQualites()
      }             

      tmpComboBox = new JComboBox();
      tmpIterator = tmpList.listIterator();
      while(tmpIterator.hasNext()){
        tmpComboBox.addItem(((Generique)tmpIterator.next()).getCode());
      }
      tmpColumn.setCellEditor(new DefaultCellEditor(tmpComboBox));       


    } catch (SQLException e) {
      JOptionPane.showOptionDialog(
          SwingUtilities.getWindowAncestor(this),
          Libelle.getLibelle("erreurSuppression"),
          Libelle.getLibelle("erreur"),
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.ERROR_MESSAGE,
          null,
          null,
          null);
    }
  }

  public void retourFille(){

    if(fille.isMiseAJourOk()){
      Generique tmpBean = null;
      int columnIndex = -1;

      nouveauCode = (String)fille.getJComboBoxGenerique().getSelectedItem();
      tmpBean = new Generique();

      try {
        if(localType.equals("typeMedia")){
          ancienCode = fille.getLocalMovie().getType();
          tmpBean.setCode(ancienCode);
          columnIndex = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneType")).getModelIndex();
          DatabaseDAO.deleteTypeMedia(tmpBean)
        }
        if(localType.equals("compression")){
          ancienCode = fille.getLocalMovie().getCompression();
          tmpBean.setCode(ancienCode)
          columnIndex = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneCompression")).getModelIndex();         
          DatabaseDAO.deleteCompression(tmpBean)
        }
        if(localType.equals("langue")){
          ancienCode = fille.getLocalMovie().getLangue();
          tmpBean.setCode(ancienCode);   
          columnIndex = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneLangue")).getModelIndex();         
          DatabaseDAO.deleteLangue(tmpBean)
       
        if(localType.equals("qualite")){
          ancienCode = fille.getLocalMovie().getQualite();
          tmpBean.setCode(ancienCode);
          columnIndex = localParent.getTableListeFilms().getColumn(Libelle.getLibelle("titreColonneQualite")).getModelIndex();         
          DatabaseDAO.deleteQualite(tmpBean)
        }     
      } catch (SQLException e) {
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(this),
            Libelle.getLibelle("erreurSuppression"),
            Libelle.getLibelle("erreur"),
            JOptionPane.DEFAULT_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            null,
            null);
      }

      //On commence par enlever le listener pour ne pas le perturber
      for (int i=0; i<localParent.getListFilmModel().getTableModelListeners().length;i++){
        TableModelListener tmpListener = localParent.getListFilmModel().getTableModelListeners()[i];
        if(tmpListener.getClass().equals(ListeFilmListener.class)){
          localParent.getListFilmModel().removeTableModelListener(tmpListener);
        }
      }

      int nbLigneTable = localParent.getListFilmModel().getRowCount();
      for (int i=nbLigneTable-1;i>=0;i--){
        if(((String)localParent.getListFilmModel().getValueAt(i, columnIndex)).equals(ancienCode)){
          localParent.getListFilmModel().setValueAt(nouveauCode, i, columnIndex);
        }   
      }     

      localParent.getListFilmModel().addTableModelListener(new ListeFilmListener(localParent));


      this.finSuppression();     
    }

  }

}
TOP

Related Classes of com.vgo.movie.ecran.GestionGenerique

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.