package devopsdistilled.operp.client.items.panes;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.inject.Inject;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;
import devopsdistilled.operp.client.abstracts.SubTaskPane;
import devopsdistilled.operp.client.items.exceptions.EntityNameExistsException;
import devopsdistilled.operp.client.items.exceptions.NullFieldException;
import devopsdistilled.operp.client.items.panes.controllers.EditManufacturerPaneController;
import devopsdistilled.operp.client.items.panes.details.ManufacturerDetailsPane;
import devopsdistilled.operp.client.items.panes.models.observers.EditManufacturerPaneModelObserver;
import devopsdistilled.operp.server.data.entity.items.Manufacturer;

public class EditManufacturerPane extends SubTaskPane implements
		EditManufacturerPaneModelObserver {

	@Inject
	private EditManufacturerPaneController controller;

	@Inject
	private ManufacturerDetailsPane manufacturerDetailsPane;

	private Manufacturer manufacturer;

	private final JPanel pane;
	private final JTextField manufacturerIdField;
	private final JTextField manufacturerNameField;

	public EditManufacturerPane() {
		pane = new JPanel();
		pane.setLayout(new MigLayout("", "[][grow]", "[][][][]"));

		JLabel lblManufacturerId = new JLabel("Manufacturer ID");
		pane.add(lblManufacturerId, "cell 0 0,alignx trailing");

		manufacturerIdField = new JTextField();
		manufacturerIdField.setEditable(false);
		pane.add(manufacturerIdField, "cell 1 0,growx");
		manufacturerIdField.setColumns(10);

		JLabel lblManufacturerName = new JLabel("Manufacturer Name");
		pane.add(lblManufacturerName, "cell 0 1,alignx trailing");

		manufacturerNameField = new JTextField();
		pane.add(manufacturerNameField, "cell 1 1,growx");
		manufacturerNameField.setColumns(10);

		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				getDialog().dispose();
			}
		});
		pane.add(btnCancel, "flowx,cell 1 3");

		JButton btnUpdate = new JButton("Update");
		btnUpdate.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String manufacturerName = manufacturerNameField.getText()
						.trim();
				manufacturer.setManufacturerName(manufacturerName);

				try {
					controller.validate(manufacturer);
					manufacturer = controller.save(manufacturer);

					getDialog().dispose();
					manufacturerDetailsPane.show(manufacturer);

				} catch (NullFieldException | EntityNameExistsException e1) {
					JOptionPane.showMessageDialog(getPane(), e1.getMessage());
				}

			}
		});
		pane.add(btnUpdate, "cell 1 3");
	}

	@Override
	public JComponent getPane() {
		return pane;
	}

	@Override
	public void updateEntity(Manufacturer manufacturer) {
		this.manufacturer = manufacturer;
		manufacturerIdField
				.setText(manufacturer.getManufacturerId().toString());
		manufacturerNameField.setText(manufacturer.getManufacturerName());
	}

}

@@ -2382,24 +2382,188 @@
 nEvent e) %7B%0A
+%09%09%09%09Long manufacturerId = manufacturer.getManufacturerId();%0A%09%09%09%09Manufacturer manufacturer = new Manufacturer();%0A%09%09%09%09manufacturer.setManufacturerId(manufacturerId);%0A
 %09%09%09%09String m
@@ -3003,32 +3003,266 @@
 %09%09%09%7D%0A%0A%09%09%09%7D%0A%09%09%7D);
+%0A%0A%09%09JButton btnReset = new JButton(%22Reset%22);%0A%09%09btnReset.addActionListener(new ActionListener() %7B%0A%09%09%09@Override%0A%09%09%09public void actionPerformed(ActionEvent e) %7B%0A%09%09%09%09updateEntity(manufacturer);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09pane.add(btnReset, %22cell 1 3%22);
 %0A%09%09pane.add(btnU

Add "Reset" to Manufacturer