package view;

import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import controller.EnterKeyListenerForButtons;
import model.CourierSystem;
import model.Employee;
import net.miginfocom.swing.MigLayout;

public class EmployeeManagement extends Container {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTable table;
	EmployeeTableModel employeeTable;

	public EmployeeManagement(CourierSystem data) {
		employeeTable = new EmployeeTableModel(data.Employees);
		setLayout(new MigLayout("", "[grow][50%][grow][10]", "[25][40][5][grow][][20]"));

		JLabel lblEmployeeManagement = new JLabel("Employee Management");
		lblEmployeeManagement.setFont(new Font("Tahoma", Font.BOLD, 16));
		add(lblEmployeeManagement, "cell 0 0 3 1,alignx center,aligny center");

		JButton btnAddEmployee = new JButton("Add Employee");
		add(btnAddEmployee, "cell 0 1,alignx center,aligny bottom");
		btnAddEmployee.addKeyListener(new EnterKeyListenerForButtons(btnAddEmployee));

		JButton btnSaveChanges = new JButton("Save Changes");
		add(btnSaveChanges, "cell 2 1");
		btnSaveChanges.addKeyListener(new EnterKeyListenerForButtons(btnSaveChanges));

		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, "cell 0 3 3 1,grow");
		table = new JTable(employeeTable);
		table.setCellSelectionEnabled(true);
		scrollPane.setViewportView(table);
		table.setColumnSelectionAllowed(true);

		JLabel lblNewLabel = new JLabel(" ");
		add(lblNewLabel, "cell 0 4");

		btnAddEmployee.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				employeeTable.addRow(new Employee());
			}
		});

		btnSaveChanges.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					data.SaveEmployees();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		});
	}
}

@@ -186,23 +186,93 @@
 x.swing.
-JButton
+DefaultCellEditor;%0D%0Aimport javax.swing.JButton;%0D%0Aimport javax.swing.JComboBox
 ;%0D%0Aimpor
@@ -453,24 +453,52 @@
 .Employee;%0D%0A
+import model.EmployeeRole;%0D%0A
 import net.m
@@ -676,44 +676,8 @@
 le;%0D
-%0A%09EmployeeTableModel employeeTable;%0D
 %0A%0D%0A%09
@@ -725,18 +725,37 @@
 ata) %7B%0D%0A
-
 %09%09
+EmployeeTableModel 
 employee
@@ -1731,24 +1731,340 @@
 d(true);%0D%0A%0D%0A
+%09%09JComboBox%3CEmployeeRole%3E roleComboBox = new JComboBox%3CEmployeeRole%3E();%0D%0A%09%09roleComboBox.addItem(EmployeeRole.Administrator);%0D%0A%09%09roleComboBox.addItem(EmployeeRole.Courier);%0D%0A%09%09roleComboBox.addItem(EmployeeRole.OrderTaker);%0D%0A%09%09table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(roleComboBox));%0D%0A%0D%0A
 %09%09JLabel lbl

allow role editing