Package eclc

Source Code of eclc.Main

/*
* @(#)Main.java   13/09/26
*
* Copyright (c) 2013 DieHard Development
*
* All rights reserved.
Released under the FreeBSD  license
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*
*
*
*/


package eclc;

//~--- non-JDK imports --------------------------------------------------------

import com.xzq.osc.JocTable;

import eclc.Exceptions.exceptions.NonexistentEntityException;
import eclc.Exceptions.exceptions.PreexistingEntityException;

import org.joda.time.DateTime;

//~--- JDK imports ------------------------------------------------------------

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

/**
* Class description
*
*
* @version        1.0, 13/08/21
* @author         TJ
*/
public class Main extends JFrame {
    private static final long serialVersionUID = 1L;
    private static TableCellListener tcl = null;
    private static TableCellListener tclFleet = null;
    private static final Logger LOG = Logger.getLogger(Main.class.getName(), null);

    /**
     * Field description
     */
    public static final String ENTRY = "Entry";
    private static int _votes = 0;
    private static int _ID = 0;
    private static String _truckClass = "";
    private static String _truckMake = "";
    private static String _truckOwner = "";
    private static String _createEntryTruckClass = "";
    private static String _createEntryTruckMake = "";
    private static String _createEntryTruckOwner = "";
    private static int _fleetID = 0;
    private static String _fleetName = "";
    private static int _fleetVotes = 0;
    private static DateTime dTime;
    private Action action = new AbstractAction() {
        private static final long serialVersionUID = 1L;
        @Override
        public void actionPerformed(ActionEvent e) {
            tcl = (TableCellListener) e.getSource();
            getEntryTableValues();
            createEntryEdit();
            System.out.println("Row   : " + tcl.getRow());
            System.out.println("Column: " + tcl.getColumn());
            System.out.println("Old   : " + tcl.getOldValue());
            System.out.println("New   : " + tcl.getNewValue());
        }
    };
    private Action actionFleet = new AbstractAction() {
        private static final long serialVersionUID = 1L;
        @Override
        public void actionPerformed(ActionEvent e) {
            tclFleet = (TableCellListener) e.getSource();
            getFleetTableValues();
            createFleetEdit();
            System.out.println("Row   : " + tclFleet.getRow());
            System.out.println("Column: " + tclFleet.getColumn());
            System.out.println("Old   : " + tclFleet.getOldValue());
            System.out.println("New   : " + tclFleet.getNewValue());
        }
    };
    @SuppressWarnings("rawtypes")
    private org.jdesktop.swingbinding.JTableBinding jTableBinding;
    @SuppressWarnings("rawtypes")
    private org.jdesktop.swingbinding.JTableBinding jTableBindingFleet;
    private JPanel contentPane;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    private com.xzq.osc.JocTable jocTable;
    private com.xzq.osc.JocTable jocFleet;
    private javax.persistence.EntityManager entityManager;
    private javax.persistence.Query entryQuery;
    private javax.persistence.Query fleetQuery;
    private java.util.List<eclc.Entry> entryList;
    private java.util.List<eclc.Fleet> fleetList;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private JMenuBar menuBar;
    private JMenu mnFile;
    private JMenuItem mntmExit;
    private JTextField txtTruckOwner;
    private JButton btnNewButton_2;
    private JButton btnNewButton_3;
    private JButton btnNewButton_4;
    private JButton btnNewButton_5;
    private JButton btnNewButton_6;
    private JButton btnDelete;
    private JButton btnFleetDelete;

    /**
     * Create the frame.
     */
    public Main() {
        initBinding();
        bindFleetTable();
        buildGui();
    }

