001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.labs.kitchensink;
017
018import org.apache.commons.lang.StringUtils;
019
020import java.beans.PropertyEditorSupport;
021import java.io.Serializable;
022
023/**
024 * @author Kuali Rice Team (rice.collab@kuali.org)
025 */
026public class UITestPropertyEditor extends PropertyEditorSupport implements Serializable {
027    private static final long serialVersionUID = -4113846709722954737L;
028
029    /**
030     * @see java.beans.PropertyEditorSupport#getAsText()
031     */
032    @Override
033    public String getAsText() {
034        Object obj = this.getValue();
035
036        if (obj == null) {
037            return null;
038        }
039
040        String displayValue = obj.toString();
041        if (displayValue.length() > 3) {
042            displayValue = StringUtils.substring(displayValue, 0, 3) + "-" + StringUtils.substring(displayValue, 3);
043        }
044
045        return displayValue;
046    }
047
048    /**
049     * @see java.beans.PropertyEditorSupport#setAsText(String)
050     */
051    @Override
052    public void setAsText(String text) {
053        String value = text;
054        if (StringUtils.contains(value, "-")) {
055            value = StringUtils.replaceOnce(value, "-", "");
056        }
057
058        this.setValue(value);
059    }
060
061}