<commit_before>/* Copyright (c) 2007 Pentaho Corporation.  All rights reserved. 
 * This software was developed by Pentaho Corporation and is provided under the terms 
 * of the GNU Lesser General Public License, Version 2.1. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.gnu.org/licenses/lgpl-2.1.txt. The Original Code is Pentaho 
 * Data Integration.  The Initial Developer is Pentaho Corporation.
 *
 * Software distributed under the GNU Lesser Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.*/

package org.pentaho.di.ui.core.dialog;

import java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.SourceToTargetMapping;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.ui.core.PropsUI;
import org.pentaho.di.ui.core.database.dialog.DatabaseDialog;
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.core.gui.WindowProperty;
import org.pentaho.di.ui.trans.step.BaseStepDialog;



/**
 * Shows a user 2 lists of strings and allows the linkage of values between values in the 2 lists
 * 
 * @author Matt
 * @since 23-03-2006
 */
public class EnterMappingDialog extends Dialog
{
	private static Class<?> PKG = DatabaseDialog.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$

    public static final String STRING_ORIGIN_SEPARATOR = "            (";
    
    private Label     wlSource;

    private List      wSource;

    private FormData  fdlSource, fdSource;

    private Label     wlSourceAuto;

    private Button    wSourceAuto;

    private FormData  fdlSourceAuto, fdSourceAuto;

    private Label     wlSourceHide;

    private Button    wSourceHide;

    private FormData  fdlSourceHide, fdSourceHide;

    private Label     wlTarget;

    private List      wTarget;

    private FormData  fdlTarget, fdTarget;

    private Label     wlTargetAuto;

    private Button    wTargetAuto;

    private FormData  fdlTargetAuto, fdTargetAuto;

    private Label     wlTargetHide;

    private Button    wTargetHide;

    private FormData  fdlTargetHide, fdTargetHide;

    private Label     wlResult;

    private List      wResult;

    private FormData  fdlResult, fdResult;

    private Button    wAdd;

    private FormData  fdAdd;

    private Button    wDelete;

    private FormData  fdDelete;

    private Button    wOK, wGuess, wCancel;

    private Listener  lsOK, lsGuess, lsCancel;

    private Shell     shell;

    private String    sourceList[];

    private String    targetList[];

    private PropsUI     props;

    private java.util.List<SourceToTargetMapping> mappings;

    /**
     * Create a new dialog allowing the user to enter a mapping
     * 
     * @param parent the parent shell
     * @param source the source values
     * @param target the target values
     */
    public EnterMappingDialog(Shell parent, String source[], String target[])
    {
        this(parent, source, target, new ArrayList<SourceToTargetMapping>());
    }

    /**
     * Create a new dialog allowing the user to enter a mapping
     * 
     * @param parent the parent shell
     * @param source the source values
     * @param target the target values
     * @param mappings the already selected mappings (ArrayList containing <code>SourceToTargetMapping</code>s)
     */
    public EnterMappingDialog(Shell parent, String source[], String target[], java.util.List<SourceToTargetMapping> mappings)
    {
        super(parent, SWT.NONE);
        props = PropsUI.getInstance();
        this.sourceList = source;
        this.targetList = target;

        this.mappings = mappings;
    }
    
