001 /*
002 * Copyright 2002-2004 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
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, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package org.springframework.richclient.form.binding.swing;
017
018 import javax.swing.JTextField;
019
020 import org.springframework.binding.form.FieldMetadata;
021
022 public class TextComponentBindingAbstractTests extends BindingAbstractTests {
023
024 private JTextField tc;
025
026 private TextComponentBinding b;
027
028 protected String setUpBinding() {
029 b = new TextComponentBinding(new JTextField(), fm, "simpleProperty");
030 tc = (JTextField)b.getControl();
031 return "simpleProperty";
032 }
033
034 public void testComponentTracksEnabledChanges() {
035 assertEquals(true, tc.isEnabled());
036 fm.setEnabled(false);
037 assertEquals(false, tc.isEnabled());
038 fm.setEnabled(true);
039 assertEquals(true, tc.isEnabled());
040 }
041
042 public void testComponentTracksReadOnlyChanges() {
043 FieldMetadata state = fm.getFieldMetadata("simpleProperty");
044 assertEquals(true, tc.isEditable());
045 state.setReadOnly(true);
046 assertEquals(false, tc.isEditable());
047 state.setReadOnly(false);
048 assertEquals(true, tc.isEditable());
049 }
050
051 public void testComponentUpdatesValueModel() {
052 tc.setText("1");
053 assertEquals("1", vm.getValue());
054 tc.setText(null);
055 assertEquals("", vm.getValue());
056 tc.setText("2");
057 assertEquals("2", vm.getValue());
058 tc.setText("");
059 assertEquals("", vm.getValue());
060 }
061
062 public void testValueModelUpdatesComponent() {
063 vm.setValue("1");
064 assertEquals("1", tc.getText());
065 vm.setValue(null);
066 assertEquals("", tc.getText());
067 vm.setValue("2");
068 assertEquals("2", tc.getText());
069 vm.setValue("");
070 assertEquals("", tc.getText());
071 }
072 }