package beaform.gui.search;

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

import javax.persistence.EntityManager;
import javax.swing.JTextField;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;

import beaform.GraphDbHandlerForJTA;
import beaform.entities.Formula;

public class SearchAction implements ActionListener {

	private final JTextField txtName;

	public SearchAction(JTextField name) {
		this.txtName = name;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		TransactionManager tm = GraphDbHandlerForJTA.getInstance().getTransactionManager();

		try {
			tm.begin();
		}
		catch (NotSupportedException | SystemException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return;
		}

		final EntityManager em = GraphDbHandlerForJTA.getInstance().getNewEntityManager();

		String query = "match (n:Formula { name:'" + this.txtName.getText() + "' }) return n";
		Formula result = (Formula) em.createNativeQuery(query, Formula.class).getSingleResult();
		System.out.println("Found: " + result);

		em.flush();
		em.close();

		try {
			tm.commit();
		}
		catch (SecurityException | IllegalStateException | RollbackException | HeuristicMixedException
						| HeuristicRollbackException | SystemException e1)
		{
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}

}

@@ -94,16 +94,71 @@
 istener;
+%0Aimport java.util.Iterator;%0Aimport java.util.Map.Entry;
 %0A%0Aimport
@@ -1348,16 +1348,360 @@
 sult);%0A%0A
+%09%09System.out.println(%22Printing ingredients...%22);%0A%09%09Iterator%3CEntry%3CString, Formula%3E%3E it = result.getIngredients();%0A%09%09while (it.hasNext()) %7B%0A%09%09%09Entry%3CString, Formula%3E entry = it.next();%0A%0A%09%09%09String amount = entry.getKey();%0A%09%09%09amount = amount.substring(amount.indexOf('%7C') + 1);%0A%09%09%09System.out.println(%22 - %22 + amount + %22 %22 + entry.getValue());%0A%09%09%7D%0A%0A
 %09%09em.flu

Print ingredients as well when searching