<commit_before>package org.aludratest.eclipse.vde.internal.editors;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.aludratest.eclipse.vde.internal.VdeImage;
import org.aludratest.eclipse.vde.internal.model.TestDataConfigurationSegment;
import org.aludratest.eclipse.vde.internal.model.TestDataFieldValue;
import org.aludratest.eclipse.vde.model.IFieldValue;
import org.aludratest.eclipse.vde.model.IStringListValue;
import org.aludratest.eclipse.vde.model.IStringValue;
import org.aludratest.eclipse.vde.model.ITestDataConfigurationSegment;
import org.aludratest.eclipse.vde.model.ITestDataFieldMetadata;
import org.aludratest.eclipse.vde.model.ITestDataFieldValue;
import org.aludratest.eclipse.vde.model.ITestDataSegmentMetadata;
import org.aludratest.eclipse.vde.model.TestDataFieldType;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.AbstractFormPart;
import org.eclipse.ui.forms.IDetailsPage;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class ConfigurationSegmentDetailsFormPart extends AbstractFormPart implements IDetailsPage {

	private Section section;

	private TableViewer tvFields;

	private ConfigurationSegmentsMasterDetailsBlock masterBlock;

	private ITestDataConfigurationSegment segment;

	public ConfigurationSegmentDetailsFormPart(ConfigurationSegmentsMasterDetailsBlock masterBlock) {
		this.masterBlock = masterBlock;
	}

	@Override
	public void selectionChanged(IFormPart part, ISelection selection) {
		IStructuredSelection sel = (IStructuredSelection) selection;
		Object input = sel.getFirstElement();
		tvFields.setInput(input);

		segment = (ITestDataConfigurationSegment) input;

		boolean allRed = false;
		if (input instanceof TestDataConfigurationSegment) {
			allRed = ((TestDataConfigurationSegment) input).isNotReferencedInMetadata(false);
		}

		tvFields.setLabelProvider(new SegmentFieldLabelProvider(allRed));
	}

	@Override
	public void createContents(Composite parent) {
		FormToolkit toolkit = getManagedForm().getToolkit();
		GridLayout gl = new GridLayout(1, false);
		gl.marginTop = -5;
		gl.marginBottom = -5;
		parent.setLayout(gl);

		section = toolkit.createSection(parent, Section.EXPANDED | Section.DESCRIPTION | Section.TITLE_BAR);
		section.setText("Segment contents");
		section.setDescription("Main Segment Fields");
		section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		Composite c = toolkit.createComposite(section);
		section.setClient(c);
		c.setLayout(new GridLayout(1, false));

		Table tbl = new Table(c, SWT.BORDER | SWT.FULL_SELECTION);
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd.heightHint = 200;
		tbl.setLayoutData(gd);
		tbl.setHeaderVisible(true);


		// create columns
		TableColumn tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Field");
		tc.setWidth(120);
		tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Data type");
		tc.setWidth(90);
		tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Data subtype");
		tc.setWidth(140);
		tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Value");
		tc.setWidth(200);

		tvFields = new TableViewer(tbl);
		tvFields.setContentProvider(new SegmentFieldsContentProvider());
		tvFields.setLabelProvider(new SegmentFieldLabelProvider(false));

		Menu contextMenu = new Menu(tbl);
		final MenuItem mnuDelete = new MenuItem(contextMenu, SWT.PUSH);
		mnuDelete.setText("Remove");
		mnuDelete.setImage(VdeImage.DELETE.getImage());
		contextMenu.addMenuListener(new MenuListener() {
			@Override
			public void menuShown(MenuEvent e) {
				// get selected field; only enable if field is red
				ITestDataFieldValue field = (ITestDataFieldValue) ((IStructuredSelection) tvFields.getSelection())
						.getFirstElement();
				if (field != null && (field instanceof TestDataFieldValue)
						&& ((TestDataFieldValue) field).isNotReferencedInMetadata()) {
					mnuDelete.setEnabled(true);
				}
				else {
					mnuDelete.setEnabled(false);
				}
			}
<commit_msg>Fix ClassCastException in context menu<commit_after>package org.aludratest.eclipse.vde.internal.editors;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.aludratest.eclipse.vde.internal.VdeImage;
import org.aludratest.eclipse.vde.internal.model.TestDataConfigurationSegment;
import org.aludratest.eclipse.vde.internal.model.TestDataFieldValue;
import org.aludratest.eclipse.vde.model.IFieldValue;
import org.aludratest.eclipse.vde.model.IStringListValue;
import org.aludratest.eclipse.vde.model.IStringValue;
import org.aludratest.eclipse.vde.model.ITestDataConfigurationSegment;
import org.aludratest.eclipse.vde.model.ITestDataFieldMetadata;
import org.aludratest.eclipse.vde.model.ITestDataFieldValue;
import org.aludratest.eclipse.vde.model.ITestDataSegmentMetadata;
import org.aludratest.eclipse.vde.model.TestDataFieldType;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.AbstractFormPart;
import org.eclipse.ui.forms.IDetailsPage;
import org.eclipse.ui.forms.IFormPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;

public class ConfigurationSegmentDetailsFormPart extends AbstractFormPart implements IDetailsPage {

	private Section section;

	private TableViewer tvFields;

	private ConfigurationSegmentsMasterDetailsBlock masterBlock;

	private ITestDataConfigurationSegment segment;

	public ConfigurationSegmentDetailsFormPart(ConfigurationSegmentsMasterDetailsBlock masterBlock) {
		this.masterBlock = masterBlock;
	}

	@Override
	public void selectionChanged(IFormPart part, ISelection selection) {
		IStructuredSelection sel = (IStructuredSelection) selection;
		Object input = sel.getFirstElement();
		tvFields.setInput(input);

		segment = (ITestDataConfigurationSegment) input;

		boolean allRed = false;
		if (input instanceof TestDataConfigurationSegment) {
			allRed = ((TestDataConfigurationSegment) input).isNotReferencedInMetadata(false);
		}

		tvFields.setLabelProvider(new SegmentFieldLabelProvider(allRed));
	}

	@Override
	public void createContents(Composite parent) {
		FormToolkit toolkit = getManagedForm().getToolkit();
		GridLayout gl = new GridLayout(1, false);
		gl.marginTop = -5;
		gl.marginBottom = -5;
		parent.setLayout(gl);

		section = toolkit.createSection(parent, Section.EXPANDED | Section.DESCRIPTION | Section.TITLE_BAR);
		section.setText("Segment contents");
		section.setDescription("Main Segment Fields");
		section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		Composite c = toolkit.createComposite(section);
		section.setClient(c);
		c.setLayout(new GridLayout(1, false));

		Table tbl = new Table(c, SWT.BORDER | SWT.FULL_SELECTION);
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd.heightHint = 200;
		tbl.setLayoutData(gd);
		tbl.setHeaderVisible(true);


		// create columns
		TableColumn tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Field");
		tc.setWidth(120);
		tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Data type");
		tc.setWidth(90);
		tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Data subtype");
		tc.setWidth(140);
		tc = new TableColumn(tbl, SWT.LEAD);
		tc.setText("Value");
		tc.setWidth(200);

		tvFields = new TableViewer(tbl);
		tvFields.setContentProvider(new SegmentFieldsContentProvider());
		tvFields.setLabelProvider(new SegmentFieldLabelProvider(false));

		Menu contextMenu = new Menu(tbl);
		final MenuItem mnuDelete = new MenuItem(contextMenu, SWT.PUSH);
		mnuDelete.setText("Remove");
		mnuDelete.setImage(VdeImage.DELETE.getImage());
		contextMenu.addMenuListener(new MenuListener() {
			@Override
			public void menuShown(MenuEvent e) {
				// get selected field; only enable if field is red
				SegmentField field = (SegmentField) ((IStructuredSelection) tvFields.getSelection())
						.getFirstElement();
				if (field != null && (field.fieldValue instanceof TestDataFieldValue)
						&& ((TestDataFieldValue) field.fieldValue).isNotReferencedInMetadata()) {
					mnuDelete.setEnabled(true);
				}
				else {
					mnuDelete.setEnabled(false);
				}
			}

{'fraction_non_alphanumeric': 0.10918161757651348, 'fraction_numerical': 0.0034539000287825005, 'mean_word_length': 5.755670771224887, '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': '3115439', 'n_tokens_mistral': 3567, 'n_tokens_neox': 3296, 'n_words': 576}