// Path: spring-richclient-core/src/main/java/org/springframework/binding/value/swing/ValueCommitPolicy.java
// public abstract class ValueCommitPolicy extends ShortCodedLabeledEnum {
// 	public static final ValueCommitPolicy AS_YOU_TYPE = new ValueCommitPolicy(0, "as_you_type") {
// 		public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
// 			textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// 			formatter.setOverwriteMode(false);
// 			formatter.setAllowsInvalid(true);
// 			formatter.setCommitsOnValidEdit(true);
// 		}
// 	};
// 
// 	public static final ValueCommitPolicy FOCUS_LOST = new ValueCommitPolicy(1, "focus_lost") {
// 		public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
// 			textField.setFocusLostBehavior(JFormattedTextField.COMMIT);
// 			formatter.setOverwriteMode(false);
// 			formatter.setAllowsInvalid(true);
// 			formatter.setCommitsOnValidEdit(false);
// 		}
// 	};
// 
// 	public static final ValueCommitPolicy ON_SUBMIT = new ValueCommitPolicy(2, "on_submit") {
// 		public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
// 			textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// 			formatter.setOverwriteMode(false);
// 			formatter.setAllowsInvalid(true);
// 			formatter.setCommitsOnValidEdit(false);
// 		}
// 	};
// 
// 	private ValueCommitPolicy(int code, String label) {
// 		super(code, label); 
// 	}
// 
// 	public abstract void configure(JFormattedTextField textField, DefaultFormatter formatter);
// }


import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import org.springframework.binding.form.FormModel;
import org.springframework.binding.value.ValueModel;
import org.springframework.binding.value.swing.FormattedTextFieldAdapter;
import org.springframework.binding.value.swing.ValueCommitPolicy;
import org.springframework.richclient.form.binding.support.AbstractBinding;
/*
 * Copyright 2002-2004 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.richclient.form.binding.swing;



/**
 * TODO: this is probably very broken. Need to do extensive testing.
 *  
 * @author Oliver Hutchison
 */
public class FormattedTextFieldBinding extends AbstractBinding {

    private final JFormattedTextField formattedTextField;

    public FormattedTextFieldBinding(JFormattedTextField formattedTextField, FormModel formModel,
            String formPropertyPath, Class requiredSourceClass) {
        super(formModel, formPropertyPath, requiredSourceClass);
        this.formattedTextField = formattedTextField;
    }

    protected JComponent doBindControl() {
        final ValueModel valueModel = getValueModel();
        formattedTextField.setValue(valueModel.getValue());
        // TODO: implement ValueCommitPolicies
// Path: spring-richclient-core/src/main/java/org/springframework/binding/value/swing/ValueCommitPolicy.java
// public abstract class ValueCommitPolicy extends ShortCodedLabeledEnum {
// 	public static final ValueCommitPolicy AS_YOU_TYPE = new ValueCommitPolicy(0, "as_you_type") {
// 		public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
// 			textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// 			formatter.setOverwriteMode(false);
// 			formatter.setAllowsInvalid(true);
// 			formatter.setCommitsOnValidEdit(true);
// 		}
// 	};
// 
// 	public static final ValueCommitPolicy FOCUS_LOST = new ValueCommitPolicy(1, "focus_lost") {
// 		public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
// 			textField.setFocusLostBehavior(JFormattedTextField.COMMIT);
// 			formatter.setOverwriteMode(false);
// 			formatter.setAllowsInvalid(true);
// 			formatter.setCommitsOnValidEdit(false);
// 		}
// 	};
// 
// 	public static final ValueCommitPolicy ON_SUBMIT = new ValueCommitPolicy(2, "on_submit") {
// 		public void configure(JFormattedTextField textField, DefaultFormatter formatter) {
// 			textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// 			formatter.setOverwriteMode(false);
// 			formatter.setAllowsInvalid(true);
// 			formatter.setCommitsOnValidEdit(false);
// 		}
// 	};
// 
// 	private ValueCommitPolicy(int code, String label) {
// 		super(code, label); 
// 	}
// 
// 	public abstract void configure(JFormattedTextField textField, DefaultFormatter formatter);
// }


// Path: spring-richclient-core/src/main/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBinding.java
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import org.springframework.binding.form.FormModel;
import org.springframework.binding.value.ValueModel;
import org.springframework.binding.value.swing.FormattedTextFieldAdapter;
import org.springframework.binding.value.swing.ValueCommitPolicy;
import org.springframework.richclient.form.binding.support.AbstractBinding;

/*
 * Copyright 2002-2004 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.richclient.form.binding.swing;



/**
 * TODO: this is probably very broken. Need to do extensive testing.
 *  
 * @author Oliver Hutchison
 */
public class FormattedTextFieldBinding extends AbstractBinding {

    private final JFormattedTextField formattedTextField;

    public FormattedTextFieldBinding(JFormattedTextField formattedTextField, FormModel formModel,
            String formPropertyPath, Class requiredSourceClass) {
        super(formModel, formPropertyPath, requiredSourceClass);
        this.formattedTextField = formattedTextField;
    }

    protected JComponent doBindControl() {
        final ValueModel valueModel = getValueModel();
        formattedTextField.setValue(valueModel.getValue());
        // TODO: implement ValueCommitPolicies
        new FormattedTextFieldAdapter(formattedTextField, valueModel, ValueCommitPolicy.AS_YOU_TYPE);