Package com.ledruide.druidecave.gui

Source Code of com.ledruide.druidecave.gui.VigneronAdd

/**
* Copyright (C) 2007 Julien Revault d'Allonnes
*
* This file is part of DruideCave.
*
* DruideCave is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DruideCave is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DruideCave; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
package com.ledruide.druidecave.gui;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.ledruide.druidecave.business.CombosProxy;
import com.ledruide.druidecave.business.lists.CountryProxy;
import com.ledruide.druidecave.dao.Vigneron;
import com.ledruide.druidecave.dao.VigneronPeer;
import com.ledruide.druidecave.helpers.I18nScreens;
import com.ledruide.druidegui.Stop;
import com.ledruide.druidegui.SwapFrame;
import com.ledruide.druidegui.helpers.Constants;
import com.ledruide.druidegui.helpers.Session;
import com.ledruide.druidegui.helpers.TextTools;
import com.ledruide.druidegui.tools.ComponentTools;
import com.ledruide.druidegui.tools.DruideJPanel;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;


public class VigneronAdd extends DruideJPanel
{
   JLabel labelTitle = new JLabel();
   JButton buttonQuit = new JButton();
   JButton buttonHome = new JButton();
   JLabel labelFirstname = new JLabel();
   JTextField fieldFirstname = new JTextField();
   JLabel labelAddress = new JLabel();
   JTextField fieldAddress = new JTextField();
   JLabel labelCP = new JLabel();
   JTextField fieldCP = new JTextField();
   JLabel labelTown = new JLabel();
   JTextField fieldTown = new JTextField();
   JComboBox comboCountry = new JComboBox();
   JLabel labelWeb = new JLabel();
   JTextField fieldWeb = new JTextField();
   JLabel labelEmail = new JLabel();
   JTextField fieldEmail = new JTextField();
   JLabel image = new JLabel();
   JLabel labelTel = new JLabel();
   JTextField fieldTel = new JTextField();
   JLabel labelFax = new JLabel();
   JTextField fieldFax = new JTextField();
   JButton buttonRegions = new JButton();
   JButton buttonCancel = new JButton();
   JButton buttonFinish = new JButton();
   JLabel labelNote = new JLabel();
   JLabel labelCountry = new JLabel();
   JLabel labelLastname = new JLabel();
   JTextField fieldLastName = new JTextField();
   JTextField fieldNote = new JTextField();

   /**
    * Default constructor
    */
   public VigneronAdd()
   {
      initializePanel();
   }

   public JPanel createPanel()
   {
      JPanel jpanel1 = new JPanel();
      FormLayout formlayout1 = new FormLayout("FILL:10PX:NONE,FILL:75PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:37PX:NONE,FILL:75PX:NONE,FILL:10PX:NONE","CENTER:17PX:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
      CellConstraints cc = new CellConstraints();
      jpanel1.setLayout(formlayout1);

      labelTitle.setFont(new Font("Tahoma",Font.BOLD,11));
      labelTitle.setForeground(new Color(204,0,51));
      labelTitle.setName("labelTitle");
      labelTitle.setText("screen.vigneron.add.title");
      labelTitle.setHorizontalAlignment(JLabel.CENTER);
      jpanel1.add(labelTitle,cc.xywh(3,1,10,2));

      buttonQuit.setActionCommand("Quitter");
      buttonQuit.setFont(new Font("Dialog",Font.BOLD,10));
      buttonQuit.setName("buttonQuit");
      buttonQuit.setOpaque(false);
      buttonQuit.setText("screen.button.quit");
      jpanel1.add(buttonQuit,cc.xy(2,1));

      buttonHome.setActionCommand("Quitter");
      buttonHome.setFont(new Font("Dialog",Font.BOLD,10));
      buttonHome.setName("buttonHome");
      buttonHome.setOpaque(false);
      buttonHome.setText("screen.button.home");
      jpanel1.add(buttonHome,cc.xy(13,1));

      labelFirstname.setName("labelFirstname");
      labelFirstname.setText("screen.vigneron.add.firstname");
      labelFirstname.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelFirstname,cc.xywh(2,4,2,1));

      fieldFirstname.setName("fieldFirstname");
      jpanel1.add(fieldFirstname,cc.xywh(4,4,3,1));

      labelAddress.setName("labelAddress");
      labelAddress.setText("screen.vigneron.add.address");
      labelAddress.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelAddress,cc.xywh(2,6,2,1));

      fieldAddress.setName("fieldAddress");
      jpanel1.add(fieldAddress,cc.xywh(4,6,6,1));

      labelCP.setName("labelCP");
      labelCP.setText("screen.vigneron.add.cp");
      labelCP.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelCP,cc.xywh(10,6,3,1));

      fieldCP.setName("fieldCP");
      jpanel1.add(fieldCP,cc.xy(13,6));

      labelTown.setName("labelTown");
      labelTown.setText("screen.vigneron.add.town");
      labelTown.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelTown,cc.xywh(2,8,2,1));

      fieldTown.setName("fieldTown");
      jpanel1.add(fieldTown,cc.xywh(4,8,4,1));

      comboCountry.setName("comboCountry");
      jpanel1.add(comboCountry,cc.xywh(10,8,4,1));

      labelWeb.setName("labelWeb");
      labelWeb.setText("screen.vigneron.add.web");
      labelWeb.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelWeb,cc.xywh(2,10,2,1));

      fieldWeb.setName("fieldWeb");
      fieldWeb.setSelectionEnd(7);
      fieldWeb.setSelectionStart(7);
      fieldWeb.setText("http://");
      jpanel1.add(fieldWeb,cc.xywh(4,10,6,1));

      labelEmail.setName("labelEmail");
      labelEmail.setText("screen.vigneron.add.email");
      labelEmail.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelEmail,cc.xywh(2,12,2,1));

      fieldEmail.setName("fieldEmail");
      jpanel1.add(fieldEmail,cc.xywh(4,12,6,1));

      image.setIcon(loadImage("img/cave2.png"));
      image.setName("image");
      image.setHorizontalAlignment(JLabel.CENTER);
      jpanel1.add(image,cc.xywh(2,14,8,12));

      labelTel.setName("labelTel");
      labelTel.setText("screen.vigneron.add.tel");
      labelTel.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelTel,cc.xywh(10,10,2,1));

      fieldTel.setName("fieldTel");
      jpanel1.add(fieldTel,cc.xywh(12,10,2,1));

      labelFax.setName("labelFax");
      labelFax.setText("screen.vigneron.add.fax");
      labelFax.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelFax,cc.xywh(10,12,2,1));

      fieldFax.setName("fieldFax");
      jpanel1.add(fieldFax,cc.xywh(12,12,2,1));

      buttonRegions.setActionCommand("Suite...");
      buttonRegions.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonRegions.setName("buttonRegions");
      buttonRegions.setOpaque(false);
      buttonRegions.setText("screen.vigneron.add.button.regions");
      jpanel1.add(buttonRegions,cc.xywh(10,18,4,1));

      buttonCancel.setActionCommand("Annuler");
      buttonCancel.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonCancel.setName("buttonCancel");
      buttonCancel.setOpaque(false);
      buttonCancel.setText("screen.vigneron.add.button.cancel");
      jpanel1.add(buttonCancel,cc.xywh(10,21,4,1));

      buttonFinish.setActionCommand("Annuler");
      buttonFinish.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonFinish.setName("buttonFinish");
      buttonFinish.setOpaque(false);
      buttonFinish.setText("screen.vigneron.add.button.finish");
      jpanel1.add(buttonFinish,cc.xywh(10,24,4,1));

      labelNote.setName("labelNote");
      labelNote.setText("screen.vigneron.add.note");
      labelNote.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelNote,cc.xywh(10,15,2,1));

      labelCountry.setName("labelCountry");
      labelCountry.setText("screen.vigneron.add.country");
      labelCountry.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelCountry,cc.xywh(8,8,2,1));

      labelLastname.setName("labelLastname");
      labelLastname.setText("screen.vigneron.add.lastname");
      labelLastname.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelLastname,cc.xywh(7,4,3,1));

      fieldLastName.setName("fieldLastName");
      jpanel1.add(fieldLastName,cc.xywh(10,4,4,1));

      fieldNote.setName("fieldNote");
      jpanel1.add(fieldNote,cc.xy(12,15));

      addFillComponents(jpanel1,new int[]{ 1,4,5,6,7,8,9,10,11,12,14 },new int[]{ 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 });
      return jpanel1;
   }

   /**
    * Initializer
    */
   protected void initializePanel()
   {
      setLayout(new BorderLayout());
      add(createPanel(), BorderLayout.CENTER);
   }

    /* _____________________________________________________________________
      |                                                                     |
      |             IMPLEMENTATION DES METHODES QUI PERMETTENT              |
      |         DE S'INSERER FACILEMENT DANS L'ARCHITECTURE GLOBALE         |
      |_____________________________________________________________________|
    */
    public void initFirst() throws Exception {
        buttonQuit.addActionListener(this);
        buttonHome.addActionListener(this);
        buttonFinish.addActionListener(this);
        buttonCancel.addActionListener(this);
        buttonRegions.addActionListener(this);
    }

    public void initI18n() {
        buttonQuit.setText(I18nScreens.getInstance().get(buttonQuit.getText()));
        buttonHome.setText(I18nScreens.getInstance().get(buttonHome.getText()));
        buttonCancel.setText(I18nScreens.getInstance().get(buttonCancel.getText()));
        buttonRegions.setText(I18nScreens.getInstance().get(buttonRegions.getText()));
        buttonFinish.setText(I18nScreens.getInstance().get(buttonFinish.getText()));
        labelTitle.setText(I18nScreens.getInstance().get(labelTitle.getText()));
        labelCountry.setText(I18nScreens.getInstance().get(labelCountry.getText()));
        labelFirstname.setText(I18nScreens.getInstance().get(labelFirstname.getText()));
        labelLastname.setText(I18nScreens.getInstance().get(labelLastname.getText()));
        labelAddress.setText(I18nScreens.getInstance().get(labelAddress.getText()));
        labelEmail.setText(I18nScreens.getInstance().get(labelEmail.getText()));
        labelWeb.setText(I18nScreens.getInstance().get(labelWeb.getText()));
        labelTown.setText(I18nScreens.getInstance().get(labelTown.getText()));
        labelCP.setText(I18nScreens.getInstance().get(labelCP.getText()));
        labelFax.setText(I18nScreens.getInstance().get(labelFax.getText()));
        labelTel.setText(I18nScreens.getInstance().get(labelTel.getText()));
        labelNote.setText(I18nScreens.getInstance().get(labelNote.getText()));
    }

    public void initEach() throws Exception {
        rollbackMessages();

        comboCountry.removeAllItems();
        CombosProxy.add(comboCountry, CountryProxy.getKeyValueList(), true);

        // Si l'on revient de la page des ajoutRecoltantsRegions
        String retour = (String) Session.getInstance().getAttribute("RETOUR");
        if (TextTools.isNullOrEmpty(retour)) {
            // Effacer les champs
            fieldLastName.setText(Constants.BLANK);
            fieldFirstname.setText(Constants.BLANK);
            fieldAddress.setText(Constants.BLANK);
            fieldCP.setText(Constants.BLANK);
            fieldTown.setText(Constants.BLANK);
            comboCountry.setSelectedIndex(0);
            fieldWeb.setText(Constants.BLANK);
            fieldNote.setText(Constants.BLANK);
            fieldTel.setText(Constants.BLANK);
            fieldFax.setText(Constants.BLANK);
            fieldEmail.setText(Constants.BLANK);
        }
        else {
            String recoltant_id = (String) Session.getInstance().getAttribute("AJOUT_RECOLTANT_ID");
            Session.getInstance().removeAttribute("AJOUT_RECOLTANT_ID");
            Vigneron recoltant = VigneronPeer.findByPK(recoltant_id);
            fieldLastName.setText(recoltant.getLastname());
            fieldFirstname.setText(recoltant.getFirstname());
            fieldAddress.setText(recoltant.getAddress());
            fieldCP.setText(recoltant.getCp());
            fieldTown.setText(recoltant.getTown());
            ComponentTools.positionnerCombo(comboCountry, recoltant.getCountry_id());
            fieldWeb.setText(recoltant.getWeb());
            fieldNote.setText(recoltant.getNote());
            fieldTel.setText(recoltant.getTel());
            fieldFax.setText(recoltant.getFax());
            fieldEmail.setText(recoltant.getEmail());
        }

    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(buttonQuit)) {
            Stop.close();
        }
        else if (e.getSource().equals(buttonHome)) {
            SwapFrame.getInstance().init(Home.class);
        }
        else if (e.getSource().equals(buttonCancel)) {
            SwapFrame.getInstance().init(Home.class);
        }
        else if (e.getSource().equals(buttonFinish)) {
            rollbackMessages();
            // ici on va enregistrer le r�coltant
            if (enregistrer()) {
                // Ensuite on regarde vers o� il faut repartir
                Class retour = (Class) Session.getInstance().getAttribute("ECRAN_RESERVE");
                if (retour == null) {
                    retour = Home.class;
                }
                SwapFrame.getInstance().init(retour);
            }
            else {
                initMessages();
            }
        }
        else if (e.getSource().equals(buttonRegions)) {
            rollbackMessages();
            // ici on va enregistrer le r�coltant
            if (enregistrer()) {
                SwapFrame.getInstance().init(VigneronAddRegions.class);
            }
            else {
                initMessages();
            }
        }
        else {
            System.out.println("Ce boutton n'existe pas !");
        }
    }

    private boolean enregistrer() {

        // Proc�dons � quelques v�rifications
        // le nom doit �tre renseign�
        if (TextTools.isNullOrEmpty(fieldLastName.getText())) {
            addMessages(fieldLastName, I18nScreens.getInstance().get("screen.vigneron.add.error.name"));
        }
        // le pays doit �tre renseign� KLOUG : surtout pour les tests de messages d'erreurs
        String id_country = ComponentTools.getClefFromCombo(comboCountry);
        if ( id_country == null || Constants.BLANK.equals(id_country.trim()) ) {
            addMessages(comboCountry, I18nScreens.getInstance().get("screen.vigneron.add.error.country"));
        }
        if (hasMessages()) {
            return false;
        }
       
        Vigneron leGars = new Vigneron();
        String recoltant_id = (String) Session.getInstance().getAttribute("AJOUT_RECOLTANT_ID");
        if (!TextTools.isNullOrEmpty(recoltant_id)) {
            leGars.setId(recoltant_id);
        }
        leGars.setAddress(fieldAddress.getText());
        leGars.setEmail(fieldEmail.getText());
        leGars.setCp(fieldCP.getText());
        leGars.setFax(fieldFax.getText());
        leGars.setLastname(fieldLastName.getText());
        leGars.setFirstname(fieldFirstname.getText());
        leGars.setNote(fieldNote.getText());
        leGars.setCountry_id(id_country);
        leGars.setWeb(fieldWeb.getText());
        leGars.setTel(fieldTel.getText());
        leGars.setTown(fieldTown.getText());

        try {
            leGars.save();
            recoltant_id = leGars.getId();
            if (!TextTools.isNullOrEmpty(recoltant_id)) {
                Session.getInstance().setAttribute("AJOUT_RECOLTANT_ID", recoltant_id);
                return true;
            }
        }
        catch (Exception ex) {
            // ERREUR
            ex.printStackTrace();
        }
        return false;
    }

    public int getPanelHeight() {
        return 400;
    }


}
TOP

Related Classes of com.ledruide.druidecave.gui.VigneronAdd

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.