Package com.ledruide.druidecave.gui

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

/**
* 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.VigneronProxy;
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.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 VigneronDetail 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 buttonFinish = new JButton();
   JLabel labelNote = new JLabel();
   JLabel labelCountry = new JLabel();
   JLabel labelLastname = new JLabel();
   JTextField fieldLastName = new JTextField();
   JTextField fieldNote = new JTextField();
   JButton buttonCancel = new JButton();
   JButton buttonDelete = new JButton();

   /**
    * Default constructor
    */
   public VigneronDetail()
   {
      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.detail.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.detail.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.detail.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.detail.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.detail.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.detail.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.detail.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.detail.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.detail.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.detail.button.regions");
      jpanel1.add(buttonRegions,cc.xywh(10,18,4,1));

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

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

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

      labelLastname.setName("labelLastname");
      labelLastname.setText("screen.vigneron.detail.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));

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

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

      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);
        buttonDelete.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()));
        buttonFinish.setText(I18nScreens.getInstance().get(buttonFinish.getText()));
        buttonRegions.setText(I18nScreens.getInstance().get(buttonRegions.getText()));
        buttonDelete.setText(I18nScreens.getInstance().get(buttonDelete.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 {

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

        Vigneron recoltant = VigneronProxy.getSessionRecoltantFromID();
        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(VigneronSearch.class);
        }
        else if (e.getSource().equals(buttonFinish)) {
            enregistrer(VigneronSearch.class);
        }
        else if (e.getSource().equals(buttonRegions)) {
            enregistrer(VigneronDetailRegions.class);
        }
        else if (e.getSource().equals(buttonDelete)) {
            try {
                if (showQuestion("Etes-vous certain de vouloir supprimer ce r�coltant ?")) {
                    Vigneron recoltant = VigneronProxy.getSessionRecoltantFromID();
                    VigneronPeer.delete(recoltant);
                    SwapFrame.getInstance().init(VigneronSearch.class);
                }
                else {
                    SwapFrame.getInstance().init(VigneronDetail.class);
                }

            }
            catch (Exception ex) {
                System.out.println("Impossible d'enregistrer ce r�coltant : ");
                // ERREUR
                ex.printStackTrace();
            }
        }
    }

    private void enregistrer(Class partirVers) {
        // ici on va enregistrer le recoltant existant
        try {
            Vigneron recoltant = VigneronProxy.getSessionRecoltantFromID();
            recoltant.setLastname(fieldLastName.getText());
            recoltant.setFirstname(fieldFirstname.getText());
            recoltant.setAddress(fieldAddress.getText());
            recoltant.setCp(fieldCP.getText());
            recoltant.setTown(fieldTown.getText());
            recoltant.setCountry_id(ComponentTools.getClefFromCombo(comboCountry));
            recoltant.setWeb(fieldWeb.getText());
            recoltant.setNote(fieldNote.getText());
            recoltant.setTel(fieldTel.getText());
            recoltant.setFax(fieldFax.getText());
            recoltant.setEmail(fieldEmail.getText());
            recoltant.save();
            SwapFrame.getInstance().init(partirVers);
        }
        catch (Exception ex) {
            System.out.println("Impossible d'enregistrer ce r�coltant : ");
            // ERREUR
            ex.printStackTrace();
        }
    }

    public int getPanelHeight() {
        return 410;
    }


}
TOP

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

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.