<commit_before>/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * 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
 ******************************************************************************/
package org.csstudio.opibuilder.properties;

import org.csstudio.opibuilder.editparts.ExecutionMode;
import org.csstudio.opibuilder.properties.support.PropertySSHelper;
import org.csstudio.opibuilder.script.RuleData;
import org.csstudio.opibuilder.util.OPIBuilderMacroUtil;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.jdom.CDATA;
import org.jdom.Element;

/**The widget property for string. It also accept macro string $(macro).
 * @author <NAME> (class of same name in SDS)
 * @author <NAME>
 *
 */
public class StringProperty extends AbstractWidgetProperty {
	
	private boolean multiLine, saveAsCDATA;
	/**String Property Constructor. The property value type is {@link String}.
	 * @param prop_id the property id which should be unique in a widget model.
	 * @param description the description of the property,
	 * which will be shown as the property name in property sheet.
	 * @param category the category of the widget.
	 * @param defaultValue the default value when the widget is first created.
	 */
	public StringProperty(String prop_id, String description,
			WidgetPropertyCategory category, String defaultValue) {
		this(prop_id, description, category, defaultValue, false, false);
	}
	
	public StringProperty(String prop_id, String description,
			WidgetPropertyCategory category, String defaultValue, boolean multiLine) {
		this(prop_id, description, category, defaultValue, multiLine, false);
	}
	
	public StringProperty(String prop_id, String description,
			WidgetPropertyCategory category, String defaultValue, boolean multiLine, boolean saveAsCDATA) {
		super(prop_id, description, category, defaultValue);
		this.multiLine = multiLine;
		this.saveAsCDATA = saveAsCDATA;
	}
	

	@Override
	public Object checkValue(Object value) {
		if(value == null)
			return null;
		
		String acceptedValue = null;

		if (value instanceof String) 
			acceptedValue = (String) value;
		else
			acceptedValue = value.toString();
		
		
		return acceptedValue;
	}

	@Override
	protected PropertyDescriptor createPropertyDescriptor() {
		if(PropertySSHelper.getIMPL() == null)
			return null;<commit_msg>BOY: evaluate macro value while setting string property value.<commit_after>/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * 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
 ******************************************************************************/
package org.csstudio.opibuilder.properties;

import org.csstudio.opibuilder.editparts.ExecutionMode;
import org.csstudio.opibuilder.properties.support.PropertySSHelper;
import org.csstudio.opibuilder.script.RuleData;
import org.csstudio.opibuilder.util.OPIBuilderMacroUtil;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.jdom.CDATA;
import org.jdom.Element;

/**The widget property for string. It also accept macro string $(macro).
 * @author <NAME> (class of same name in SDS)
 * @author <NAME>
 *
 */
public class StringProperty extends AbstractWidgetProperty {
	
	private boolean multiLine, saveAsCDATA;
	/**String Property Constructor. The property value type is {@link String}.
	 * @param prop_id the property id which should be unique in a widget model.
	 * @param description the description of the property,
	 * which will be shown as the property name in property sheet.
	 * @param category the category of the widget.
	 * @param defaultValue the default value when the widget is first created.
	 */
	public StringProperty(String prop_id, String description,
			WidgetPropertyCategory category, String defaultValue) {
		this(prop_id, description, category, defaultValue, false, false);
	}
	
	public StringProperty(String prop_id, String description,
			WidgetPropertyCategory category, String defaultValue, boolean multiLine) {
		this(prop_id, description, category, defaultValue, multiLine, false);
	}
	
	public StringProperty(String prop_id, String description,
			WidgetPropertyCategory category, String defaultValue, boolean multiLine, boolean saveAsCDATA) {
		super(prop_id, description, category, defaultValue);
		this.multiLine = multiLine;
		this.saveAsCDATA = saveAsCDATA;
	}
	

	@Override
	public Object checkValue(Object value) {
		if(value == null)
			return null;
		
		String acceptedValue = null;

		if (value instanceof String) 
			acceptedValue = (String) value;
		else
			acceptedValue = value.toString();
		
		if(widgetModel !=null && widgetModel.getExecutionMode() == ExecutionMode.RUN_MODE)
			return OPIBuilderMacroUtil.replaceMacros(
					widgetModel, acceptedValue);
		return acceptedValue;
	}

	@Override
	protected PropertyDescriptor createPropertyDescriptor() {
		if(PropertySSHelper.getIMPL() == null)
			return null;
{'fraction_non_alphanumeric': 0.13460118168389956, 'fraction_numerical': 0.0029542097488921715, 'mean_word_length': 5.240783410138249, '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': '382302', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1376, 'n_words': 471}