All pastes #2108416 Raw Edit

Untitled

public java v1 · immutable
#2108416 ·published 2012-01-31 23:43 UTC
rendered paste body
package supermarket.gui;import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import net.miginfocom.swing.MigLayout;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.JComboBox;import javax.swing.DefaultComboBoxModel;import supermarket.domain.Product;import supermarket.domain.StaffExperienceType;import supermarket.domain.StaffProfile;import supermarket.domain.dao.StaffProfileDao;import supermarket.gui.exceptions.NullInputException;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.math.BigDecimal;import javax.swing.JScrollPane;public class StaffProfileEditor extends JPanel {    private JTextField txtId;    private JTextField txtLongQueueSize;    private JTextField txtNormalServeSpeed;    private JTextField txtImprovedServeSpeed;    private JComboBox comboExperience;    private StaffProfilesTableModel staffTableModel;    private JTable staffTable;    /**     * Create the frame.     */    public StaffProfileEditor() {                setLayout(new MigLayout("", "[][grow]", "[grow][][][][][][]"));                JScrollPane scrollPaneStaffData = new JScrollPane();        add(scrollPaneStaffData, "cell 0 0 2 1,grow");                this.staffTableModel = new StaffProfilesTableModel();        this.staffTable = new JTable(staffTableModel);        this.staffTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {            @Override            public void valueChanged(ListSelectionEvent e) {                if(!e.getValueIsAdjusting() && !staffTable.getSelectionModel().isSelectionEmpty()) {                    int selectedRowIndex = staffTable.getSelectedRow();                    StaffProfile selectedStaffProfile = staffTableModel.getStaffProfileAtRow(selectedRowIndex);                    txtId.setText("" + selectedStaffProfile.getId());                    comboExperience.setSelectedItem(selectedStaffProfile.getExperience());                    txtLongQueueSize.setText("" + selectedStaffProfile.getLongQueueSize());                    txtNormalServeSpeed.setText("" + selectedStaffProfile.getNormalServeSpeed());                    txtImprovedServeSpeed.setText("" + selectedStaffProfile.getImprovedServeSpeed());                }            }        });        scrollPaneStaffData.setViewportView(staffTable);                JLabel lblId = new JLabel("Id: ");        add(lblId, "cell 0 1,alignx trailing");                txtId = new JTextField();        txtId.setEnabled(false);        txtId.setEditable(false);        add(txtId, "cell 1 1,growx");        txtId.setColumns(10);                JLabel lblExperience = new JLabel("Experience");        add(lblExperience, "cell 0 2,alignx trailing");                comboExperience = new JComboBox();        comboExperience.setModel(new DefaultComboBoxModel(StaffExperienceType.values()));        add(comboExperience, "cell 1 2,growx");                JLabel lblLongQueueSize = new JLabel("Long Queue Size: ");        add(lblLongQueueSize, "cell 0 3,alignx trailing");                txtLongQueueSize = new JTextField();        add(txtLongQueueSize, "cell 1 3,growx");        txtLongQueueSize.setColumns(10);                JLabel lblNormalServeSpeed = new JLabel("Normal Serve Speed: ");        add(lblNormalServeSpeed, "cell 0 4,alignx trailing");                txtNormalServeSpeed = new JTextField();        add(txtNormalServeSpeed, "cell 1 4,growx");        txtNormalServeSpeed.setColumns(10);                JLabel lblImprovedServeSpeed = new JLabel("Improved Serve Speed: ");        add(lblImprovedServeSpeed, "cell 0 5,alignx trailing");                txtImprovedServeSpeed = new JTextField();        add(txtImprovedServeSpeed, "cell 1 5,growx");        txtImprovedServeSpeed.setColumns(10);                JButton btnAddStaffProfile = new JButton("Add");        btnAddStaffProfile.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent arg0) {                try {                    addStaffProfile();                } catch (NullInputException ex) {                    JOptionPane.showMessageDialog(null, ex.getMessage(), "look!",JOptionPane.ERROR_MESSAGE);                }            }        });                JButton btnDelete = new JButton("Delete");        btnDelete.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent arg0) {                removeStaffProfile();            }        });        add(btnDelete, "flowx,cell 1 6");                JButton btnModify = new JButton("Modify");        btnModify.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent arg0) {                modifyStaffProfile();            }        });        add(btnModify, "cell 1 6");        add(btnAddStaffProfile, "cell 1 6,aligny top");        }      private void addStaffProfile() throws NullInputException {        StaffProfile tempStaffProfile = new StaffProfile();                       if(txtLongQueueSize.getText().length() == 0){        	throw new NullInputException("No long Queue Size");        }        if(txtNormalServeSpeed.getText().length() == 0){        	throw new NullInputException("No Normal Serve Speed");        }        if(txtImprovedServeSpeed.getText().length() == 0){        	throw new NullInputException("No Improved Serve Speed");        }                    try{            tempStaffProfile.setExperience((StaffExperienceType)comboExperience.getSelectedItem());            tempStaffProfile.setLongQueueSize(Integer.parseInt(txtLongQueueSize.getText()));            tempStaffProfile.setNormalServeSpeed(Float.parseFloat(txtNormalServeSpeed.getText()));            tempStaffProfile.setImprovedServeSpeed(Float.parseFloat(txtImprovedServeSpeed.getText()));                    }        catch(NullInputException e){        	JOptionPane.showMessageDialog(null, "Nothing has been entered", "look!",JOptionPane.ERROR_MESSAGE);        }                        this.staffTableModel.addStaffProfile(tempStaffProfile);      }    private void removeStaffProfile() {        this.staffTableModel.removeStaffProfile(this.staffTable.getSelectedRow());    }    private void modifyStaffProfile() {        StaffProfile tempStaffProfile = this.staffTableModel.getStaffProfileAtRow(this.staffTable.getSelectedRow());        tempStaffProfile.setExperience((StaffExperienceType)comboExperience.getSelectedItem());        tempStaffProfile.setLongQueueSize(Integer.parseInt(txtLongQueueSize.getText()));        tempStaffProfile.setNormalServeSpeed(Float.parseFloat(txtNormalServeSpeed.getText()));        tempStaffProfile.setImprovedServeSpeed(Float.parseFloat(txtImprovedServeSpeed.getText()));        this.staffTableModel.updateStaffProfile(tempStaffProfile);    }}