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() {
		Formula searchResult;
		try {
			searchResult = this.searchresult.get();
		}
		catch (InterruptedException | ExecutionException e1) {
			LOG.error("An error happened getting the result from the search.", e1);
			return;
		}
		SwingUtilities.invokeLater(new AddFormTreeToGui(searchResult, this.pane));
	}

	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();
		}
	}
}
@@ -768,16 +768,31 @@
 n() %7B%0A%09%09
+try %7B%0A%09%09%09final 
 Formula 
@@ -807,58 +807,111 @@
 sult
-;%0A%09%09try %7B%0A%09%09%09
+ = this.
 search
-R
+r
 esult
- = this.
+.get();%0A%09%09%09SwingUtilities.invokeLater(new AddFormTreeToGui(
 search
-r
+R
 esult
-.get(
+, this.pane)
 );%0A%09
@@ -1064,85 +1064,8 @@
 %09%09%7D%0A
-%09%09SwingUtilities.invokeLater(new AddFormTreeToGui(searchResult, this.pane));%0A
 %09%7D%0A%0A

Make the code more compact