<commit_before>package data;

import gmmlVision.GmmlVision;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import util.TableColumnResizer;

/**
 * This class is a {@link Wizard} that guides the user trough the process to
 * create an expression dataset from a delimited text file
 */
public class ImportExprDataWizard extends Wizard {
	ImportInformation importInformation;

	public ImportExprDataWizard() {
		importInformation = new ImportInformation();

		setWindowTitle("Create an expression dataset");
		setNeedsProgressMonitor(true);
	}

	public void addPages() {
		addPage(new FilePage());
		addPage(new HeaderPage());
		addPage(new ColumnPage());
		addPage(new ImportPage());
	}

	boolean importFinished;

	public boolean performFinish() {
		if (!importFinished) {
			ImportPage ip = (ImportPage) getPage("ImportPage");
			getContainer().showPage(ip);
			try {
				// Start import process
				getContainer().run(true, true,
						new GmmlGex.ImportRunnableWithProgress(
								importInformation,
								(ImportPage) getPage("ImportPage")));
			} catch (Exception e) {
				GmmlVision.log.error("while running expression data import process: " + e.getMessage(), e);
			} // TODO: handle exception
			ip.setTitle("Import finished");
			ip.setDescription("Press finish to return to Gmml-Visio");
			importFinished = true;
			return false;
		}
		if (importFinished
				&& getContainer().getCurrentPage().getName().equals(
						"ImportPage")) {
			return true;
		}
		return false;
	}

	public boolean performCancel() {
		return true; // Do nothing, just close wizard
	}

	/**
	 * This is the wizard page to specify the location of the text file
	 * containing expression data and the location to store the new expression
	 * dataset
	 */
	public class FilePage extends WizardPage {
		boolean txtFileComplete;

		boolean gexFileComplete;

		public FilePage() {
			super("FilePage");
			setTitle("File locations");
			setDescription("Specify the locations of the file containing the expression data "
					+ "and where to store the expression dataset");
			setPageComplete(false);
		}

		public void createControl(Composite parent) {
			final FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);

			Composite composite = new Composite(parent, SWT.NULL);
			composite.setLayout(new GridLayout(2, false));

			GridData labelGrid = new GridData(GridData.FILL_HORIZONTAL);
			labelGrid.horizontalSpan = 2;

			Label txtLabel = new Label(composite, SWT.FLAT);
			txtLabel
					.setText("Specify location of text file containing expression data");
			txtLabel.setLayoutData(labelGrid);

			final Text txtText = new Text(composite, SWT.SINGLE | SWT.BORDER);
			txtText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			Button txtButton = new Button(composite, SWT.PUSH);
			txtButton.setText("Browse");

			Label gexLabel = new Label(composite, SWT.FLAT);
			gexLabel.setText("Specify location to save the expression dataset");
			gexLabel.setLayoutData(labelGrid);

			final Text gexText = new Text(composite, SWT.SINGLE | SWT.BORDER);
			gexText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			Button gexButton = new Button(composite, SWT.PUSH);
			gexButton.setText("Browse");

			txtButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					fileDialog
							.setText("Select tab delimited text file containing expression data");
					fileDialog.setFilterExtensions(new String[] { "*.txt",
							"*.*" });
					fileDialog.setFilterNames(new String[] { "Text file",
							"All files" });
					String file = fileDialog.open();
					if (file != null) {
						txtText.setText(file);<commit_msg>- file dialog in ImportExprDataWizard didn't point to default data directory<commit_after>package data;

import gmmlVision.GmmlVision;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import preferences.GmmlPreferences;

import util.TableColumnResizer;

/**
 * This class is a {@link Wizard} that guides the user trough the process to
 * create an expression dataset from a delimited text file
 */
public class ImportExprDataWizard extends Wizard {
	ImportInformation importInformation;

	public ImportExprDataWizard() {
		importInformation = new ImportInformation();

		setWindowTitle("Create an expression dataset");
		setNeedsProgressMonitor(true);
	}

	public void addPages() {
		addPage(new FilePage());
		addPage(new HeaderPage());
		addPage(new ColumnPage());
		addPage(new ImportPage());
	}

	boolean importFinished;

	public boolean performFinish() {
		if (!importFinished) {
			ImportPage ip = (ImportPage) getPage("ImportPage");
			getContainer().showPage(ip);
			try {
				// Start import process
				getContainer().run(true, true,
						new GmmlGex.ImportRunnableWithProgress(
								importInformation,
								(ImportPage) getPage("ImportPage")));
			} catch (Exception e) {
				GmmlVision.log.error("while running expression data import process: " + e.getMessage(), e);
			} // TODO: handle exception
			ip.setTitle("Import finished");
			ip.setDescription("Press finish to return to Gmml-Visio");
			importFinished = true;
			return false;
		}
		if (importFinished
				&& getContainer().getCurrentPage().getName().equals(
						"ImportPage")) {
			return true;
		}
		return false;
	}

	public boolean performCancel() {
		return true; // Do nothing, just close wizard
	}

	/**
	 * This is the wizard page to specify the location of the text file
	 * containing expression data and the location to store the new expression
	 * dataset
	 */
	public class FilePage extends WizardPage {
		boolean txtFileComplete;

		boolean gexFileComplete;

		public FilePage() {
			super("FilePage");
			setTitle("File locations");
			setDescription("Specify the locations of the file containing the expression data "
					+ "and where to store the expression dataset");
			setPageComplete(false);
		}

		public void createControl(Composite parent) {
			final FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);

			Composite composite = new Composite(parent, SWT.NULL);
			composite.setLayout(new GridLayout(2, false));

			GridData labelGrid = new GridData(GridData.FILL_HORIZONTAL);
			labelGrid.horizontalSpan = 2;

			Label txtLabel = new Label(composite, SWT.FLAT);
			txtLabel
					.setText("Specify location of text file containing expression data");
			txtLabel.setLayoutData(labelGrid);

			final Text txtText = new Text(composite, SWT.SINGLE | SWT.BORDER);
			txtText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			Button txtButton = new Button(composite, SWT.PUSH);
			txtButton.setText("Browse");

			Label gexLabel = new Label(composite, SWT.FLAT);
			gexLabel.setText("Specify location to save the expression dataset");
			gexLabel.setLayoutData(labelGrid);

			final Text gexText = new Text(composite, SWT.SINGLE | SWT.BORDER);
			gexText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
			Button gexButton = new Button(composite, SWT.PUSH);
			gexButton.setText("Browse");

			txtButton.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					fileDialog
							.setText("Select tab delimited text file containing expression data");
					fileDialog.setFilterExtensions(new String[] { "*.txt",
							"*.*" });
					fileDialog.setFilterNames(new String[] { "Text file",
							"All files" });
					fileDialog.setFilterPath(GmmlVision.getPreferences().getString(GmmlPreferences.PREF_DIR_EXPR));
					String file = fileDialog.open();
					if (file != null) {
						txtText.setText(file);
{'fraction_non_alphanumeric': 0.1087066437455759, 'fraction_numerical': 0.0004044898371928405, 'mean_word_length': 4.531319910514541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4720119', 'n_tokens_mistral': 3394, 'n_tokens_neox': 2959, 'n_words': 724}