View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.labs.kitchensink;
17  
18  import org.apache.commons.lang.StringUtils;
19  
20  import java.beans.PropertyEditorSupport;
21  import java.io.Serializable;
22  
23  /**
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class UITestPropertyEditor extends PropertyEditorSupport implements Serializable {
27      private static final long serialVersionUID = -4113846709722954737L;
28  
29      /**
30       * @see java.beans.PropertyEditorSupport#getAsText()
31       */
32      @Override
33      public String getAsText() {
34          Object obj = this.getValue();
35  
36          if (obj == null) {
37              return null;
38          }
39  
40          String displayValue = obj.toString();
41          if (displayValue.length() > 3) {
42              displayValue = StringUtils.substring(displayValue, 0, 3) + "-" + StringUtils.substring(displayValue, 3);
43          }
44  
45          return displayValue;
46      }
47  
48      /**
49       * @see java.beans.PropertyEditorSupport#setAsText(String)
50       */
51      @Override
52      public void setAsText(String text) {
53          String value = text;
54          if (StringUtils.contains(value, "-")) {
55              value = StringUtils.replaceOnce(value, "-", "");
56          }
57  
58          this.setValue(value);
59      }
60  
61  }