Package gui

Source Code of gui.PSAMusteriSecimEkrani

package gui;

import hibernateSwingApi.component.TablePanel;
import hibernateSwingApi.hibernate.HibernateManager;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import pojos.BireyselMusteri;
import pojos.KurumsalMusteri;
import service.PSAUtil;
import database.DatabaseConnection;

public class PSAMusteriSecimEkrani extends JDialog {

  private static final long serialVersionUID = 1L;
  private JButton jButtonIptal;
  private String musteriAd;
  private Container contentPane;
  private JTabbedPane jTabbedPaneMusteri;
  private JPanel jPanelBireyselMusteri;
  private JPanel jPanelKurumsalMusteri;
  private JLabel jLabelBireyselMusteri;
  private TablePanel cTablePanelBireyselMusteri;
  private JLabel jLabelKurumsalMusteri;
  private TablePanel cTablePanelKurumsalMusteri;
  private JButton jButtonMusteriEkle;

  private final String B_MUSTERI = "bireysel";
  private final String K_MUSTERI = "kurumsal";
  private final String MUSTERI_DEFAULT_VALUE = "Müşteri Seçiniz";

  public PSAMusteriSecimEkrani(Frame owner) {
    super(owner, true);
    setResizable(false);
    setModal(false);
    setModalityType(ModalityType.DOCUMENT_MODAL);
    setTitle("PSA MERKEZ MÜŞTERİ SECİM EKRANI");
    setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
        .getImage());
    contentPane = getContentPane();
    contentPane.setBounds(100, 100, 470, 300);

    jButtonIptal = new JButton("İPTAL");
    jButtonIptal.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/geriButonu.png"));

    jButtonIptal.setFont(new Font("Tahoma", Font.BOLD, 12));
    jButtonIptal.setBounds(70, 273, 144, 23);

    jTabbedPaneMusteri = new JTabbedPane(SwingConstants.TOP);
    jTabbedPaneMusteri.setFont(new Font("Tahoma", Font.BOLD, 15));