    public java.util.List<SourceToTargetMapping> open()
    {
        Shell parent = getParent();
        Display display = parent.getDisplay();

        shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
        props.setLook(shell);
        
        shell.setImage(GUIResource.getInstance().getImageSpoon());

        FormLayout formLayout = new FormLayout();
        formLayout.marginWidth = Const.FORM_MARGIN;
        formLayout.marginHeight = Const.FORM_MARGIN;

        shell.setLayout(formLayout);
        shell.setText(BaseMessages.getString(PKG, "EnterMappingDialog.Title"));
		shell.setImage(GUIResource.getInstance().getImageTransGraph());

        int margin = Const.MARGIN;
        int buttonSpace = 90;

        // Source table
        wlSource = new Label(shell, SWT.NONE);
        wlSource.setText(BaseMessages.getString(PKG, "EnterMappingDialog.SourceFields.Label"));
        props.setLook(wlSource);
        fdlSource = new FormData();
        fdlSource.left = new FormAttachment(0, 0);<commit_msg>PDI-4925 Spoon freezes insert/update & Update step when specifying db connection/schema. Randomly crashes when exiting either step<commit_after>/* Copyright (c) 2007 Pentaho Corporation.  All rights reserved. 
 * This software was developed by Pentaho Corporation and is provided under the terms 
 * of the GNU Lesser General Public License, Version 2.1. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.gnu.org/licenses/lgpl-2.1.txt. The Original Code is Pentaho 
 * Data Integration.  The Initial Developer is Pentaho Corporation.
 *
 * Software distributed under the GNU Lesser Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.*/

package org.pentaho.di.ui.core.dialog;

import java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.SourceToTargetMapping;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.ui.core.PropsUI;
import org.pentaho.di.ui.core.database.dialog.DatabaseDialog;
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.core.gui.WindowProperty;
import org.pentaho.di.ui.trans.step.BaseStepDialog;



/**
 * Shows a user 2 lists of strings and allows the linkage of values between values in the 2 lists
 * 
 * @author Matt
 * @since 23-03-2006
 */
public class EnterMappingDialog extends Dialog
{
	private static Class<?> PKG = DatabaseDialog.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$

    public static final String STRING_ORIGIN_SEPARATOR = "            (";
    
    private Label     wlSource;

    private List      wSource;

    private FormData  fdlSource, fdSource;

    private Label     wlSourceAuto;

    private Button    wSourceAuto;

    private FormData  fdlSourceAuto, fdSourceAuto;

    private Label     wlSourceHide;

    private Button    wSourceHide;

    private FormData  fdlSourceHide, fdSourceHide;

    private Label     wlTarget;

    private List      wTarget;

    private FormData  fdlTarget, fdTarget;

    private Label     wlTargetAuto;

    private Button    wTargetAuto;

    private FormData  fdlTargetAuto, fdTargetAuto;

    private Label     wlTargetHide;

    private Button    wTargetHide;

    private FormData  fdlTargetHide, fdTargetHide;

    private Label     wlResult;

    private List      wResult;

    private FormData  fdlResult, fdResult;

    private Button    wAdd;

    private FormData  fdAdd;

    private Button    wDelete;

    private FormData  fdDelete;

    private Button    wOK, wGuess, wCancel;

    private Listener  lsOK, lsGuess, lsCancel;

    private Shell     shell;

    private String    sourceList[];

    private String    targetList[];

    private PropsUI     props;

    private java.util.List<SourceToTargetMapping> mappings;

    /**
     * Create a new dialog allowing the user to enter a mapping
     * 
     * @param parent the parent shell
     * @param source the source values
     * @param target the target values
     */
    public EnterMappingDialog(Shell parent, String source[], String target[])
    {
        this(parent, source, target, new ArrayList<SourceToTargetMapping>());
    }

    /**
     * Create a new dialog allowing the user to enter a mapping
     * 
     * @param parent the parent shell
     * @param source the source values
     * @param target the target values
     * @param mappings the already selected mappings (ArrayList containing <code>SourceToTargetMapping</code>s)
     */
    public EnterMappingDialog(Shell parent, String source[], String target[], java.util.List<SourceToTargetMapping> mappings)
    {
        super(parent, SWT.NONE);
        props = PropsUI.getInstance();
        this.sourceList = source;
        this.targetList = target;

        this.mappings = mappings;
    }
    
    public java.util.List<SourceToTargetMapping> open()
    {
        Shell parent = getParent();
        Display display = parent.getDisplay();

        shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL);
        props.setLook(shell);
        
        shell.setImage(GUIResource.getInstance().getImageSpoon());

        FormLayout formLayout = new FormLayout();
        formLayout.marginWidth = Const.FORM_MARGIN;
        formLayout.marginHeight = Const.FORM_MARGIN;

        shell.setLayout(formLayout);
        shell.setText(BaseMessages.getString(PKG, "EnterMappingDialog.Title"));
		shell.setImage(GUIResource.getInstance().getImageTransGraph());

        int margin = Const.MARGIN;
        int buttonSpace = 90;

        // Source table
        wlSource = new Label(shell, SWT.NONE);
        wlSource.setText(BaseMessages.getString(PKG, "EnterMappingDialog.SourceFields.Label"));
        props.setLook(wlSource);
        fdlSource = new FormData();
        fdlSource.left = new FormAttachment(0, 0);
{'fraction_non_alphanumeric': 0.08541275377873178, 'fraction_numerical': 0.005366246310705662, 'mean_word_length': 3.178624813153961, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485791', 'n_tokens_mistral': 3320, 'n_tokens_neox': 3125, 'n_words': 923}