Package gui

Source Code of gui.PSAMusteriEkrani

package gui;

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

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
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.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import pojos.BireyselMusteri;
import pojos.KurumsalMusteri;
import service.AutoClosingMessageDialog;
import service.PSAUtil;

public class PSAMusteriEkrani extends JFrame {

  private static final long serialVersionUID = 1L;
  private static PSAMusteriEkrani instance;
  private JPopupMenu pMenu;
  private JMenuItem menuItem;
  private JMenuItem menuItem2;
  private JMenuItem menuItem3;
  private JButton JButtonMusteriEkle;
  private JButton JButtonMusteriGuncelle;
  private JButton JButtonMusteriSil;
  private JButton jButtonMusteriHareket;
  private JTabbedPane jTabbedPaneMusteri;
  private JPanel jPanelBireyselMusteri;
  private JLabel jLabelBireyselMusteri;
  private TablePanel cTableBireyselMusteri;
  private JPanel jPanelKurumsalMusteri;
  private JLabel jLabelKurumsalMusteri;
  private TablePanel cTableKurumsalMusteri;
  private BireyselMusteri bMusteri;
  private KurumsalMusteri kMusteri;

  private final String B_MUSTERI = "bireysel";
  private final String K_MUSTERI = "kurumsal";
  private String musteriTuru = B_MUSTERI;

  public static PSAMusteriEkrani getInstance(int state) {
    if (state == 0)
      instance = new PSAMusteriEkrani();
    return instance;
  }

  public PSAMusteriEkrani() {
    initialize();
  }

  private void initialize() {
    setTitle("PSA MERKEZ MÜŞTERİ EKRANI");
    setBounds(0, 0, 1250, 485);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
        .getImage());

