package beaform.gui.search;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import beaform.entities.Formula;
import beaform.gui.FormulaTree;

public final class RenderSearchResult implements Runnable { // NOPMD by steven on 5/16/16 4:31 PM

	/** A logger */
	private static final Logger LOG = LoggerFactory.getLogger(RenderSearchResult.class);
	private final transient Future<Formula> searchresult;
	private final transient JPanel pane;

	public RenderSearchResult(final Future<Formula> searchresult, final JPanel pane) {
		this.searchresult = searchresult;
		this.pane = pane;
	}

	@Override
	public void run() {
		try {
			final Formula searchResult = this.searchresult.get();
			SwingUtilities.invokeLater(new AddFormTreeToGui(searchResult, this.pane));
		}
		catch (InterruptedException | ExecutionException e1) {
			LOG.error("An error happened getting the result from the search.", e1);
			return;
		}
	}

	public static final class AddFormTreeToGui implements Runnable { // NOPMD by steven on 5/16/16 4:30 PM
		/** The index of the formula tree on the target panel */
		private static final int FORMULA_TREE_LOC = 3;

		private final Formula searchResult;
		private final JPanel pane;

		public AddFormTreeToGui(final Formula searchResult, final JPanel pane) {
			this.searchResult = searchResult;
			this.pane = pane;
		}

		@Override
		public void run() {
			final FormulaTree formulaTree = new FormulaTree(this.searchResult);
			if (this.pane.getComponentCount() > FORMULA_TREE_LOC) {
				this.pane.remove(FORMULA_TREE_LOC);
			}
			this.pane.add(formulaTree);
			this.pane.revalidate();
		}
	}
}
@@ -294,16 +294,128 @@
 aTree;%0A%0A
+/**%0A * This class is used to render the result of a formula search in the GUI.%0A *%0A * @author Steven Post%0A *%0A */%0A
 public f
@@ -469,46 +469,8 @@
 le %7B
- // NOPMD by steven on 5/16/16 4:31 PM
 %0A%0A%09/
@@ -569,16 +569,57 @@
 .class);
+%0A%0A%09/** The task with the search result */
 %0A%09privat
@@ -665,16 +665,42 @@
 hresult;
+%0A%0A%09/** The target panel */
 %0A%09privat
@@ -731,16 +731,126 @@
  pane;%0A%0A
+%09/**%0A%09 * Constructor.%0A%09 * @param searchresult The task for the search.%0A%09 * @param pane The target panel.%0A%09 */%0A
 %09public 
@@ -985,16 +985,62 @@
 ne;%0A%09%7D%0A%0A
+%09/**%0A%09 * Invoked when the action occurs.%0A%09 */%0A
 %09@Overri
@@ -1361,16 +1361,97 @@
 %09%09%7D%0A%09%7D%0A%0A
+%09/**%0A%09 * A task to to the actual rendering.%0A%09 *%0A%09 * @author Steven Post%0A%09 *%0A%09 */%0A
 %09public 
@@ -1511,46 +1511,9 @@
 le %7B
- // NOPMD by steven on 5/16/16 4:30 PM
+%0A
 %0A%09%09/
@@ -1618,16 +1618,50 @@
 C = 3;%0A%0A
+%09%09/** The result of the search */%0A
 %09%09privat
@@ -1689,16 +1689,43 @@
 hResult;
+%0A%0A%09%09/** The target panel */
 %0A%09%09priva
@@ -1747,16 +1747,130 @@
  pane;%0A%0A
+%09%09/**%0A%09%09 * Constructor.%0A%09%09 * @param searchResult the result of the search%0A%09%09 * @param pane the target panel%0A%09%09 */%0A
 %09%09public
@@ -1999,16 +1999,65 @@
 e;%0A%09%09%7D%0A%0A
+%09%09/**%0A%09%09 * Invoked when the action occurs.%0A%09%09 */%0A
 %09%09@Overr

Add JavaDoc