<commit_before>/***********************************************************************************************************************
 * Copyright (c) 2012 Atos.
 * 
 * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: <NAME> (Atos) - initial API and implementation
 * 				 <NAME> (Atos) - composite modified according to the new deletion parameters model
 * 
 **********************************************************************************************************************/
package org.topcased.typesmodel.ui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
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 org.topcased.typesmodel.Messages;
import org.topcased.typesmodel.model.inittypes.DeletionParameters;
import org.topcased.typesmodel.model.inittypes.DeletionParemeter;
import org.topcased.typesmodel.model.inittypes.InittypesFactory;

/**
 * Composite of the deletion parameters. 
 */
public class DeletionParametersComposite {
	
	private Label lblIdRegex;
	private Text txtIdRegex;
	private Label lblDescriptionRegex;
	private Text txtDescriptionRegex;
	private Table tabAttributes;
	private Button btnAddAttribute;
	private Button btnEditAttribute;
	private Button btnRemoveAttribute;
	

	public DeletionParametersComposite(Composite composite, DeletionParameters deletionParameters) {
		composite.setLayout(new GridLayout(2, false));

		lblIdRegex = new Label(composite, SWT.NONE);
		lblIdRegex.setText(Messages.DeletionParametersComposite_LabelIdRegex);
		
		txtIdRegex = new Text(composite, SWT.BORDER);
		txtIdRegex.setText(Messages.DeletionParametersComposite_TestIdRegex);
		txtIdRegex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		lblDescriptionRegex = new Label(composite, SWT.NONE);
		lblDescriptionRegex.setText(Messages.DeletionParametersComposite_LabelDescriptionRegex);
		
		txtDescriptionRegex = new Text(composite, SWT.BORDER);
		txtDescriptionRegex.setText(Messages.DeletionParametersComposite_TextDescriptionRegex);
		txtDescriptionRegex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		
		Group deletionGroup = new Group(composite, SWT.NONE);
        deletionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        deletionGroup.setText(Messages.DeletionParametersComposite_GroupAttributes);
        deletionGroup.setLayout(new GridLayout(2, false));

        // The table containing all the attributes (name & regex) 
        tabAttributes = new Table(deletionGroup, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
        tabAttributes.setLinesVisible(true);
        tabAttributes.setHeaderVisible(true);
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.heightHint = 150;
        tabAttributes.setLayoutData(data);
        String[] titles = { Messages.DeletionParametersComposite_ColumnAttributeName, Messages.DeletionParametersComposite_ColumnAttributeRegex};
        int i;
        for (i = 0; i < titles.length; i++) {
          TableColumn column = new TableColumn(tabAttributes, SWT.NONE);
          column.setText(titles[i]);
          tabAttributes.getColumn(i).pack();
        }
        // The column for the combo deletion/filters is added
        TableColumn column = new TableColumn(tabAttributes, SWT.NONE);
        column.setText(Messages.DeletionParametersComposite_ParameterTypeColumn);
        tabAttributes.getColumn(i).pack();
        
        Composite buttonGroup = new Composite(deletionGroup, SWT.NONE);
        buttonGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        buttonGroup.setLayout(new GridLayout(1, false));
        
        btnAddAttribute = new Button(buttonGroup, SWT.PUSH);
        btnAddAttribute.setText(Messages.DeletionParametersComposite_ButtonAdd);
        btnAddAttribute.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        btnAddAttribute.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				PopupAttributesDialog dialog = new PopupAttributesDialog(null);
                if (dialog.open() == Dialog.OK)
                {
                	TableItem item = new TableItem(tabAttributes, SWT.NONE);
                    item.setText (0, dialog.getAttributesName());
                    item.setText (1, dialog.getAttributesRegex());
                    item.setText (2, dialog.getAttributesRegex());
                }
			}
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
        btnEditAttribute = new Button(buttonGroup, SWT.PUSH);
        btnEditAttribute.setText(Messages.DeletionParametersComposite_ButtonEdit);
        btnEditAttribute.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        btnEditAttribute.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				int selectedIndex = tabAttributes.getSelectionIndex();
				PopupAttributesDialog dialog = new PopupAttributesDialog(null,tabAttributes.getItem(selectedIndex).getText(0),tabAttributes.getItem(selectedIndex).getText(1), tabAttributes.getItem(selectedIndex).getText(2));
                if (dialog.open() == Dialog.OK)
                {
                	tabAttributes.getItem(selectedIndex).setText(0, dialog.getAttributesName());
                	tabAttributes.getItem(selectedIndex).setText(1, dialog.getAttributesRegex());<commit_msg>[#4294] Requirements filtering when updating Deletion parameters edition composite fixed (parameter type on the "add" action)<commit_after>/***********************************************************************************************************************
 * Copyright (c) 2012 Atos.
 * 
 * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: <NAME> (Atos) - initial API and implementation
 * 				 <NAME> (Atos) - composite modified according to the new deletion parameters model
 * 
 **********************************************************************************************************************/
package org.topcased.typesmodel.ui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
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 org.topcased.typesmodel.Messages;
import org.topcased.typesmodel.model.inittypes.DeletionParameters;
import org.topcased.typesmodel.model.inittypes.DeletionParemeter;
import org.topcased.typesmodel.model.inittypes.InittypesFactory;

/**
 * Composite of the deletion parameters. 
 */
public class DeletionParametersComposite {
	
	private Label lblIdRegex;
	private Text txtIdRegex;
	private Label lblDescriptionRegex;
	private Text txtDescriptionRegex;
	private Table tabAttributes;
	private Button btnAddAttribute;
	private Button btnEditAttribute;
	private Button btnRemoveAttribute;
	

	public DeletionParametersComposite(Composite composite, DeletionParameters deletionParameters) {
		composite.setLayout(new GridLayout(2, false));

		lblIdRegex = new Label(composite, SWT.NONE);
		lblIdRegex.setText(Messages.DeletionParametersComposite_LabelIdRegex);
		
		txtIdRegex = new Text(composite, SWT.BORDER);
		txtIdRegex.setText(Messages.DeletionParametersComposite_TestIdRegex);
		txtIdRegex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		lblDescriptionRegex = new Label(composite, SWT.NONE);
		lblDescriptionRegex.setText(Messages.DeletionParametersComposite_LabelDescriptionRegex);
		
		txtDescriptionRegex = new Text(composite, SWT.BORDER);
		txtDescriptionRegex.setText(Messages.DeletionParametersComposite_TextDescriptionRegex);
		txtDescriptionRegex.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		
		Group deletionGroup = new Group(composite, SWT.NONE);
        deletionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        deletionGroup.setText(Messages.DeletionParametersComposite_GroupAttributes);
        deletionGroup.setLayout(new GridLayout(2, false));

        // The table containing all the attributes (name & regex) 
        tabAttributes = new Table(deletionGroup, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
        tabAttributes.setLinesVisible(true);
        tabAttributes.setHeaderVisible(true);
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
        data.heightHint = 150;
        tabAttributes.setLayoutData(data);
        String[] titles = { Messages.DeletionParametersComposite_ColumnAttributeName, Messages.DeletionParametersComposite_ColumnAttributeRegex};
        int i;
        for (i = 0; i < titles.length; i++) {
          TableColumn column = new TableColumn(tabAttributes, SWT.NONE);
          column.setText(titles[i]);
          tabAttributes.getColumn(i).pack();
        }
        // The column for the combo deletion/filters is added
        TableColumn column = new TableColumn(tabAttributes, SWT.NONE);
        column.setText(Messages.DeletionParametersComposite_ParameterTypeColumn);
        tabAttributes.getColumn(i).pack();
        
        Composite buttonGroup = new Composite(deletionGroup, SWT.NONE);
        buttonGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
        buttonGroup.setLayout(new GridLayout(1, false));
        
        btnAddAttribute = new Button(buttonGroup, SWT.PUSH);
        btnAddAttribute.setText(Messages.DeletionParametersComposite_ButtonAdd);
        btnAddAttribute.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        btnAddAttribute.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				PopupAttributesDialog dialog = new PopupAttributesDialog(null);
                if (dialog.open() == Dialog.OK)
                {
                	TableItem item = new TableItem(tabAttributes, SWT.NONE);
                    item.setText (0, dialog.getAttributesName());
                    item.setText (1, dialog.getAttributesRegex());
                    item.setText (2, dialog.getAttributesType());
                }
			}
			public void widgetDefaultSelected(SelectionEvent e) {}
		});
        btnEditAttribute = new Button(buttonGroup, SWT.PUSH);
        btnEditAttribute.setText(Messages.DeletionParametersComposite_ButtonEdit);
        btnEditAttribute.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        btnEditAttribute.addSelectionListener(new SelectionListener() {
			public void widgetSelected(SelectionEvent e) {
				int selectedIndex = tabAttributes.getSelectionIndex();
				PopupAttributesDialog dialog = new PopupAttributesDialog(null,tabAttributes.getItem(selectedIndex).getText(0),tabAttributes.getItem(selectedIndex).getText(1), tabAttributes.getItem(selectedIndex).getText(2));
                if (dialog.open() == Dialog.OK)
                {
                	tabAttributes.getItem(selectedIndex).setText(0, dialog.getAttributesName());
                	tabAttributes.getItem(selectedIndex).setText(1, dialog.getAttributesRegex());
{'fraction_non_alphanumeric': 0.13159815130138652, 'fraction_numerical': 0.0060001621665450415, 'mean_word_length': 4.284490145672665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7492721', 'n_tokens_mistral': 3565, 'n_tokens_neox': 3315, 'n_words': 682}