<commit_before>/**
 * Copyright (c) 2011 committers of YAKINDU and others.
 * 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:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.simulation.ui.view;

import java.util.Map;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
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.Label;
import org.eclipse.swt.widgets.TreeItem;
import org.yakindu.base.types.EnumerationType;
import org.yakindu.base.types.PrimitiveType;
import org.yakindu.sct.model.sruntime.CompositeSlot;
import org.yakindu.sct.model.sruntime.ExecutionEvent;
import org.yakindu.sct.model.sruntime.ExecutionOperation;
import org.yakindu.sct.model.sruntime.ExecutionSlot;
import org.yakindu.sct.model.sruntime.ExecutionVariable;
import org.yakindu.sct.model.sruntime.ReferenceSlot;
import org.yakindu.sct.simulation.ui.SimulationImages;

import com.google.common.collect.Maps;

/**
 * 
 * @author <NAME> - Initial contribution and API
 * 
 */
public class ExecutionContextLabelProvider extends StyledCellLabelProvider {

	private final int index;
	private static Map<String, Button> viewerCells = Maps.newHashMap();

	public ExecutionContextLabelProvider(int index) {
		this.index = index;
	}

	public void update(ViewerCell cell) {
		switch (index) {
			case 0 :
				updateNameCell(cell);
				break;
			case 1 :
				updateValueCell(cell);
				break;
		}
		super.update(cell);
	}

	private void updateValueCell(ViewerCell cell) {
		Object element = cell.getElement();
		if (element instanceof ReferenceSlot) {
			ReferenceSlot refSlot = (ReferenceSlot) element;
			String label = "";
			if (refSlot.getReference() != null) {
				String refFqn = refSlot.getReference().getFqName();
				Object refValue = refSlot.getReference().getValue();
				label = refValue != null ? refFqn + " = " + refValue : refFqn;
			}
			cell.setText(label);
		} else if (element instanceof ExecutionSlot) {
			Object value = ((ExecutionSlot) element).getValue();
			if (value != null) {
				if (((ExecutionSlot) element).getType().getOriginType() instanceof EnumerationType) {
					EnumerationType enumType = (EnumerationType) ((ExecutionSlot) element).getType().getOriginType();
					String text = enumType.getEnumerator().get(((Long) value).intValue()).getName();
					cell.setText(text);
				}
				if (((ExecutionSlot) element).getType().getOriginType() instanceof PrimitiveType) {
					PrimitiveType primitiveType = (PrimitiveType) ((ExecutionSlot) element).getType().getOriginType();
					if (primitiveType != null
							&& Boolean.class.getSimpleName().equalsIgnoreCase(primitiveType.getName())) {
						TreeItem currentItem = (TreeItem) cell.getItem();
						NativeCellWidgetUtil.addNativeCheckbox(cell, element, value,
								new TreeEditorDisposeListener(currentItem));

						// layout cells with checkbox widgets to update positions if tree contents have
						// changed
						cell.getControl().getParent().layout();
					} else {
						cell.setText(value.toString());
					}
				} else {
					cell.setText(value.toString());
				}
			} else {
				cell.setText("");
			}
		}
	}

	private void updateNameCell(ViewerCell cell) {
		Object element = cell.getElement();
		if (element instanceof ExecutionEvent) {
			ExecutionEvent event = (ExecutionEvent) element;
			cell.setText(event.getName());
			StyleRange style1 = new StyleRange();
			style1.start = 0;
			style1.length = event.getName().length();<commit_msg>Fixes #1807. Changed ExecutionContextLabelProvider to check the value type instead of the name for boolean types. (#1808)<commit_after>/**
 * Copyright (c) 2011 committers of YAKINDU and others.
 * 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:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.simulation.ui.view;

import java.util.Map;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
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.Label;
import org.eclipse.swt.widgets.TreeItem;
import org.yakindu.base.types.EnumerationType;
import org.yakindu.base.types.PrimitiveType;
import org.yakindu.sct.model.sruntime.CompositeSlot;
import org.yakindu.sct.model.sruntime.ExecutionEvent;
import org.yakindu.sct.model.sruntime.ExecutionOperation;
import org.yakindu.sct.model.sruntime.ExecutionSlot;
import org.yakindu.sct.model.sruntime.ExecutionVariable;
import org.yakindu.sct.model.sruntime.ReferenceSlot;
import org.yakindu.sct.simulation.ui.SimulationImages;

import com.google.common.collect.Maps;

/**
 * 
 * @author <NAME> - Initial contribution and API
 * 
 */
public class ExecutionContextLabelProvider extends StyledCellLabelProvider {

	private final int index;
	private static Map<String, Button> viewerCells = Maps.newHashMap();

	public ExecutionContextLabelProvider(int index) {
		this.index = index;
	}

	public void update(ViewerCell cell) {
		switch (index) {
			case 0 :
				updateNameCell(cell);
				break;
			case 1 :
				updateValueCell(cell);
				break;
		}
		super.update(cell);
	}

	private void updateValueCell(ViewerCell cell) {
		Object element = cell.getElement();
		if (element instanceof ReferenceSlot) {
			ReferenceSlot refSlot = (ReferenceSlot) element;
			String label = "";
			if (refSlot.getReference() != null) {
				String refFqn = refSlot.getReference().getFqName();
				Object refValue = refSlot.getReference().getValue();
				label = refValue != null ? refFqn + " = " + refValue : refFqn;
			}
			cell.setText(label);
		} else if (element instanceof ExecutionSlot) {
			Object value = ((ExecutionSlot) element).getValue();
			if (value != null) {
				if (((ExecutionSlot) element).getType().getOriginType() instanceof EnumerationType) {
					EnumerationType enumType = (EnumerationType) ((ExecutionSlot) element).getType().getOriginType();
					String text = enumType.getEnumerator().get(((Long) value).intValue()).getName();
					cell.setText(text);
				}
				if (((ExecutionSlot) element).getType().getOriginType() instanceof PrimitiveType) {
					PrimitiveType primitiveType = (PrimitiveType) ((ExecutionSlot) element).getType().getOriginType();
					if (primitiveType != null && value instanceof Boolean) {
						TreeItem currentItem = (TreeItem) cell.getItem();
						NativeCellWidgetUtil.addNativeCheckbox(cell, element, value,
								new TreeEditorDisposeListener(currentItem));

						// layout cells with checkbox widgets to update positions if tree contents have
						// changed
						cell.getControl().getParent().layout();
					} else {
						cell.setText(value.toString());
					}
				}
			} else {
				cell.setText("");
			}
		}
	}

	private void updateNameCell(ViewerCell cell) {
		Object element = cell.getElement();
		if (element instanceof ExecutionEvent) {
			ExecutionEvent event = (ExecutionEvent) element;
			cell.setText(event.getName());
			StyleRange style1 = new StyleRange();
			style1.start = 0;
			style1.length = event.getName().length();
{'fraction_non_alphanumeric': 0.11702380952380953, 'fraction_numerical': 0.004523809523809524, 'mean_word_length': 4.3956326268465, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2022028', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2525, 'n_words': 557}