Revision: 1201
Author: jhoskens
Date: 2006-06-14 01:08:31 -0700 (Wed, 14 Jun 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1201&view=rev
Log Message:
-----------
patch for RCP-367: use JFormattedTextField.setValue() instead of .setText()
Modified Paths:
--------------
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBinding.java
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
Added Paths:
-----------
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBindingTests.java
Modified:
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBinding.java
===================================================================
---
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBinding.java
2006-06-14 07:16:12 UTC (rev 1200)
+++
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBinding.java
2006-06-14 08:08:31 UTC (rev 1201)
@@ -41,15 +41,7 @@
protected JComponent doBindControl() {
final ValueModel valueModel = getValueModel();
- try {
- formattedTextField.setText((String)valueModel.getValue());
- }
- catch (ClassCastException e) {
- IllegalArgumentException ex = new IllegalArgumentException("Class
cast exception converting '"
- + getProperty() + "' property value to string - did you
install a type converter?");
- ex.initCause(e);
- throw ex;
- }
+ formattedTextField.setValue(valueModel.getValue());
// TODO: implement ValueCommitPolicies
new FormattedTextFieldAdapter(formattedTextField, valueModel,
ValueCommitPolicy.AS_YOU_TYPE);
return formattedTextField;
Modified:
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
===================================================================
---
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
2006-06-14 07:16:12 UTC (rev 1200)
+++
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
2006-06-14 08:08:31 UTC (rev 1201)
@@ -38,7 +38,17 @@
public Object readOnly;
public Object writeOnly;
+
+ public Number numberProperty;
+ public Number getNumberProperty() {
+ return numberProperty;
+ }
+
+ public void setNumberProperty(Number numberProperty) {
+ this.numberProperty = numberProperty;
+ }
+
public String getSimpleProperty() {
return simpleProperty;
}
Modified:
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
===================================================================
---
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
2006-06-14 07:16:12 UTC (rev 1200)
+++
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
2006-06-14 08:08:31 UTC (rev 1201)
@@ -28,11 +28,15 @@
protected ValueModel vm;
public void doSetUp() {
- fm = new DefaultFormModel(new TestBean());
+ fm = new DefaultFormModel(createTestBean());
String property = setUpBinding();
vm = fm.getValueModel(property);
}
+ protected TestBean createTestBean() {
+ return new TestBean();
+ }
+
protected abstract String setUpBinding();
public abstract void testComponentTracksEnabledChanges();
Added:
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBindingTests.java
===================================================================
---
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBindingTests.java
(rev 0)
+++
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/FormattedTextFieldBindingTests.java
2006-06-14 08:08:31 UTC (rev 1201)
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import java.text.NumberFormat;
+
+import javax.swing.JFormattedTextField;
+
+import org.springframework.binding.form.FieldMetadata;
+import org.springframework.binding.support.TestBean;
+
+public class FormattedTextFieldBindingTests extends BindingAbstractTests {
+
+ private static final Long initialValue = new Long(99);
+
+ private JFormattedTextField ftc;
+
+ private FormattedTextFieldBinding b;
+
+ protected TestBean createTestBean() {
+ TestBean testBean = super.createTestBean();
+ testBean.setNumberProperty(initialValue);
+ return testBean;
+ }
+
+ protected String setUpBinding() {
+ b = new FormattedTextFieldBinding(new
JFormattedTextField(NumberFormat.getInstance()), fm, "numberProperty", null);
+ ftc = (JFormattedTextField)b.getControl();
+ return "numberProperty";
+ }
+
+ public void testInitialValue() {
+ assertEquals(initialValue, vm.getValue());
+ assertEquals(initialValue, ftc.getValue());
+ }
+
+ public void testComponentTracksEnabledChanges() {
+ assertEquals(true, ftc.isEnabled());
+ fm.setEnabled(false);
+ assertEquals(false, ftc.isEnabled());
+ fm.setEnabled(true);
+ assertEquals(true, ftc.isEnabled());
+ }
+
+ public void testComponentTracksReadOnlyChanges() {
+ FieldMetadata state = fm.getFieldMetadata("numberProperty");
+ assertEquals(true, ftc.isEditable());
+ state.setReadOnly(true);
+ assertEquals(false, ftc.isEditable());
+ state.setReadOnly(false);
+ assertEquals(true, ftc.isEditable());
+ }
+
+ public void testComponentUpdatesValueModel() {
+ Long one = new Long(1);
+ Long two = new Long(2);
+ ftc.setValue(one);
+ assertTrue(vm.getValue() instanceof Long);
+ assertTrue(one.compareTo((Long)vm.getValue()) == 0);
+ ftc.setValue(null);
+ assertEquals(null, vm.getValue());
+ ftc.setValue(two);
+ assertEquals(two, vm.getValue());
+ ftc.setValue(null);
+ assertEquals(null, vm.getValue());
+ }
+
+ public void testValueModelUpdatesComponent() {
+ Long one = new Long(1);
+ Long two = new Long(2);
+ vm.setValue(one);
+ assertEquals(one, ftc.getValue());
+ vm.setValue(null);
+ assertEquals(null, ftc.getValue());
+ vm.setValue(two);
+ assertEquals(two, ftc.getValue());
+ vm.setValue(null);
+ assertEquals(null, ftc.getValue());
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs