package devopsdistilled.operp.client.abstracts;

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

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import devopsdistilled.operp.server.data.entity.Entiti;

public abstract class AbstractEntityDetailsPane<E extends Entiti<?>, EC extends EntityController<E>> {

	protected final JDialog dialog;

	protected JPanel btnPanel;

	public AbstractEntityDetailsPane() {
		dialog = new JDialog();
		dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		dialog.setTitle(getTitle());
		dialog.setSize(400, 300);
		dialog.getContentPane().setLayout(new MigLayout("fill", "[]", "[]"));

		btnPanel = new JPanel();
		btnPanel.setLayout(new MigLayout(""));

		JButton btnDelete = new JButton("Delete");
		btnDelete.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
						getPane(), "Delete " + getEntity() + " ?", "Delete ?",
						JOptionPane.YES_NO_OPTION)) {

					getDialog().dispose();
					getEntityController().delete(getEntity());
				}
			}

		});
		btnPanel.add(btnDelete);

		JButton btnEdit = new JButton("Edit");
		btnEdit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				getDialog().dispose();
				getEntityController().edit(getEntity());
			}
		});
		btnPanel.add(btnEdit);

		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				getDialog().dispose();
			}
		});
		btnPanel.add(btnOk);
	}

	public abstract EC getEntityController();

	protected abstract E getEntity();

	public abstract JPanel getPane();

	public abstract void show(E entity);

	public abstract String getTitle();

	public JDialog getDialog() {
		return dialog;
	}

	public void showDetailsPane(JPanel detailsPane) {
		getPane().add(btnPanel, "south, pad 20 100 20 20");
		dialog.getContentPane().add(getPane(), "grow");
		getDialog().setVisible(true);
	}
}

@@ -144,16 +144,47 @@
 Button;%0A
+import javax.swing.JComponent;%0A
 import j
@@ -526,16 +526,46 @@
 Panel;%0A%0A
+%09protected JComponent owner;%0A%0A
 %09public 
@@ -1796,24 +1796,92 @@
 btnOk);%0A%09%7D%0A%0A
+%09public void setOwner(JComponent owner) %7B%0A%09%09this.owner = owner;%0A%09%7D%0A%0A
 %09public abst
@@ -2287,21 +2287,123 @@
 .set
-Visible(true)
+LocationRelativeTo(getOwner());%0A%09%09getDialog().setVisible(true);%0A%09%7D%0A%0A%09private JComponent getOwner() %7B%0A%09%09return owner
 ;%0A%09%7D

Add owner field to set location of dialog