Package com.ledruide.druidecave.gui

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

/**
* 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.business.lists.RegionProxy;
import com.ledruide.druidecave.dao.Vigneron;
import com.ledruide.druidecave.helpers.I18nScreens;
import com.ledruide.druidecave.model.TableRecoltants;
import com.ledruide.druidecave.model.TableSorter;
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.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.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;


public class VigneronSearch extends DruideJPanel
{
   JLabel labelTitle = new JLabel();
   JLabel labelCountry = new JLabel();
   JComboBox comboCountry = new JComboBox();
   JLabel labelRegion = new JLabel();
   JButton buttonQuit = new JButton();
   JButton buttonHome = new JButton();
   JButton buttonDetail = new JButton();
   JLabel labelName = new JLabel();
   JTextField fieldName = new JTextField();
   JLabel labelNoteMin = new JLabel();
   JButton buttonAdd = new JButton();
   JTextField fieldNoteMin = new JTextField();
   JComboBox comboRegion = new JComboBox();

    // ****************************************/
    // **                                    **/
    // FAIRE ATTENTION ICI AVEC LE MERGE
    TableRecoltants tableModel = new TableRecoltants();
    TableSorter sorter = new TableSorter(tableModel);
    JTable tableResultats = new JTable(sorter);
    JScrollPane resultatsScrollPane = new JScrollPane();
    // **                                    **/
    // ****************************************/

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

   public JPanel createPanel()
   {
      JPanel jpanel1 = new JPanel();
      FormLayout formlayout1 = new FormLayout("FILL:10PX:NONE,FILL:75PX:NONE,FILL:35PX:NONE,FILL:12PX:NONE,FILL:62PX:NONE,FILL:35PX:NONE,FILL:12PX:NONE,FILL:28PX:NONE,FILL:68PX:NONE,FILL:25PX:NONE,FILL:54PX:NONE,FILL:40PX: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:180PX:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
      CellConstraints cc = new CellConstraints();
      jpanel1.setLayout(formlayout1);

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

      labelCountry.setName("labelCountry");
      labelCountry.setText("screen.vigneron.search.country");
      labelCountry.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelCountry,cc.xy(2,5));

      comboCountry.setName("comboCountry");
      jpanel1.add(comboCountry,cc.xywh(3,5,6,1));

      labelRegion.setName("labelRegion");
      labelRegion.setText("screen.vigneron.search.region");
      labelRegion.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelRegion,cc.xy(9,5));

      /* ******************************* */
      /* ATTENTION AVEC LE MERGE !       */
      tableResultats.setName("tableResultats");
      tableResultats.setRowMargin(2);
      tableResultats.setCellSelectionEnabled(false);
      tableResultats.setColumnSelectionAllowed(false);
      tableResultats.setRowSelectionAllowed(true);
      resultatsScrollPane.setViewportView(tableResultats);
      resultatsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      resultatsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      jpanel1.add(resultatsScrollPane,cc.xywh(2,9,12,1));
      /* ******************************* */

      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));

      buttonDetail.setActionCommand("  ");
      buttonDetail.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonDetail.setName("buttonDetail");
      buttonDetail.setOpaque(false);
      buttonDetail.setText("screen.vigneron.search.button.detail");
      jpanel1.add(buttonDetail,cc.xywh(11,11,3,1));

      labelName.setName("labelName");
      labelName.setText("screen.vigneron.search.name");
      labelName.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelName,cc.xy(2,7));

      fieldName.setName("fieldName");
      jpanel1.add(fieldName,cc.xywh(3,7,8,1));

      labelNoteMin.setName("labelNoteMin");
      labelNoteMin.setText("screen.vigneron.search.notemin");
      labelNoteMin.setHorizontalAlignment(JLabel.RIGHT);
      jpanel1.add(labelNoteMin,cc.xywh(11,7,2,1));

      buttonAdd.setActionCommand("Ajouter un r�coltant");
      buttonAdd.setFont(new Font("Tahoma",Font.BOLD,11));
      buttonAdd.setName("buttonAdd");
      buttonAdd.setOpaque(false);
      buttonAdd.setText("screen.vigneron.search.button.add");
      jpanel1.add(buttonAdd,cc.xywh(2,11,4,1));

      fieldNoteMin.setName("fieldNoteMin");
      jpanel1.add(fieldNoteMin,cc.xy(13,7));

      comboRegion.setName("comboRegion");
      jpanel1.add(comboRegion,cc.xywh(10,5,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 });
      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);
        buttonAdd.addActionListener(this);
        buttonDetail.addActionListener(this);
        comboCountry.addActionListener(this);
        comboRegion.addActionListener(this);

        fieldName.addKeyListener(this);
        fieldNoteMin.addKeyListener(this);
    }

    public void initI18n() {
        buttonQuit.setText(I18nScreens.getInstance().get(buttonQuit.getText()));
        buttonHome.setText(I18nScreens.getInstance().get(buttonHome.getText()));
        buttonDetail.setText(I18nScreens.getInstance().get(buttonDetail.getText()));
        buttonAdd.setText(I18nScreens.getInstance().get(buttonAdd.getText()));
        labelTitle.setText(I18nScreens.getInstance().get(labelTitle.getText()));
        labelCountry.setText(I18nScreens.getInstance().get(labelCountry.getText()));
        labelRegion.setText(I18nScreens.getInstance().get(labelRegion.getText()));
        labelName.setText(I18nScreens.getInstance().get(labelName.getText()));
        labelNoteMin.setText(I18nScreens.getInstance().get(labelNoteMin.getText()));
    }

    public void initEach() throws Exception {
        Session.getInstance().removeAttribute("RECOLTANT_ID");

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

        fieldName.setText(Constants.BLANK);
        fieldNoteMin.setText(Constants.BLANK);

        tableModel.vider();
        // on fait ue recherche afin de pr�afficher tous les r�sultats...
        recherche();
    }

    public void keyReleased(KeyEvent e) {
        if (e.getSource().equals(fieldName)
         || e.getSource().equals(fieldNoteMin)) {
            recherche();
        }
    }

    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(buttonAdd)) {
            SwapFrame.getInstance().init(VigneronAdd.class);
        }
        else if (e.getSource().equals(buttonDetail)) {
            // ici on part sur le d�tail d'une bouteille
            Vigneron recoltant = (Vigneron) tableModel.getSelection(tableResultats.getSelectedRow());
            if (recoltant != null) {
                Session.getInstance().setAttribute("RECOLTANT_ID", recoltant.getId());
                SwapFrame.getInstance().init(VigneronDetail.class);
            }
        }
        else if (e.getSource().equals(comboRegion)){
            recherche();
        }
        else if (e.getSource().equals(comboCountry)) {
            // Ici cela lance la recherche car on modifie les r�gions ce
            //   qui du coup lance la recherche !

            // ici on met � jour les r�gions
            try {
                comboRegion.removeAllItems();
                CombosProxy.add(comboRegion, RegionProxy.getKeyValueList(ComponentTools.getClefFromCombo(comboCountry)), true);
            } catch (Exception ex) { ex.printStackTrace(); }
        }
    }

    private void recherche() {
        // On commence par vider le tableau des r�sultats
        tableModel.vider();

        String pays_id   = ComponentTools.getClefFromCombo(comboCountry);
        String region_id = ComponentTools.getClefFromCombo(comboRegion);
        String leNom  = fieldName.getText();
        String laNote = fieldNoteMin.getText();

        try {
            java.util.List lesRecoltants = VigneronProxy.trouver(leNom, pays_id, region_id);
            java.util.List results = VigneronProxy.filtrerParNoteMin(lesRecoltants, laNote);
            tableModel.addRows(results);
        }
        catch (Exception e1) {
            System.out.println("Impossible de trouver les r�coltants li�e � cette recherche...");
            e1.printStackTrace();
        }
    }

    public int getPanelHeight() {
        return 360;
    }

}
TOP

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

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.