Package gui.gestionCompteUser

Source Code of gui.gestionCompteUser.RoleUserEditionFenetre

package gui.gestionCompteUser;

import static gui.MotsCleProjet.CMD_CANCEL;

import static gui.MotsCleProjet.CMD_OK;
import static gui.MotsCleProjet.IsNumString;
import static gui.util.TaxiGuiUtil.FabricationButton;
import gui.*;
import gui.util.ErreurDeValidation;
import gui.util.TaxiGuiUtil;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Vector;

import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;

import modele.compteUser.RoleUser;

/**
* class RoleUserEditionFenetre
* Cr�e une fen�tre qui permet d'ajouter ou de modifier
* un enregistrement
*
* @author Kasandra
*
*/
class RoleUserEditionFenetre implements ActionListener{
 
  private JDialog aDialog;// R�f�rence � la boite de dialogue.
  private static Font titreFont = new Font("Tahoma", 1, 12);

  private JTextControlKey textLibelle; 

  private JLabel labLib, titres;
 
  private JPanel titre = null;
 
  private RoleUser roleUser = new RoleUser();

  protected boolean okFlag;

  public boolean OK_Button() {
    return okFlag;
  }

  /**
   * Cr�e le titre du formulaire
   * @return titre formulaire
   */
  private JPanel getTitre() {
    if (titre == null) {
      GridBagConstraints gridBagTitre = new GridBagConstraints();
      gridBagTitre.gridx = 0;
      gridBagTitre.gridy = 0;
      titres = new JLabel();
      titres.setText("Fiche r�le utilisateur");
      titres.setFont(new java.awt.Font("Comic Sans MS", 1, 20));
      titres.setForeground(new java.awt.Color(255, 255, 255));
      titre = new JPanel();
      titre.setLayout(new GridBagLayout());
      titre.setPreferredSize(new Dimension(50, 45));
      titre.setBackground(new java.awt.Color(66, 79, 120));
      titre.add(titres, gridBagTitre);
    }

    return titre;
  }

  /**
   * Constructeur
   */

  public RoleUserEditionFenetre() {
   
    aDialog = new JDialog(MainWindow.cadrePrincipal(), "R�le utilisateur...", true);

    textLibelle = new JTextControlKey("", 20, IsNumString);
    textLibelle.ChampsTxt.setForeground(new java.awt.Color(66, 79, 120));

    okFlag = false;
  }


  /**
   * Initialise les donn�es
   * @param roleUser
   */
  public void initializeDonnee(RoleUser roleUser) {
   
    this.roleUser = roleUser;
    textLibelle.ChampsTxt.setText(roleUser.getLibelle());
   
  }
 
  /**
   *
   * @return roleUser
   */
  public RoleUser renvoiRoleUser(){
   
    return roleUser;
   
  }
 
  /**
   * Cr�e le panel libell� r�leUser
   * @return le libell�
   */
  private JPanel creeLibelleRoleUserPane(){
   
    JPanel parameterPane = new JPanel(false);

    parameterPane.setBackground(Color.white);
    parameterPane.setLayout(new GridLayout());
    parameterPane.setPreferredSize(new Dimension(400, 25));
    labLib = new JLabel("     R�le utilisateur : *");
    labLib.setFont(titreFont);
    labLib.setForeground(new java.awt.Color(66, 79, 120));
    parameterPane.add(labLib);
    // parameterPane.add(new JLabel("          Libelle:"));
    parameterPane.add(textLibelle.ChampsTxt);
    return parameterPane;
   
  }

  /**
   *D�finit la fen�tre pour ajouter ou modifier un enregistrement
   *
   */
  public void affiche() {
    JToolBar toolBar = new JToolBar("Outils...");

    JPanel parameterPane = new JPanel(false);
    parameterPane.setLayout(new FlowLayout());
    parameterPane.setPreferredSize(new Dimension(500, 200));

    parameterPane.setBorder(javax.swing.BorderFactory.createLineBorder(
        new java.awt.Color(66, 79, 120), 2));

    parameterPane.setBackground(new java.awt.Color(170, 207, 249));

    parameterPane.add(creeLibelleRoleUserPane());

    aDialog.getContentPane().add(getTitre(), BorderLayout.NORTH);
    aDialog.getContentPane().add(parameterPane, BorderLayout.CENTER);
    aDialog.getContentPane().add(toolBar, BorderLayout.PAGE_END);

    toolBar.setBackground(new java.awt.Color(66, 79, 120));
    toolBar.add(FabricationButton("OK", CMD_OK, "OK...", this));
    toolBar
        .add(FabricationButton("ANNULER", CMD_CANCEL, "Annuler...",
            this));

    Point p = MainWindow.cadrePrincipal().getLocation();
    aDialog.setLocation((p.x + 450), (p.y + 200));

    aDialog.pack();
    aDialog.setVisible(true);
  }
 
  /**
   * Gestionnaire des �v�nements
   */
  public void actionPerformed(ActionEvent e) {
   
    try {
      // Restaure la couleur de fonds par d�faut.
      for (JComponent composant : Arrays.asList(textLibelle.ChampsTxt)) {
        composant.setBackground(Color.WHITE);
        composant.setToolTipText("");
      }
     
    String cmd = e.getActionCommand();
   
    if (CMD_OK.equals(cmd)) {

      Vector<ErreurDeValidation> erreursDeValidation = new Vector<ErreurDeValidation>();
     
      if (textLibelle.ChampsTxt.getText().trim().equals("")) {
        erreursDeValidation.add(new ErreurDeValidation(textLibelle.ChampsTxt, "le champ 'r�le user' est obligatoire."));
      }
     
     
      if (!erreursDeValidation.isEmpty()) {
        StringBuffer erreurAffichee = new StringBuffer();
        for (ErreurDeValidation erreurDeValidation : erreursDeValidation) {
          erreurAffichee.append(erreurDeValidation.getMessageErreur());
          erreurAffichee.append("\n");
          erreurDeValidation.getComposant().setBackground(Color.RED);
          erreurDeValidation.getComposant().setToolTipText(erreurDeValidation.getMessageErreur());
        }
        TaxiGuiUtil.MessageBox(MainWindow.desktop(), erreurAffichee.toString(), "ERREUR");
       
        return;
     
      else{
     
      roleUser.setLibelle(textLibelle.ChampsTxt.getText());     
      okFlag = true;
      aDialog.setVisible(false);
     
    }
    }else if (CMD_CANCEL.equals(cmd)) {
     
      okFlag = false;
      aDialog.setVisible(false);
    }
    }catch(Exception ex) {
      TaxiGuiUtil.MessageBox(MainWindow.desktop(), "Erreur syst�me : " + ex.getMessage(), "Erreur syst�me");
    }
  }
}
TOP

Related Classes of gui.gestionCompteUser.RoleUserEditionFenetre

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.