package transformation.associationtags.buttonlisteners;

import transformation.associationtags.AssociationTagWindow;

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

import javax.swing.JButton;
import javax.swing.JFrame;

public class EditCancelButtonListener implements ActionListener {
	
	AssociationTagWindow window;
	
	public EditCancelButtonListener(AssociationTagWindow window) {
		this.window = window;
	}

	/**
	 * Cancels the changes made to an association tag,
	 * closes the editing form and opens the association tags list
	 */
	public void actionPerformed(ActionEvent e) {
		Container container = ((JButton) e.getSource()).getParent();
		while (container.getClass() != JFrame.class) {
			container = container.getParent();
		}
		JFrame frame = (JFrame) container;
		frame.dispose();
		window.showTags();
	}

}
