<commit_before>package org.ensembl.healthcheck.eg_gui;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;

import org.ensembl.healthcheck.DatabaseRegistry;
import org.ensembl.healthcheck.DatabaseRegistryEntry;
import org.ensembl.healthcheck.configuration.ConfigureHost;
import org.ensembl.healthcheck.eg_gui.TestProgressDialog;
import org.ensembl.healthcheck.testcase.EnsTestCase;
import org.ensembl.healthcheck.testcase.PerlScriptConfig;
import org.ensembl.healthcheck.util.DBUtils;

/**
 * 
 * <p>
 * 	Collection of static methods. The actionPerformed method in the 
 * GuiGroupTestRunnerFrame delegates here. It is a collection of code
 * that executes actions the user requested. Put here so it won't clutter
 * the code in GuiGroupTestRunnerFrame.
 * </p>
 * 
 * @author michael
 *
 */
public class GuiTestRunnerFrameActionPerformer {

	/**
	 * <p>
	 * 	This is called when the user has selected a different database server.
	 * </p>
	 * 
	 * <p>
	 * 	Resets the databaseTabbedPane pane with dbDetails. The DBUtils
	 * object is reset in case it was used for accessing a different database
	 * server before this one.
	 * </p>
	 * 
	 * @param databaseTabbedPane
	 * @param dbDetails
	 * 
	 */
	public static void setupDatabasePane(
			DatabaseTabbedPane databaseTabbedPane,
			ConfigureHost dbDetails
	) {
		DBUtils.initialise();
		DBUtils.setHostConfiguration(dbDetails);
		
		List<String> regexps = new ArrayList<String>();
		regexps.add(".*");

		DatabaseRegistry databaseRegistry = new DatabaseRegistry(regexps, null,
				null, false);
		// Should throw an exception which can be caught and displayed 
		// something in a dialog box.
		//
		//if (databaseRegistry.getEntryCount() == 0) {
		//	logger.warning("Warning: no databases found!");
		//}
		
		databaseTabbedPane.init(databaseRegistry);			
		databaseTabbedPane.repaint();
	}

	/**
	 * <p>
	 * 	Finds out which tests the user wants to run and runs them.
	 * </p>
	 * 
	 * @param listOfTestsToBeRun
	 * @param databases
	 * @param testProgressDialog
	 * 
	 */
	public static Thread runSelectedTests(
			final JList listOfTestsToBeRun,
			final DatabaseRegistryEntry[] databases,
			final TestProgressDialog testProgressDialog,
			final JComponent resultDisplayComponent,
			final String PERL5LIB,
			final PerlScriptConfig psc,
			final GuiLogHandler guiLogHandler
	) {
		
		Object[] whatsthis = listOfTestsToBeRun.getSelectedValues();
		
		// Awkward doing this with a loop, but necessary. This won't work:
		//<commit_msg>Put connecting to a db server and loading the databases into a separate thread so the gui remains responsive during that time<commit_after>package org.ensembl.healthcheck.eg_gui;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListModel;

import org.ensembl.healthcheck.DatabaseRegistry;
import org.ensembl.healthcheck.DatabaseRegistryEntry;
import org.ensembl.healthcheck.configuration.ConfigureHost;
import org.ensembl.healthcheck.eg_gui.TestProgressDialog;
import org.ensembl.healthcheck.testcase.EnsTestCase;
import org.ensembl.healthcheck.testcase.PerlScriptConfig;
import org.ensembl.healthcheck.util.DBUtils;

/**
 * 
 * <p>
 * 	Collection of static methods. The actionPerformed method in the 
 * GuiGroupTestRunnerFrame delegates here. It is a collection of code
 * that executes actions the user requested. Put here so it won't clutter
 * the code in GuiGroupTestRunnerFrame.
 * </p>
 * 
 * @author michael
 *
 */
public class GuiTestRunnerFrameActionPerformer {

	/**
	 * <p>
	 * 	This is called when the user has selected a different database server.
	 * </p>
	 * 
	 * <p>
	 * 	Resets the databaseTabbedPane pane with dbDetails. The DBUtils
	 * object is reset in case it was used for accessing a different database
	 * server before this one.
	 * </p>
	 * 
	 * @param databaseTabbedPane
	 * @param dbDetails
	 * 
	 */
	public static Thread setupDatabasePane(
			final DatabaseTabbedPane databaseTabbedPane,
			ConfigureHost dbDetails
	) {
		DBUtils.initialise();
		DBUtils.setHostConfiguration(dbDetails);
		
		final List<String> regexps = new ArrayList<String>();
		regexps.add(".*");

		Thread t = new Thread() {

			public void run() {
			
				DatabaseRegistry databaseRegistry = new DatabaseRegistry(regexps, null,
						null, false);
				// Should throw an exception which can be caught and displayed 
				// something in a dialog box.
				//
				//if (databaseRegistry.getEntryCount() == 0) {
				//	logger.warning("Warning: no databases found!");
				//}
				
				databaseTabbedPane.init(databaseRegistry);
				databaseTabbedPane.repaint();
			}
		};
		databaseTabbedPane.setMessage(
			"Changing database server", 
			"Connecting and loading database entries, please wait"
		);
		t.start();
		return t;
	}

	/**
	 * <p>
	 * 	Finds out which tests the user wants to run and runs them.
	 * </p>
	 * 
	 * @param listOfTestsToBeRun
	 * @param databases
	 * @param testProgressDialog
	 * 
	 */
	public static Thread runSelectedTests(
			final JList listOfTestsToBeRun,
			final DatabaseRegistryEntry[] databases,
			final TestProgressDialog testProgressDialog,
			final JComponent resultDisplayComponent,
			final String PERL5LIB,
			final PerlScriptConfig psc,
			final GuiLogHandler guiLogHandler
	) {
		
		Object[] whatsthis = listOfTestsToBeRun.getSelectedValues();
		
		// Awkward doing this with a loop, but necessary. This won't work:
		//
{'fraction_non_alphanumeric': 0.09098816979819067, 'fraction_numerical': 0.0006958942240779402, 'mean_word_length': 3.9220890410958904, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7061468', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1692, 'n_words': 494}