/*******************************************************************************
 * Copyright 2019 2Fi Business Solutions Ltd.
 *
 * This code is part of the Core project.
 *
 * This code is copyrighted. Under no circumstances should any party, people,
 * or organization should redistribute any portions of this code in any form,
 * either verbatim or through electronic media, to any third parties, unless
 * under explicit written permission by 2Fi Business Solutions Ltd.
 ******************************************************************************/
package com.ffii.core.support;

import java.beans.PropertyEditorSupport;

import com.ffii.core.utils.StringUtils;

/**
 * <p>
 * Property Editor for String
 * </p>
 * <p>
 * Use {@link StringUtils.trimToEmpty()} when binding the value and getting the value to display
 * </p>
 *
 * @see StringUtils#trimToEmpty(String)
 *
 * @author Patrick
 */
public class SimpleStringTrimToEmptyEditor extends PropertyEditorSupport {

	@Override
	public void setAsText(String value) throws IllegalArgumentException {
		setValue(StringUtils.trimToEmpty(value));
	}

	@Override
	public String getAsText() {
		return (getValue() == null ? StringUtils.EMPTY : StringUtils.trimToEmpty((String) getValue()));
	}

}