    jButtonMusteriEkle = new JButton("MÜŞTERİ EKLE");
    jButtonMusteriEkle.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/ekle.png"));
    jButtonMusteriEkle.setFont(new Font("Tahoma", Font.BOLD, 12));
    GroupLayout groupLayout = new GroupLayout(getContentPane());
    groupLayout
        .setHorizontalGroup(groupLayout
            .createParallelGroup(Alignment.TRAILING)
            .addGroup(
                Alignment.LEADING,
                groupLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        groupLayout
                            .createParallelGroup(
                                Alignment.LEADING)
                            .addComponent(
                                jTabbedPaneMusteri,
                                GroupLayout.PREFERRED_SIZE,
                                589,
                                GroupLayout.PREFERRED_SIZE)
                            .addGroup(
                                groupLayout
                                    .createSequentialGroup()
                                    .addComponent(
                                        jButtonMusteriEkle,
                                        GroupLayout.DEFAULT_SIZE,
                                        291,
                                        Short.MAX_VALUE)
                                    .addGap(7)
                                    .addComponent(
                                        jButtonIptal,
                                        GroupLayout.DEFAULT_SIZE,
                                        291,
                                        Short.MAX_VALUE)))
                    .addContainerGap()));
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
        Alignment.LEADING).addGroup(
        groupLayout
            .createSequentialGroup()
            .addContainerGap()
            .addComponent(jTabbedPaneMusteri,
                GroupLayout.PREFERRED_SIZE, 440,
                GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(
                groupLayout
                    .createParallelGroup(Alignment.LEADING)
                    .addComponent(jButtonIptal,
                        GroupLayout.DEFAULT_SIZE, 41,
                        Short.MAX_VALUE)
                    .addComponent(jButtonMusteriEkle,
                        GroupLayout.PREFERRED_SIZE, 14,
                        Short.MAX_VALUE))
            .addContainerGap()));

    jPanelBireyselMusteri = new JPanel();
    jTabbedPaneMusteri.addTab("Bireysel", PSAUtil
        .getImageIconViaRelativePath("picture/bireyselMusteri.png"),
        jPanelBireyselMusteri, "Bireysel Müşteri Listesi");
    jPanelBireyselMusteri.setLayout(null);

    jLabelBireyselMusteri = new JLabel();
    jLabelBireyselMusteri.setText("BİREYSEL MÜŞTERİ LİSTESİ");
    jLabelBireyselMusteri.setFont(new Font("Tahoma", Font.BOLD, 14));
    jLabelBireyselMusteri.setBounds(10, 11, 212, 25);
    jPanelBireyselMusteri.add(jLabelBireyselMusteri);

    cTablePanelBireyselMusteri = new TablePanel((String) null,
        BireyselMusteri.class, true, true);
    cTablePanelBireyselMusteri.getTable().setAutoResizeMode(
        JTable.AUTO_RESIZE_ALL_COLUMNS);
    cTablePanelBireyselMusteri
        .setBorder(new LineBorder(new Color(0, 0, 0)));
    cTablePanelBireyselMusteri.setBounds(10, 41, 564, 342);
    jPanelBireyselMusteri.add(cTablePanelBireyselMusteri);

    jPanelKurumsalMusteri = new JPanel();
    jTabbedPaneMusteri.addTab("Kurumsal", PSAUtil
        .getImageIconViaRelativePath("picture/kurumsalMusteri.png"),
        jPanelKurumsalMusteri, "Kurumsal Müşteri Listesi");
    jPanelKurumsalMusteri.setLayout(null);

    jLabelKurumsalMusteri = new JLabel();
    jLabelKurumsalMusteri.setText("KURUMSAL MÜŞTERİ LİSTESİ");
    jLabelKurumsalMusteri.setFont(new Font("Tahoma", Font.BOLD, 14));
    jLabelKurumsalMusteri.setBounds(10, 11, 219, 25);
    jPanelKurumsalMusteri.add(jLabelKurumsalMusteri);

    cTablePanelKurumsalMusteri = new TablePanel((String) null,
        KurumsalMusteri.class, true, true);
    cTablePanelKurumsalMusteri.getTable().setAutoResizeMode(
        JTable.AUTO_RESIZE_ALL_COLUMNS);
    cTablePanelKurumsalMusteri
        .setBorder(new LineBorder(new Color(0, 0, 0)));
    cTablePanelKurumsalMusteri.setBounds(10, 39, 564, 344);
    jPanelKurumsalMusteri.add(cTablePanelKurumsalMusteri);
    getContentPane().setLayout(groupLayout);

    refreshTable();
    initListener();
    pack();
  }

  private void refreshTable() {
    DatabaseConnection.databaseConnect();
    List<?> bireyselMusteriListesi = HibernateManager.getInstance().get(
        BireyselMusteri.class, false);
    cTablePanelBireyselMusteri.setObjects(bireyselMusteriListesi);
    List<?> kurumsalMusteriListesi = HibernateManager.getInstance().get(
        KurumsalMusteri.class, false);
    cTablePanelKurumsalMusteri.setObjects(kurumsalMusteriListesi);
  }

  private void initListener() {

    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        musteriAd = MUSTERI_DEFAULT_VALUE;
        dispose();
      }
    });

    jButtonIptal.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        musteriAd = MUSTERI_DEFAULT_VALUE;
        dispose();
      }
    });

    jTabbedPaneMusteri.addChangeListener(new ChangeListener() {
      @Override
      public void stateChanged(ChangeEvent arg0) {
        cTablePanelBireyselMusteri.clearSelection();
        cTablePanelKurumsalMusteri.clearSelection();
      }
    });

    cTablePanelBireyselMusteri.getTable().addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              BireyselMusteri bm = (BireyselMusteri) cTablePanelBireyselMusteri
                  .getSelectedObject();
              musteriAd = bm.getAd() + " " + bm.getSoyad();
              dispose();
            }
          }
        });

    cTablePanelKurumsalMusteri.getTable().addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              KurumsalMusteri km = (KurumsalMusteri) cTablePanelKurumsalMusteri
                  .getSelectedObject();
              musteriAd = km.getFirmaUnvani();
              dispose();
            }
          }
        });

    jButtonMusteriEkle.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        musteriEkleClicked();
      }
    });
  }

  protected void musteriEkleClicked() {
    if (PSAMusteriEklemeEkrani.getInstanceState() != null) {
      PSAMusteriEklemeEkrani.getInstanceState().requestFocus();
      return;
    }
    if (jTabbedPaneMusteri.getSelectedIndex() == 0) {
      PSAMusteriEklemeEkrani.getInstance(0, B_MUSTERI).setVisible(true);
    } else if (jTabbedPaneMusteri.getSelectedIndex() == 1) {
      PSAMusteriEklemeEkrani.getInstance(0, K_MUSTERI).setVisible(true);
    }
  }

  public String showDialog() {
    setVisible(true);
    return musteriAd;
  }
}
TOP

Related Classes of gui.PSAMusteriSecimEkrani

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.