View Javadoc
1   /**
2    * Copyright 2005-2015 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 edu.sampleu.demo.kitchensink;
17  
18  import org.apache.commons.lang.StringUtils;
19  import java.beans.PropertyEditorSupport;
20  import java.io.Serializable;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  public class UITestPropertyEditor extends PropertyEditorSupport implements Serializable {
26      private static final long serialVersionUID = -4113846709722954737L;
27  
28      /**
29       * @see java.beans.PropertyEditorSupport#getAsText()
30       */
31      @Override
32      public String getAsText() {
33          Object obj = this.getValue();
34  
35          if (obj == null) {
36              return null;
37          }
38  
39          String displayValue = obj.toString();
40          if (displayValue.length() > 3) {
41              displayValue = StringUtils.substring(displayValue, 0, 3) + "-" + StringUtils.substring(displayValue, 3);
42          }
43  
44          return displayValue;
45      }
46  
47      /**
48       * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
49       */
50      @Override
51      public void setAsText(String text) {
52          String value = text;
53          if (StringUtils.contains(value, "-")) {
54              value = StringUtils.replaceOnce(value, "-", "");
55          }
56  
57          this.setValue(value);
58      }
59  
60  }