    pMenu = new JPopupMenu();
    menuItem2 = new JMenuItem("Müşteri Sil");
    pMenu.add(menuItem2);
    menuItem = new JMenuItem("Müşteri Güncelle");
    pMenu.add(menuItem);
    menuItem3 = new JMenuItem("Müşteri Hareketleri");
    pMenu.add(menuItem3);
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0, 821, 300, 15, 0 };
    gridBagLayout.rowHeights = new int[] { 32, 100, 100, 100, 100, 15, 0 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 1.0, 0.0,
        Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
        Double.MIN_VALUE };
    getContentPane().setLayout(gridBagLayout);

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

    jPanelBireyselMusteri = new JPanel();
    jTabbedPaneMusteri.addTab("Bireysel", PSAUtil
        .getImageIconViaRelativePath("picture/bireyselMusteri.png"),
        jPanelBireyselMusteri, "Bireysel Müşteri Listesi");
    GridBagLayout gbl_jPanelBireyselMusteri = new GridBagLayout();
    gbl_jPanelBireyselMusteri.columnWidths = new int[] { 564, 0 };
    gbl_jPanelBireyselMusteri.rowHeights = new int[] { 25, 317, 0 };
    gbl_jPanelBireyselMusteri.columnWeights = new double[] { 1.0,
        Double.MIN_VALUE };
    gbl_jPanelBireyselMusteri.rowWeights = new double[] { 0.0, 1.0,
        Double.MIN_VALUE };
    jPanelBireyselMusteri.setLayout(gbl_jPanelBireyselMusteri);

    jLabelBireyselMusteri = new JLabel();
    jLabelBireyselMusteri.setText("BİREYSEL MÜŞTERİ LİSTESİ");
    jLabelBireyselMusteri.setFont(new Font("Tahoma", Font.BOLD, 14));
    GridBagConstraints gbc_jLabelBireyselMusteri = new GridBagConstraints();
    gbc_jLabelBireyselMusteri.anchor = GridBagConstraints.WEST;
    gbc_jLabelBireyselMusteri.fill = GridBagConstraints.VERTICAL;
    gbc_jLabelBireyselMusteri.insets = new Insets(0, 0, 5, 0);
    gbc_jLabelBireyselMusteri.gridx = 0;
    gbc_jLabelBireyselMusteri.gridy = 0;
    jPanelBireyselMusteri.add(jLabelBireyselMusteri,
        gbc_jLabelBireyselMusteri);

    cTableBireyselMusteri = new TablePanel((String) null,
        BireyselMusteri.class, true, true);
    cTableBireyselMusteri.getTable().setAutoResizeMode(
        JTable.AUTO_RESIZE_ALL_COLUMNS);
    cTableBireyselMusteri.setBorder(new LineBorder(new Color(0, 0, 0)));
    GridBagConstraints gbc_cTableBireyselMusteri = new GridBagConstraints();
    gbc_cTableBireyselMusteri.fill = GridBagConstraints.BOTH;
    gbc_cTableBireyselMusteri.gridx = 0;
    gbc_cTableBireyselMusteri.gridy = 1;
    jPanelBireyselMusteri.add(cTableBireyselMusteri,
        gbc_cTableBireyselMusteri);

    jPanelKurumsalMusteri = new JPanel();
    jTabbedPaneMusteri.addTab("Kurumsal", PSAUtil
        .getImageIconViaRelativePath("picture/kurumsalMusteri.png"),
        jPanelKurumsalMusteri, "Kurumsal Müşteri Listesi");
    GridBagLayout gbl_jPanelKurumsalMusteri = new GridBagLayout();
    gbl_jPanelKurumsalMusteri.columnWidths = new int[] { 564, 0 };
    gbl_jPanelKurumsalMusteri.rowHeights = new int[] { 25, 317, 0 };
    gbl_jPanelKurumsalMusteri.columnWeights = new double[] { 1.0,
        Double.MIN_VALUE };
    gbl_jPanelKurumsalMusteri.rowWeights = new double[] { 0.0, 1.0,
        Double.MIN_VALUE };
    jPanelKurumsalMusteri.setLayout(gbl_jPanelKurumsalMusteri);

    jLabelKurumsalMusteri = new JLabel();
    jLabelKurumsalMusteri.setText("KURUMSAL MÜŞTERİ LİSTESİ");
    jLabelKurumsalMusteri.setFont(new Font("Tahoma", Font.BOLD, 14));
    GridBagConstraints gbc_jLabelKurumsalMusteri = new GridBagConstraints();
    gbc_jLabelKurumsalMusteri.anchor = GridBagConstraints.WEST;
    gbc_jLabelKurumsalMusteri.fill = GridBagConstraints.VERTICAL;
    gbc_jLabelKurumsalMusteri.insets = new Insets(0, 0, 5, 0);
    gbc_jLabelKurumsalMusteri.gridx = 0;
    gbc_jLabelKurumsalMusteri.gridy = 0;
    jPanelKurumsalMusteri.add(jLabelKurumsalMusteri,
        gbc_jLabelKurumsalMusteri);

    cTableKurumsalMusteri = new TablePanel((String) null,
        KurumsalMusteri.class, true, true);
    cTableKurumsalMusteri.getTable().setAutoResizeMode(
        JTable.AUTO_RESIZE_ALL_COLUMNS);
    cTableKurumsalMusteri.setBorder(new LineBorder(new Color(0, 0, 0)));
    GridBagConstraints gbc_cTableKurumsalMusteri = new GridBagConstraints();
    gbc_cTableKurumsalMusteri.fill = GridBagConstraints.BOTH;
    gbc_cTableKurumsalMusteri.gridx = 0;
    gbc_cTableKurumsalMusteri.gridy = 1;
    jPanelKurumsalMusteri.add(cTableKurumsalMusteri,
        gbc_cTableKurumsalMusteri);
    GridBagConstraints gbc_jTabbedPaneMusteri = new GridBagConstraints();
    gbc_jTabbedPaneMusteri.fill = GridBagConstraints.BOTH;
    gbc_jTabbedPaneMusteri.insets = new Insets(0, 0, 5, 5);
    gbc_jTabbedPaneMusteri.gridheight = 4;
    gbc_jTabbedPaneMusteri.gridx = 1;
    gbc_jTabbedPaneMusteri.gridy = 1;
    getContentPane().add(jTabbedPaneMusteri, gbc_jTabbedPaneMusteri);

    JButtonMusteriEkle = new JButton();
    JButtonMusteriEkle.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/ekle.png"));
    JButtonMusteriEkle.setText("BİREYSEL MÜŞTERİ EKLE");
    JButtonMusteriEkle.setFont(new Font("Tahoma", Font.BOLD, 14));
    GridBagConstraints gbc_JButtonMusteriEkle = new GridBagConstraints();
    gbc_JButtonMusteriEkle.fill = GridBagConstraints.BOTH;
    gbc_JButtonMusteriEkle.insets = new Insets(0, 0, 5, 5);
    gbc_JButtonMusteriEkle.gridx = 2;
    gbc_JButtonMusteriEkle.gridy = 1;
    getContentPane().add(JButtonMusteriEkle, gbc_JButtonMusteriEkle);

    JButtonMusteriGuncelle = new JButton();
    JButtonMusteriGuncelle.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/kullaniciGuncelle.png"));
    JButtonMusteriGuncelle.setText("BİREYSEL MÜŞTERİ BİLGİSİ GÜNCELLE");
    JButtonMusteriGuncelle.setFont(new Font("Tahoma", Font.BOLD, 14));
    JButtonMusteriGuncelle.setEnabled(false);
    GridBagConstraints gbc_JButtonMusteriGuncelle = new GridBagConstraints();
    gbc_JButtonMusteriGuncelle.fill = GridBagConstraints.BOTH;
    gbc_JButtonMusteriGuncelle.insets = new Insets(0, 0, 5, 5);
    gbc_JButtonMusteriGuncelle.gridx = 2;
    gbc_JButtonMusteriGuncelle.gridy = 2;
    getContentPane()
        .add(JButtonMusteriGuncelle, gbc_JButtonMusteriGuncelle);

    JButtonMusteriSil = new JButton();
    JButtonMusteriSil.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/silIcon.png"));
    JButtonMusteriSil.setText("BİREYSEL MÜŞTERİ SİL");
    JButtonMusteriSil.setFont(new Font("Tahoma", Font.BOLD, 14));
    JButtonMusteriSil.setEnabled(false);
    GridBagConstraints gbc_JButtonMusteriSil = new GridBagConstraints();
    gbc_JButtonMusteriSil.fill = GridBagConstraints.BOTH;
    gbc_JButtonMusteriSil.insets = new Insets(0, 0, 5, 5);
    gbc_JButtonMusteriSil.gridx = 2;
    gbc_JButtonMusteriSil.gridy = 3;
    getContentPane().add(JButtonMusteriSil, gbc_JButtonMusteriSil);

    jButtonMusteriHareket = new JButton();
    jButtonMusteriHareket.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/perIstatistik.png"));
    jButtonMusteriHareket.setEnabled(false);
    jButtonMusteriHareket.setText("MÜŞTERİ HAREKETLERİ");
    jButtonMusteriHareket.setFont(new Font("Tahoma", Font.BOLD, 14));
    GridBagConstraints gbc_jButtonMusteriHareket = new GridBagConstraints();
    gbc_jButtonMusteriHareket.insets = new Insets(0, 0, 5, 5);
    gbc_jButtonMusteriHareket.fill = GridBagConstraints.BOTH;
    gbc_jButtonMusteriHareket.gridx = 2;
    gbc_jButtonMusteriHareket.gridy = 4;
    getContentPane().add(jButtonMusteriHareket, gbc_jButtonMusteriHareket);

    initListeners();
    refreshTable();
  }

  private void refreshTable() {
    List<?> bireyselMüsteriListesi = HibernateManager.getInstance().get(
        BireyselMusteri.class, false);
    cTableBireyselMusteri.setObjects(bireyselMüsteriListesi);
    List<?> kurumsalMüsteriListesi = HibernateManager.getInstance().get(
        KurumsalMusteri.class, false);
    cTableKurumsalMusteri.setObjects(kurumsalMüsteriListesi);
  }

  private void initListeners() {

    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        anaEkranSetEnable();
      }
    });

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

    cTableBireyselMusteri.getTable().getSelectionModel()
        .addListSelectionListener(new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
              return;
            bMusteri = (BireyselMusteri) cTableBireyselMusteri
                .getSelectedObject();
            if (bMusteri == null) {
              JButtonMusteriGuncelle.setEnabled(false);
              JButtonMusteriSil.setEnabled(false);
              jButtonMusteriHareket.setEnabled(false);
            } else {
              JButtonMusteriGuncelle.setEnabled(true);
              JButtonMusteriSil.setEnabled(true);
              jButtonMusteriHareket.setEnabled(true);
            }
          }
        });

    cTableBireyselMusteri.getTable().addMouseListener(new MouseAdapter() {
      @Override
      public void mouseReleased(MouseEvent e) {
        popupMenu(e, B_MUSTERI);
      }

      @Override
      public void mousePressed(MouseEvent e) {
        popupMenu(e, B_MUSTERI);
      }

      @Override
      public void mouseClicked(MouseEvent e) {
        if (e.getClickCount() == 2) {
          musteriGuncelleClicked();
        }
      }
    });

    cTableKurumsalMusteri.getTable().getSelectionModel()
        .addListSelectionListener(new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
              return;
            kMusteri = (KurumsalMusteri) cTableKurumsalMusteri
                .getSelectedObject();
            if (kMusteri == null) {
              JButtonMusteriGuncelle.setEnabled(false);
              JButtonMusteriSil.setEnabled(false);
              jButtonMusteriHareket.setEnabled(false);
            } else {
              JButtonMusteriGuncelle.setEnabled(true);
              JButtonMusteriSil.setEnabled(true);
              jButtonMusteriHareket.setEnabled(true);
            }
          }
        });

    cTableKurumsalMusteri.getTable().addMouseListener(new MouseAdapter() {
      @Override
      public void mouseReleased(MouseEvent e) {
        popupMenu(e, K_MUSTERI);
      }

      @Override
      public void mousePressed(MouseEvent e) {
        popupMenu(e, K_MUSTERI);
      }

      @Override
      public void mouseClicked(MouseEvent e) {
        if (e.getClickCount() == 2) {
          musteriGuncelleClicked();
        }
      }
    });

    menuItem.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        musteriGuncelleClicked();
      }
    });

    menuItem2.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        musteriSilClicked();
      }
    });

    menuItem3.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        musteriHareketCLicked();
      }
    });

    JButtonMusteriEkle.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        musteriEklemeClicked(musteriTuru);
      }
    });

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

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

    jButtonMusteriHareket.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        musteriHareketCLicked();
      }
    });
  }

  protected void musteriHareketCLicked() {
    if (musteriTuru.equals(B_MUSTERI)) {
      PSAMusteriHareketEkrani.getInstance(bMusteri, musteriTuru)
          .setVisible(true);
    } else if (musteriTuru.equals(K_MUSTERI)) {
      PSAMusteriHareketEkrani.getInstance(kMusteri, musteriTuru)
          .setVisible(true);
    }
    setEnabled(false);
  }

  protected void musteriGuncelleClicked() {
    if (musteriTuru.equals(B_MUSTERI)) {
      PSAMusteriGuncellemeEkrani.getInstance(bMusteri, musteriTuru)
          .setVisible(true);
    } else if (musteriTuru.equals(K_MUSTERI)) {
      PSAMusteriGuncellemeEkrani.getInstance(kMusteri, musteriTuru)
          .setVisible(true);
    }
    setEnabled(false);
  }

  protected void tabbedPaneClicked() {
    cTableBireyselMusteri.clearSelection();
    cTableKurumsalMusteri.clearSelection();
    JButtonMusteriGuncelle.setEnabled(false);
    JButtonMusteriSil.setEnabled(false);
    jButtonMusteriHareket.setEnabled(false);
    if (jTabbedPaneMusteri.getSelectedIndex() == 0) {
      musteriTuru = B_MUSTERI;
      JButtonMusteriEkle.setText("BİREYSEL MÜŞTERİ EKLE");
      JButtonMusteriGuncelle.setText("BİREYSEL MÜŞTERİ BİLGİSİ GÜNCELLE");
      JButtonMusteriSil.setText("BİREYSEL MÜŞTERİ SİL");
      jButtonMusteriHareket.setText("BİREYSEL MÜŞTERİ HAREKETLERİ");
    } else if (jTabbedPaneMusteri.getSelectedIndex() == 1) {
      musteriTuru = K_MUSTERI;
      JButtonMusteriEkle.setText("KURUMSAL MÜŞTERİ EKLE");
      JButtonMusteriGuncelle.setText("KURUMSAL MÜŞTERİ BİLGİSİ GÜNCELLE");
      JButtonMusteriSil.setText("KURUMSAL MÜŞTERİ SİL");
      jButtonMusteriHareket.setText("KURUMSAL MÜŞTERİ HAREKETLERİ");
    }
  }

  protected void musteriEklemeClicked(String musteriTuru) {
    PSAMusteriEklemeEkrani.getInstance(1, musteriTuru).setVisible(true);
    setEnabled(false);
  }

  protected void anaEkranSetEnable() {
    PSAAnaEkran.getInstance(null).setEnabled(true);
    instance.dispose();
  }

  protected void popupMenu(MouseEvent e, String musteriTuru) {
    if (e.isPopupTrigger()) {
      Point p = e.getPoint();
      int rowNumber = 0;
      ListSelectionModel model = null;
      if (musteriTuru.equals(B_MUSTERI)) {
        rowNumber = cTableBireyselMusteri.getTable().rowAtPoint(p);
        model = cTableBireyselMusteri.getTable().getSelectionModel();
      } else if (musteriTuru.equals(K_MUSTERI)) {
        rowNumber = cTableKurumsalMusteri.getTable().rowAtPoint(p);
        model = cTableKurumsalMusteri.getTable().getSelectionModel();
      }
      model.setSelectionInterval(rowNumber, rowNumber);
      pMenu.show(e.getComponent(), e.getX(), e.getY());
    }
  }

  protected void musteriSilClicked() {
    int selectedOption = JOptionPane.showOptionDialog(null,
        "Müşteriyi silmek istediğinizden emin misiniz?",
        "SİSTEM UYARISI", JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.INFORMATION_MESSAGE, null, new String[] { "EVET",
            "HAYIR" }, "default");
    if (selectedOption == JOptionPane.OK_OPTION) {
      boolean delete = false;
      if (musteriTuru.equals(B_MUSTERI)) {
        delete = HibernateManager.getInstance().delete(bMusteri);
      } else if (musteriTuru.equals(K_MUSTERI)) {
        delete = HibernateManager.getInstance().delete(kMusteri);
      }

      if (!delete) {
        return;
      }

      if (musteriTuru.equals(B_MUSTERI)) {
        cTableBireyselMusteri.getTable().clearSelection();
        AutoClosingMessageDialog
            .showAutoClosingMessageDialog(
                "Bireysel müşteri sistemden başarı ile silinmiştir.",
                2);
      } else if (musteriTuru.equals(K_MUSTERI)) {
        cTableKurumsalMusteri.getTable().clearSelection();
        AutoClosingMessageDialog
            .showAutoClosingMessageDialog(
                "Kurumsal müşteri sistemden başarı ile silinmiştir.",
                2);
      }

    }
  }
}
TOP

Related Classes of gui.PSAMusteriEkrani

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.