001    /**
002     * Copyright 2005-2012 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     */
016    package org.kuali.rice.krad.web.bind;
017    
018    import java.io.Serializable;
019    import java.sql.Date;
020    import java.sql.Timestamp;
021    
022    /**
023     * PropertyEditor converts between date display strings and
024     * <code>java.sql.Timestamp</code> objects using the
025     * <code>org.kuali.rice.core.api.datetime.DateTimeService</code>
026     * 
027     * @author Kuali Rice Team (rice.collab@kuali.org)
028     */
029    public class UifTimestampEditor extends UifDateEditor implements Serializable {
030        private static final long serialVersionUID = -2776193044590819394L;
031    
032        /**
033         * This overridden method uses the
034         * <code>org.kuali.rice.core.api.datetime.DateTimeService</code> to convert
035         * the time stamp object to the display string.
036         * 
037         * @see UifDateEditor#getAsText()
038         */
039        @Override
040        public String getAsText() {
041            if (this.getValue() == null) {
042                return null;
043            }
044            if ("".equals(this.getValue())) {
045                return null;
046            }
047    
048            return getDateTimeService().toDateTimeString((Timestamp) this.getValue());
049        }
050    
051        /**
052         * This overridden method converts the display string to a
053         * <code>java.sql.Timestamp</code> object using the
054         * <code>org.kuali.rice.core.api.datetime.DateTimeService</code>.
055         * 
056         * @see UifDateEditor#setAsText(java.lang.String)
057         */
058        @Override
059        public void setAsText(String text) throws IllegalArgumentException {
060            this.setValue(new Timestamp(((Date) super.convertToObject(text)).getTime()));
061        }
062    
063    }