    /**
     *
     */
    private void buildGui() {
        tcl = new TableCellListener(jocTable, getAction());
        tclFleet = new TableCellListener(jocFleet, getActionFleet());
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 881, 409);
        menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        mnFile = new JMenu("File");
        menuBar.add(mnFile);
        mntmExit = new JMenuItem("Exit");
        mntmExit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                System.exit(0);
            }
        });
        mnFile.add(mntmExit);

        JMenu mnShowControl = new JMenu("Show Control");

        menuBar.add(mnShowControl);

        JMenuItem mntmSales = new JMenuItem("Sales");

        mntmSales.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Sales sa = new Sales();

                sa.showSales();
            }
        });
        mnShowControl.add(mntmSales);

        JMenuItem mntmVendors = new JMenuItem("Vendors");

        mntmVendors.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Vendors vn = new Vendors();

                vn.showVendors();
            }
        });
        mnShowControl.add(mntmVendors);

        JMenuItem mntmExpenses = new JMenuItem("Expenses");

        mntmExpenses.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                Expenses ep = new Expenses();

                ep.showExpenses();
            }
        });
        mnShowControl.add(mntmExpenses);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        contentPane.add(jScrollPane1);
        contentPane.add(jScrollPane2);
        txtTruckOwner = new JTextField();
        txtTruckOwner.setHorizontalAlignment(SwingConstants.CENTER);
        txtTruckOwner.setToolTipText("Enter Truck Owners Name or Fleet Name");
        txtTruckOwner.setText("Truck Owner / Fleet Name");
        txtTruckOwner.setBounds(43, 252, 180, 28);
        contentPane.add(txtTruckOwner);
        txtTruckOwner.setColumns(10);

        final JComboBox<String> comboBox = new JComboBox<String>();

        comboBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (null != comboBox.getSelectedItem()) {
                    _createEntryTruckMake = comboBox.getSelectedItem().toString();
                } else {
                    _createEntryTruckMake = "EMPTY";
                }
            }
        });
        comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {
            "Truck Make", "Peterbilt", "Kenworth", "FreightLiner", "International", "Western Star", "Volvo", "Sterling",
            "Ford", "Dodge", "Chevy"
        }));
        comboBox.setToolTipText("Choose Truck Maker");
        comboBox.setBounds(233, 252, 118, 28);
        contentPane.add(comboBox);

        final JComboBox<String> comboBox_1 = new JComboBox<String>();

        comboBox_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (null != comboBox_1.getSelectedItem()) {
                    _createEntryTruckClass = comboBox_1.getSelectedItem().toString();
                } else {
                    _createEntryTruckClass = "EMPTY";
                }
            }
        });
        comboBox_1.setModel(new DefaultComboBoxModel(new String[] {
            "Truck Class", "BobTail", "Combo", "Classic", "Straight Truck", "Wrecker"
        }));
        comboBox_1.setBounds(361, 252, 108, 28);
        comboBox_1.setToolTipText("Choose truck class");
        contentPane.add(comboBox_1);

        JButton btnNewButton = new JButton("Create Entry");

        btnNewButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (!txtTruckOwner.getText().equals("") &&!txtTruckOwner.getText().equals("Truck Owner / Fleet Name")) {
                    _createEntryTruckOwner = txtTruckOwner.getText();

                    try {
                        createNewEntry();
                        contentPane.remove(jScrollPane1);
                        contentPane.repaint();
                        contentPane.validate();
                        initBinding();
                        contentPane.add(jScrollPane1);
                    } catch (PreexistingEntityException ex) {
                        LOG.log(Level.SEVERE, null, ex);
                    } catch (Exception ex) {
                        LOG.log(Level.SEVERE, null, ex);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "You did not specify data that is required, entry FAILED");
                }
            }
        });
        btnNewButton.setToolTipText("Create Entry");
        btnNewButton.setBounds(134, 291, 108, 28);
        contentPane.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("Create Fleet");

        btnNewButton_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (!txtTruckOwner.getText().equals("") &&!txtTruckOwner.getText().equals("Truck Owner / Fleet Name")) {
                    _fleetName = txtTruckOwner.getText();
                    createFleetEntry();
                    contentPane.remove(jScrollPane2);
                    contentPane.repaint();
                    contentPane.validate();
                    bindFleetTable();
                    contentPane.add(jScrollPane2);
                } else {
                    JOptionPane.showMessageDialog(null, "You did not specify a Fleet Name, entry FAILED");
                }
            }
        });
        btnNewButton_1.setToolTipText("Create Fleet");
        btnNewButton_1.setBounds(301, 290, 108, 28);
        contentPane.add(btnNewButton_1);

        JLabel lblEastCoastLarge = new JLabel("East Coast Large Cars Annual Truck Show");

        lblEastCoastLarge.setFont(new Font("SansSerif", Font.BOLD, 22));
        lblEastCoastLarge.setHorizontalAlignment(SwingConstants.CENTER);
        lblEastCoastLarge.setBounds(15, 213, 493, 28);
        contentPane.add(lblEastCoastLarge);

        JLabel lblEclcClassWinner = new JLabel("ECLC Class Winner Selector");

        lblEclcClassWinner.setFont(new Font("SansSerif", Font.BOLD, 14));
        lblEclcClassWinner.setHorizontalAlignment(SwingConstants.CENTER);
        lblEclcClassWinner.setBounds(515, 224, 343, 16);
        contentPane.add(lblEclcClassWinner);
        btnNewButton_2 = new JButton("BobTail");
        btnNewButton_2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showWinners("BobTail");
            }
        });
        btnNewButton_2.setToolTipText("Winners BobTail Class");
        btnNewButton_2.setBounds(513, 253, 90, 28);
        contentPane.add(btnNewButton_2);
        btnNewButton_3 = new JButton("Combo");
        btnNewButton_3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showWinners("Combo");
            }
        });
        btnNewButton_3.setToolTipText("Winners Combo Class");
        btnNewButton_3.setBounds(640, 253, 90, 28);
        contentPane.add(btnNewButton_3);
        btnNewButton_4 = new JButton("Classic");
        btnNewButton_4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showWinners("Classic");
            }
        });
        btnNewButton_4.setToolTipText("Winners Classic Class");
        btnNewButton_4.setBounds(766, 253, 90, 28);
        contentPane.add(btnNewButton_4);
        btnNewButton_5 = new JButton("Straight Truck");
        btnNewButton_5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showWinners("Straight Truck");
            }
        });
        btnNewButton_5.setToolTipText("Winners Class Straight Truck");
        btnNewButton_5.setBounds(562, 290, 118, 28);
        contentPane.add(btnNewButton_5);
        btnNewButton_6 = new JButton("Wrecker");
        btnNewButton_6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                showWinners("Wrecker");
            }
        });
        btnNewButton_6.setToolTipText("Winners Wrecker Class");
        btnNewButton_6.setBounds(704, 290, 90, 28);
        contentPane.add(btnNewButton_6);

        JButton btnNewButton_7 = new JButton("Best of Show");

        btnNewButton_7.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                BestOfShow bs = new BestOfShow();

                bs.showBestOfShow();
            }
        });
        btnNewButton_7.setBounds(630, 330, 118, 28);
        btnNewButton_7.setToolTipText("Show the Best of Show Winner");
        contentPane.add(btnNewButton_7);
        btnDelete = new JButton("Delete Entry");
        btnDelete.setBounds(64, 330, 108, 28);
        btnDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                deleteEntry();
            }
        });
        contentPane.add(btnDelete);
        btnFleetDelete = new JButton("Delete Fleet");
        btnFleetDelete.setBounds(371, 330, 108, 28);
        btnFleetDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                deleteFleet();
            }
        });
        contentPane.add(btnFleetDelete);
    }

    /**
     * Launch the application.
     *
     * @param args
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                dTime = new DateTime();

                try {
                    Main frame = new Main();

                    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
                    frame.setBounds(100, 100, 870, 420);
                    frame.setLocationRelativeTo(null);
                    frame.setResizable(false);
                    frame.setTitle("East Coast large Cars Annual Truck Show  " + String.valueOf(dTime.getYear()));
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void createNewEntry() throws Exception {
        _ID = jocTable.getRowCount() + 1;

        Entry en = new Entry();

        en.setTruckowner(_createEntryTruckOwner);
        en.setTruckmake(_createEntryTruckMake);
        en.setTruckclass(_createEntryTruckClass);
        en.setVotes(0);
        en.setTruckid(_ID);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShowManager");
        EntryJpaController ejc = new EntryJpaController(emf);

        ejc.create(en);
    }

    /**
     *
     */
    private void createEntryEdit() {
        Entry en = new Entry();

        en.setTruckid(_ID);
        en.setTruckowner(_truckOwner);
        en.setTruckmake(_truckMake);
        en.setTruckclass(_truckClass);
        en.setVotes(_votes);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShowManager");
        EntryJpaController ejc = new EntryJpaController(emf);

        try {
            ejc.edit(en);
            contentPane.remove(jScrollPane1);
            contentPane.repaint();
            contentPane.validate();
            initBinding();
            contentPane.add(jScrollPane1);
        } catch (PreexistingEntityException ex) {
            LOG.log(Level.SEVERE, "Edit FAILED - Entry does not exist", ex);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, "Edit FAILED - See stack trace for details", ex);
        }
    }

    private void createFleetEdit() {
        Fleet ft = new Fleet();

        ft.setFleetid(_fleetID);
        ft.setFleetname(_fleetName);
        ft.setVotes(_fleetVotes);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShowManager");
        FleetJpaController ejc = new FleetJpaController(emf);

        try {
            ejc.edit(ft);
        } catch (PreexistingEntityException ex) {
            LOG.log(Level.SEVERE, "Edit FAILED - Entry does not exist", ex);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, "Edit FAILED - See stack trace for details", ex);
        }
    }

    private void createFleetEntry() {
        _fleetID = jocFleet.getRowCount() + 1;
        _fleetVotes = 0;

        Fleet ft = new Fleet();

        ft.setFleetid(_fleetID);
        ft.setFleetname(_fleetName);
        ft.setVotes(_fleetVotes);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShowManager");
        FleetJpaController ejc = new FleetJpaController(emf);

        try {
            ejc.create(ft);
            contentPane.remove(jScrollPane2);
            contentPane.repaint();
            contentPane.validate();
            bindFleetTable();
            contentPane.add(jScrollPane2);
        } catch (PreexistingEntityException ex) {
            LOG.log(Level.SEVERE, "Edit FAILED - Entry does not exist", ex);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, "Edit FAILED - See stack trace for details", ex);
        }
    }

    /**
     *     @throws HeadlessException
     */
    private void deleteEntry() throws HeadlessException {
        int rw = jocTable.getSelectedRow();

        if (rw > 0) {
            int tmp = (int) jocTable.getModel().getValueAt(rw, 0);
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShowManager");
            EntryJpaController ejc = new EntryJpaController(emf);
            Object[] options = { "Delete the Entry", "DO NOT Delete the Entry" };
            int n = JOptionPane.showOptionDialog(null, "Do you really want to delete the entry?", "Choose carefully",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

            if (n == JOptionPane.YES_OPTION) {
                try {
                    ejc.destroy(tmp);
                    contentPane.remove(jScrollPane1);
                    contentPane.repaint();
                    contentPane.validate();
                    initBinding();
                    contentPane.add(jScrollPane1);
                } catch (NonexistentEntityException e1) {
                    e1.printStackTrace();
                }
            } else {
                return;
            }
        } else {
            JOptionPane.showMessageDialog(null, "No entry was chosen");
        }
    }

    /**
     *     @throws HeadlessException
     */
    private void deleteFleet() throws HeadlessException {
        int rw = jocFleet.getSelectedRow();

        if (rw > 0) {
            int tmp = (int) jocFleet.getModel().getValueAt(rw, 0);
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("ShowManager");
            FleetJpaController ejc = new FleetJpaController(emf);
            Object[] options = { "Delete the Fleet", "DO NOT the Delete Fleet" };
            int n = JOptionPane.showOptionDialog(null, "Do you really want to delete the Fleet?", "Choose carefully",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

            if (n == JOptionPane.YES_OPTION) {
                try {
                    ejc.destroy(tmp);
                    contentPane.remove(jScrollPane2);
                    contentPane.repaint();
                    contentPane.validate();
                    bindFleetTable();
                    contentPane.add(jScrollPane2);
                } catch (NonexistentEntityException e1) {
                    e1.printStackTrace();
                }
            } else {
                return;
            }
        } else {
            JOptionPane.showMessageDialog(null, "No fleet was chosen");
        }
    }

    /**
     * @return the action
     */
    public Action getAction() {
        return action;
    }

    /**
     * @return the actionFleet
     */
    public Action getActionFleet() {
        return actionFleet;
    }

    /**
     *
     */
    private void getEntryTableValues() {
        _ID = (int) jocTable.getModel().getValueAt(tcl.getRow(), 0);
        _votes = (int) jocTable.getModel().getValueAt(tcl.getRow(), 4);
        _truckOwner = (String) jocTable.getModel().getValueAt(tcl.getRow(), 1);
        _truckMake = (String) jocTable.getModel().getValueAt(tcl.getRow(), 2);
        _truckClass = (String) jocTable.getModel().getValueAt(tcl.getRow(), 3);
    }

    private void getFleetTableValues() {
        _fleetVotes = (int) jocFleet.getModel().getValueAt(tclFleet.getRow(), 2);
        _fleetName = (String) jocFleet.getModel().getValueAt(tclFleet.getRow(), 1);
        _fleetID = (int) jocFleet.getModel().getValueAt(tclFleet.getRow(), 0);
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    private void initBinding() {
        jocTable = new JocTable();
        jocTable.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                int tmpCol = jocTable.getSelectedColumn();
                int tmpRow = jocTable.getSelectedRow();

                updateEntryVotes(tmpCol, tmpRow);
            }
        });
        jocTable.setColumnSelectionAllowed(true);
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
        entityManager = java.beans.Beans.isDesignTime()
                        ? null
                        : javax.persistence.Persistence.createEntityManagerFactory("ShowManager").createEntityManager();
        entryQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT e FROM Entry e");
        entryList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : entryQuery.getResultList();
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(
            org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, entryList, jocTable);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding =
            jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckid}"));

        columnBinding.setColumnName("Truck ID");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckowner}"));
        columnBinding.setColumnName("Truck Owner");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckmake}"));
        columnBinding.setColumnName("Truck Make");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckclass}"));
        columnBinding.setColumnName("Truck Class");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${votes}"));
        columnBinding.setColumnName("Votes");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1 = new JScrollPane();
        jScrollPane1.setBounds(5, 5, 503, 206);
        jScrollPane1.setPreferredSize(new Dimension(200, 300));
        jScrollPane1.setViewportView(jocTable);
        jocTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jocTable.getColumnModel().getColumn(0).setMinWidth(70);
        jocTable.getColumnModel().getColumn(0).setPreferredWidth(70);
        jocTable.getColumnModel().getColumn(0).setMaxWidth(70);
        jocTable.getColumnModel().getColumn(1).setMinWidth(150);
        jocTable.getColumnModel().getColumn(1).setPreferredWidth(150);
        jocTable.getColumnModel().getColumn(1).setMaxWidth(150);
        jocTable.getColumnModel().getColumn(2).setMinWidth(80);
        jocTable.getColumnModel().getColumn(2).setPreferredWidth(80);
        jocTable.getColumnModel().getColumn(2).setMaxWidth(80);
        jocTable.getColumnModel().getColumn(3).setMinWidth(80);
        jocTable.getColumnModel().getColumn(3).setPreferredWidth(80);
        jocTable.getColumnModel().getColumn(3).setMaxWidth(80);
        jocTable.getColumnModel().getColumn(4).setMinWidth(70);
        jocTable.getColumnModel().getColumn(4).setPreferredWidth(70);
        jocTable.getColumnModel().getColumn(4).setMaxWidth(70);
    }

    /**
     *
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    private void bindFleetTable() {
        jocFleet = new JocTable();
        jocFleet.setColumnSelectionAllowed(true);
        fleetQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT f FROM Fleet f");
        fleetList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : fleetQuery.getResultList();

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding;

        // Fleet Table
        jTableBindingFleet = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(
            org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, fleetList, jocFleet);
        columnBinding = jTableBindingFleet.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fleetid}"));
        columnBinding.setColumnName("Fleet ID");
        columnBinding.setColumnClass(Integer.class);
        columnBinding =
            jTableBindingFleet.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fleetname}"));
        columnBinding.setColumnName("Fleet Name");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBindingFleet.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${votes}"));
        columnBinding.setColumnName("Votes");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBindingFleet);
        jTableBindingFleet.bind();
        jScrollPane2 = new JScrollPane();
        jocFleet.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                int tmpCol = jocFleet.getSelectedColumn();
                int tmpRow = jocFleet.getSelectedRow();

                updateFleetVotes(tmpRow, tmpCol);
            }
        });
        jScrollPane2.setBounds(513, 5, 343, 206);
        jScrollPane2.setViewportView(jocFleet);
        jocFleet.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jocFleet.getColumnModel().getColumn(0).setMinWidth(70);
        jocFleet.getColumnModel().getColumn(0).setPreferredWidth(70);
        jocFleet.getColumnModel().getColumn(0).setMaxWidth(70);
        jocFleet.getColumnModel().getColumn(1).setMinWidth(150);
        jocFleet.getColumnModel().getColumn(1).setPreferredWidth(150);
        jocFleet.getColumnModel().getColumn(1).setMaxWidth(150);
        jocFleet.getColumnModel().getColumn(2).setMinWidth(70);
        jocFleet.getColumnModel().getColumn(2).setPreferredWidth(70);
        jocFleet.getColumnModel().getColumn(2).setMaxWidth(70);
        jocFleet.setColumnSelectionAllowed(true);
    }

    /**
     * @param action the action to set
     */
    public void setAction(Action action) {
        this.action = action;
    }

    /**
     * @param actionFleet the actionFleet to set
     */
    public void setActionFleet(Action actionFleet) {
        this.actionFleet = actionFleet;
    }

    private void showWinners(String group) {
        Winners win = new Winners();

        win.showWinners(group);
    }

    private void updateEntryVotes(int tmpCol, int tmpRow) {
        if (tmpCol == 4) {
            int tmp = (int) jocTable.getModel().getValueAt(tmpRow, 4);

            tmp += 1;
            jocTable.getModel().setValueAt(tmp, tmpRow, 4);
            _votes = tmp;
            _ID = (int) jocTable.getModel().getValueAt(tmpRow, 0);
            _truckOwner = (String) jocTable.getModel().getValueAt(tmpRow, 1);
            _truckMake = (String) jocTable.getModel().getValueAt(tmpRow, 2);
            _truckClass = (String) jocTable.getModel().getValueAt(tmpRow, 3);
            createEntryEdit();
        }
    }

    private void updateFleetVotes(int tmpRow, int tmpCol) {
        if (tmpCol == 2) {
            int tmp = (int) jocFleet.getModel().getValueAt(tmpRow, 2);

            tmp += 1;
            jocFleet.getModel().setValueAt(tmp, tmpRow, 2);
            _fleetVotes = (int) jocFleet.getModel().getValueAt(tmpRow, 2);
            _fleetName = (String) jocFleet.getModel().getValueAt(tmpRow, 1);
            _fleetID = (int) jocFleet.getModel().getValueAt(tmpRow, 0);
            createFleetEdit();
        }
    }
}


//~ Formatted in DD Std on 13/09/26
TOP

Related Classes of eclc.Main

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.