001 package org.springframework.richclient.form.binding.swing;
002
003 import org.springframework.binding.form.FormModel;
004 import org.springframework.richclient.form.binding.support.CustomBinding;
005 import org.springframework.richclient.components.TimeTextField;
006
007 import javax.swing.*;
008 import java.beans.PropertyChangeListener;
009 import java.beans.PropertyChangeEvent;
010
011 @SuppressWarnings("unchecked")
012 public final class TimeBinding extends CustomBinding implements PropertyChangeListener
013 {
014
015 private final TimeTextField field;
016
017 public TimeBinding(FormModel model, String path, Class requiredSourceClass, TimeTextField field)
018 {
019 super(model, path, requiredSourceClass);
020 this.field = field;
021 }
022
023 protected void valueModelChanged(Object newValue)
024 {
025 field.setValue(newValue);
026 readOnlyChanged();
027 }
028
029 protected JComponent doBindControl()
030 {
031 field.setValue(getValue());
032 field.addPropertyChangeListener("value", this);
033 return field;
034 }
035
036 public void propertyChange(PropertyChangeEvent evt)
037 {
038 controlValueChanged(field.getValue());
039 }
040
041 protected void readOnlyChanged()
042 {
043 field.setEditable(isEnabled() && !isReadOnly());
044 }
045
046 protected void enabledChanged()
047 {
048 field.setEnabled(isEnabled());
049 readOnlyChanged();
050 }
051 }
052