<commit_before>package org.pentaho.di.spoon.delegates;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.NotePadMeta;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.dialog.ErrorDialog;
import org.pentaho.di.core.dialog.ShowMessageDialog;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.gui.GUIResource;
import org.pentaho.di.core.gui.Point;
import org.pentaho.di.core.gui.SpoonInterface;
import org.pentaho.di.core.undo.TransAction;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.job.JobEntryLoader;
import org.pentaho.di.job.JobEntryType;
import org.pentaho.di.job.JobHopMeta;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.job.JobPlugin;
import org.pentaho.di.job.entries.special.JobEntrySpecial;
import org.pentaho.di.job.entries.sql.JobEntrySQL;
import org.pentaho.di.job.entries.trans.JobEntryTrans;
import org.pentaho.di.job.entry.JobEntryCopy;
import org.pentaho.di.job.entry.JobEntryDialogInterface;
import org.pentaho.di.job.entry.JobEntryInterface;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectory;
import org.pentaho.di.spoon.Messages;
import org.pentaho.di.spoon.Spoon;
import org.pentaho.di.spoon.TabMapEntry;
import org.pentaho.di.spoon.job.JobGraph;
import org.pentaho.di.spoon.job.JobHistory;
import org.pentaho.di.spoon.job.JobHistoryRefresher;
import org.pentaho.di.spoon.job.JobLog;
import org.pentaho.di.spoon.wizards.RipDatabaseWizardPage1;
import org.pentaho.di.spoon.wizards.RipDatabaseWizardPage2;
import org.pentaho.di.spoon.wizards.RipDatabaseWizardPage3;
import org.pentaho.di.trans.StepLoader;
import org.pentaho.di.trans.TransHopMeta;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.StepDialogInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.di.trans.steps.tableinput.TableInputMeta;
import org.pentaho.di.trans.steps.tableoutput.TableOutputMeta;
import org.pentaho.xul.swt.tab.TabItem;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class SpoonJobDelegate extends SpoonDelegate
{
	/**
	 * This contains a map between the name of a transformation and the
	 * TransMeta object. If the transformation has no name it will be mapped
	 * under a number [1], [2] etc.
	 */
	private Map<String, JobMeta> jobMap;

	public SpoonJobDelegate(Spoon spoon)
	{
		super(spoon);
		jobMap = new Hashtable<String, JobMeta>();
	}

	public JobEntryCopy newJobEntry(JobMeta jobMeta, String type_desc, boolean openit)
	{
		JobEntryLoader jobLoader = JobEntryLoader.getInstance();
		JobPlugin jobPlugin = null;

		try
		{
			jobPlugin = jobLoader.findJobEntriesWithDescription(type_desc);
			if (jobPlugin == null)
			{
				// Check if it's not START or DUMMY
				if (JobMeta.STRING_SPECIAL_START.equals(type_desc)
						|| JobMeta.STRING_SPECIAL_DUMMY.equals(type_desc))
				{
					jobPlugin = jobLoader.findJobEntriesWithID(JobMeta.STRING_SPECIAL);
				}
			}

			if (jobPlugin != null)
			{
				// Determine name & number for this entry.
				String basename = type_desc;
				int nr = jobMeta.generateJobEntryNameNr(basename);
				String entry_name = basename + " " + nr; //$NON-NLS-1$

				// Generate the appropriate class...
				JobEntryInterface jei = jobLoader.getJobEntryClass(jobPlugin);
				jei.setName(entry_name);

				if (jei.isSpecial())
				{
					if (JobMeta.STRING_SPECIAL_START.equals(type_desc))
					{
						// Check if start is already on the canvas...
						if (jobMeta.findStart() != null)
						{
							JobGraph.showOnlyStartOnceMessage(spoon.getShell());
							return null;
						}
						((JobEntrySpecial) jei).setStart(true);
						jei.setName(JobMeta.STRING_SPECIAL_START);
					}
					if (JobMeta.STRING_SPECIAL_DUMMY.equals(type_desc))
					{
						((JobEntrySpecial) jei).setDummy(true);
						jei.setName(JobMeta.STRING_SPECIAL_DUMMY);
					}
				}

				if (openit)
				{
					JobEntryDialogInterface d = getJobEntryDialog(jei, jobMeta);
					if (d != null && d.open() != null)
					{
						JobEntryCopy jge = new JobEntryCopy();
						jge.setEntry(jei);
						jge.setLocation(50, 50);
						jge.setNr(0);
						jobMeta.addJobEntry(jge);
						spoon.addUndoNew(jobMeta, new JobEntryCopy[] { jge }, new int[] { jobMeta
								.indexOfJobEntry(jge) });
						spoon.refreshGraph();
						spoon.refreshTree();
						return jge;
					} else
					{
						return null;
					}
				} else
				{
					JobEntryCopy jge = new JobEntryCopy();
					jge.setEntry(jei);
					jge.setLocation(50, 50);
					jge.setNr(0);
					jobMeta.addJobEntry(jge);
					spoon.addUndoNew(jobMeta, new JobEntryCopy[] { jge }, new int[] { jobMeta
							.indexOfJobEntry(jge) });
					spoon.refreshGraph();
					spoon.refreshTree();
					return jge;
				}
			} else
			{
				return null;
			}
		} catch (Throwable e)
		{
			new ErrorDialog(
					spoon.getShell(),
					Messages
							.getString("Spoon.ErrorDiaspoon.getLog().UnexpectedErrorCreatingNewJobGraphEntry.Title"), Messages.getString("Spoon.ErrorDiaspoon.getLog().UnexpectedErrorCreatingNewJobGraphEntry.Message"), new Exception(e)); //$NON-NLS-1$ //$NON-NLS-2$
			return null;
		}
	}

	public JobEntryDialogInterface getJobEntryDialog(JobEntryInterface jei, JobMeta jobMeta)
	{

		String dialogClassName = jei.getDialogClassName();
		try
		{
			Class<?> dialogClass;
			Class<?>[] paramClasses = new Class[] { spoon.getShell().getClass(), JobEntryInterface.class,
					Repository.class, JobMeta.class };
			Object[] paramArgs = new Object[] { spoon.getShell(), jei, spoon.getRepository(), jobMeta };
			Constructor<?> dialogConstructor;
			dialogClass = Class.forName(dialogClassName);
			dialogConstructor = dialogClass.getConstructor(paramClasses);
			return (JobEntryDialogInterface) dialogConstructor.newInstance(paramArgs);
		} catch (Throwable t)
		{
			spoon.getLog().logError("Could not create dialog for " + dialogClassName, t.getMessage());
		}
		return null;
	}

	public StepDialogInterface getStepEntryDialog(StepMetaInterface stepMeta, TransMeta transMeta,
			String stepName)
	{

		String dialogClassName = stepMeta.getDialogClassName();
		try
		{
			Class<?> dialogClass;
			Class<?>[] paramClasses = new Class[] { spoon.getShell().getClass(), Object.class,
					TransMeta.class, String.class };
			Object[] paramArgs = new Object[] { spoon.getShell(), stepMeta, transMeta, stepName };
			Constructor<?> dialogConstructor;
			dialogClass = Class.forName(dialogClassName);
			dialogConstructor = dialogClass.getConstructor(paramClasses);
			return (StepDialogInterface) dialogConstructor.newInstance(paramArgs);
		} catch (Throwable t)
		{
			spoon.getLog().logError("Could not create dialog for " + dialogClassName, t.getMessage());
		}
		return null;
	}<commit_msg>Loading plugin dialog using JobEntryLoader.loadClass<commit_after>package org.pentaho.di.spoon.delegates;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.NotePadMeta;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.dialog.ErrorDialog;
import org.pentaho.di.core.dialog.ShowMessageDialog;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.gui.GUIResource;
import org.pentaho.di.core.gui.Point;
import org.pentaho.di.core.gui.SpoonInterface;
import org.pentaho.di.core.undo.TransAction;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.job.JobEntryLoader;
import org.pentaho.di.job.JobEntryType;
import org.pentaho.di.job.JobHopMeta;
import org.pentaho.di.job.JobMeta;
import org.pentaho.di.job.JobPlugin;
import org.pentaho.di.job.entries.special.JobEntrySpecial;
import org.pentaho.di.job.entries.sql.JobEntrySQL;
import org.pentaho.di.job.entries.trans.JobEntryTrans;
import org.pentaho.di.job.entry.JobEntryCopy;
import org.pentaho.di.job.entry.JobEntryDialogInterface;
import org.pentaho.di.job.entry.JobEntryInterface;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectory;
import org.pentaho.di.spoon.Messages;
import org.pentaho.di.spoon.Spoon;
import org.pentaho.di.spoon.TabMapEntry;
import org.pentaho.di.spoon.job.JobGraph;
import org.pentaho.di.spoon.job.JobHistory;
import org.pentaho.di.spoon.job.JobHistoryRefresher;
import org.pentaho.di.spoon.job.JobLog;
import org.pentaho.di.spoon.wizards.RipDatabaseWizardPage1;
import org.pentaho.di.spoon.wizards.RipDatabaseWizardPage2;
import org.pentaho.di.spoon.wizards.RipDatabaseWizardPage3;
import org.pentaho.di.trans.StepLoader;
import org.pentaho.di.trans.TransHopMeta;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.StepDialogInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.di.trans.steps.tableinput.TableInputMeta;
import org.pentaho.di.trans.steps.tableoutput.TableOutputMeta;
import org.pentaho.xul.swt.tab.TabItem;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class SpoonJobDelegate extends SpoonDelegate
{
	/**
	 * This contains a map between the name of a transformation and the
	 * TransMeta object. If the transformation has no name it will be mapped
	 * under a number [1], [2] etc.
	 */
	private Map<String, JobMeta> jobMap;

	public SpoonJobDelegate(Spoon spoon)
	{
		super(spoon);
		jobMap = new Hashtable<String, JobMeta>();
	}

	public JobEntryCopy newJobEntry(JobMeta jobMeta, String type_desc, boolean openit)
	{
		JobEntryLoader jobLoader = JobEntryLoader.getInstance();
		JobPlugin jobPlugin = null;

		try
		{
			jobPlugin = jobLoader.findJobEntriesWithDescription(type_desc);
			if (jobPlugin == null)
			{
				// Check if it's not START or DUMMY
				if (JobMeta.STRING_SPECIAL_START.equals(type_desc)
						|| JobMeta.STRING_SPECIAL_DUMMY.equals(type_desc))
				{
					jobPlugin = jobLoader.findJobEntriesWithID(JobMeta.STRING_SPECIAL);
				}
			}

			if (jobPlugin != null)
			{
				// Determine name & number for this entry.
				String basename = type_desc;
				int nr = jobMeta.generateJobEntryNameNr(basename);
				String entry_name = basename + " " + nr; //$NON-NLS-1$

				// Generate the appropriate class...
				JobEntryInterface jei = jobLoader.getJobEntryClass(jobPlugin);
				jei.setName(entry_name);

				if (jei.isSpecial())
				{
					if (JobMeta.STRING_SPECIAL_START.equals(type_desc))
					{
						// Check if start is already on the canvas...
						if (jobMeta.findStart() != null)
						{
							JobGraph.showOnlyStartOnceMessage(spoon.getShell());
							return null;
						}
						((JobEntrySpecial) jei).setStart(true);
						jei.setName(JobMeta.STRING_SPECIAL_START);
					}
					if (JobMeta.STRING_SPECIAL_DUMMY.equals(type_desc))
					{
						((JobEntrySpecial) jei).setDummy(true);
						jei.setName(JobMeta.STRING_SPECIAL_DUMMY);
					}
				}

				if (openit)
				{
					JobEntryDialogInterface d = getJobEntryDialog(jei, jobMeta);
					if (d != null && d.open() != null)
					{
						JobEntryCopy jge = new JobEntryCopy();
						jge.setEntry(jei);
						jge.setLocation(50, 50);
						jge.setNr(0);
						jobMeta.addJobEntry(jge);
						spoon.addUndoNew(jobMeta, new JobEntryCopy[] { jge }, new int[] { jobMeta
								.indexOfJobEntry(jge) });
						spoon.refreshGraph();
						spoon.refreshTree();
						return jge;
					} else
					{
						return null;
					}
				} else
				{
					JobEntryCopy jge = new JobEntryCopy();
					jge.setEntry(jei);
					jge.setLocation(50, 50);
					jge.setNr(0);
					jobMeta.addJobEntry(jge);
					spoon.addUndoNew(jobMeta, new JobEntryCopy[] { jge }, new int[] { jobMeta
							.indexOfJobEntry(jge) });
					spoon.refreshGraph();
					spoon.refreshTree();
					return jge;
				}
			} else
			{
				return null;
			}
		} catch (Throwable e)
		{
			new ErrorDialog(
					spoon.getShell(),
					Messages
							.getString("Spoon.ErrorDiaspoon.getLog().UnexpectedErrorCreatingNewJobGraphEntry.Title"), Messages.getString("Spoon.ErrorDiaspoon.getLog().UnexpectedErrorCreatingNewJobGraphEntry.Message"), new Exception(e)); //$NON-NLS-1$ //$NON-NLS-2$
			return null;
		}
	}

	public JobEntryDialogInterface getJobEntryDialog(JobEntryInterface jei, JobMeta jobMeta)
	{

		String dialogClassName = jei.getDialogClassName();
		try
		{
			Class<?> dialogClass;
			Class<?>[] paramClasses = new Class[] { spoon.getShell().getClass(), JobEntryInterface.class,
					Repository.class, JobMeta.class };
			Object[] paramArgs = new Object[] { spoon.getShell(), jei, spoon.getRepository(), jobMeta };
			Constructor<?> dialogConstructor;
			dialogClass = JobEntryLoader.getInstance().loadClass(jei.getDescription(),dialogClassName);
			dialogConstructor = dialogClass.getConstructor(paramClasses);
			return (JobEntryDialogInterface) dialogConstructor.newInstance(paramArgs);
		} catch (Throwable t)
		{
			spoon.getLog().logError("Could not create dialog for " + dialogClassName, t.getMessage());
		}
		return null;
	}

	public StepDialogInterface getStepEntryDialog(StepMetaInterface stepMeta, TransMeta transMeta,
			String stepName)
	{

		String dialogClassName = stepMeta.getDialogClassName();
		try
		{
			Class<?> dialogClass;
			Class<?>[] paramClasses = new Class[] { spoon.getShell().getClass(), Object.class,
					TransMeta.class, String.class };
			Object[] paramArgs = new Object[] { spoon.getShell(), stepMeta, transMeta, stepName };
			Constructor<?> dialogConstructor;
			dialogClass = Class.forName(dialogClassName);
			dialogConstructor = dialogClass.getConstructor(paramClasses);
			return (StepDialogInterface) dialogConstructor.newInstance(paramArgs);
		} catch (Throwable t)
		{
			spoon.getLog().logError("Could not create dialog for " + dialogClassName, t.getMessage());
		}
		return null;
	}
{'fraction_non_alphanumeric': 0.11938892253852884, 'fraction_numerical': 0.0026919711959082038, 'mean_word_length': 4.1704940848990955, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7056305', 'n_tokens_mistral': 5648, 'n_tokens_neox': 4858, 'n_words': 860}