Revision: 1216
Author: ge0ffrey
Date: 2006-06-27 02:54:09 -0700 (Tue, 27 Jun 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1216&view=rev
Log Message:
-----------
RCP-204 nachocalendar
Modified Paths:
--------------
trunk/spring-richclient/pom.xml
trunk/spring-richclient/sandbox/pom.xml
trunk/spring-richclient/support/pom.xml
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
Added Paths:
-----------
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinder.java
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinding.java
trunk/spring-richclient/sandbox/src/test/java/org/springframework/richclient/form/binding/
trunk/spring-richclient/sandbox/src/test/java/org/springframework/richclient/form/binding/swing/
trunk/spring-richclient/sandbox/src/test/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinderTests.java
Modified: trunk/spring-richclient/pom.xml
===================================================================
--- trunk/spring-richclient/pom.xml 2006-06-27 07:52:17 UTC (rev 1215)
+++ trunk/spring-richclient/pom.xml 2006-06-27 09:54:09 UTC (rev 1216)
@@ -699,12 +699,11 @@
<artifactId>jdnc</artifactId>
<version>0.7</version>
</dependency>
- <!--<dependency>-->
- <!--<groupId>nachocalendar</groupId>-->
- <!--<artifactId>nachocalendar</artifactId>-->
- <!--<version>0.23</version>-->
- <!--<optional>true</optional>-->
- <!--</dependency>-->
+ <dependency>
+ <groupId>net.sf.nachocalendar</groupId>
+ <artifactId>nachocalendar</artifactId>
+ <version>0.23</version>
+ </dependency>
<!-- Utils -->
<dependency>
Modified: trunk/spring-richclient/sandbox/pom.xml
===================================================================
--- trunk/spring-richclient/sandbox/pom.xml 2006-06-27 07:52:17 UTC (rev
1215)
+++ trunk/spring-richclient/sandbox/pom.xml 2006-06-27 09:54:09 UTC (rev
1216)
@@ -120,6 +120,10 @@
<groupId>net.java.dev.glazedlists</groupId>
<artifactId>glazedlists</artifactId>
</dependency>
+ <dependency>
+ <groupId>net.sf.nachocalendar</groupId>
+ <artifactId>nachocalendar</artifactId>
+ </dependency>
<!-- Utils -->
<dependency>
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinder.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinder.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinder.java
2006-06-27 09:54:09 UTC (rev 1216)
@@ -0,0 +1,95 @@
+/*
+ * 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 net.sf.nachocalendar.CalendarFactory;
+import net.sf.nachocalendar.components.DateField;
+import net.sf.nachocalendar.components.DefaultDayRenderer;
+import net.sf.nachocalendar.components.DefaultHeaderRenderer;
+
+import org.springframework.binding.form.FormModel;
+import org.springframework.richclient.form.binding.Binder;
+import org.springframework.richclient.form.binding.Binding;
+import org.springframework.richclient.form.binding.support.AbstractBinder;
+import org.springframework.util.Assert;
+
+import javax.swing.JComponent;
+import javax.swing.text.DateFormatter;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * Binds a <cod>Date</code> to a NachoCalendar <code>DateField</code>
+ *
+ * @author Geoffrey De Smet
+ * @author Benoit Xhenseval (added dateFormat setting)
+ */
+public class NachoCalendarDateFieldBinder extends AbstractBinder implements
Binder {
+
+ public static final String SHOW_OK_CANCEL_KEY = "showOkCancel";
+
+ private String dateFormat;
+
+ public NachoCalendarDateFieldBinder() {
+ this(new String[] {SHOW_OK_CANCEL_KEY});
+ }
+
+ public NachoCalendarDateFieldBinder(String[] supportedContextKeys) {
+ super(Date.class, supportedContextKeys);
+ }
+
+ protected Binding doBind(JComponent control, FormModel formModel, String
formPropertyPath, Map context) {
+ Assert.isTrue(control instanceof DateField, "Control must be an
instance of DateField.");
+ NachoCalendarDateFieldBinding binding = new
NachoCalendarDateFieldBinding((DateField) control, formModel, formPropertyPath);
+ applyContext(binding, context);
+ return binding;
+ }
+
+ private void applyContext(NachoCalendarDateFieldBinding binding, Map
context) {
+ if (context.containsKey(SHOW_OK_CANCEL_KEY)) {
+ binding.setShowOkCancel((Boolean) context.get(SHOW_OK_CANCEL_KEY));
+ }
+ }
+
+ protected JComponent createControl(Map context) {
+ DateField dateField;
+ if (dateFormat != null) {
+ dateField = new DateField(new DateFormatter(new
SimpleDateFormat(dateFormat)));
+ dateField.setRenderer(new DefaultDayRenderer());
+ dateField.setHeaderRenderer(new DefaultHeaderRenderer());
+ } else {
+ dateField = CalendarFactory.createDateField();
+ }
+ return dateField;
+ }
+
+ /**
+ * @return Returns the dateFormat.
+ */
+ public String getDateFormat() {
+ return dateFormat;
+ }
+
+ /**
+ * @param dateFormat The dateFormat to set.
+ */
+ public void setDateFormat(String dateFormat) {
+ this.dateFormat = dateFormat;
+ }
+
+}
\ No newline at end of file
Added:
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinding.java
===================================================================
---
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinding.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/main/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinding.java
2006-06-27 09:54:09 UTC (rev 1216)
@@ -0,0 +1,79 @@
+/*
+ * 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 net.sf.nachocalendar.components.DateField;
+import org.springframework.binding.form.FormModel;
+import org.springframework.richclient.form.binding.support.CustomBinding;
+
+import javax.swing.JComponent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Date;
+
+/**
+ * Binds a <cod>Date</code> to a NachoCalendar <code>DateField</code>
+ *
+ * @author Geoffrey De Smet
+ */
+public class NachoCalendarDateFieldBinding extends CustomBinding {
+
+ private final DateField dateField;
+
+ private Boolean showOkCancel;
+
+ public NachoCalendarDateFieldBinding(DateField dateField, FormModel
formModel, String formPropertyPath) {
+ super(formModel, formPropertyPath, Date.class);
+ this.dateField = dateField;
+ }
+
+ public Boolean getShowOkCancel() {
+ return showOkCancel;
+ }
+
+ public void setShowOkCancel(Boolean showOkCancel) {
+ this.showOkCancel = showOkCancel;
+ }
+
+ protected JComponent doBindControl() {
+ dateField.setValue((Date) getValue());
+ if (showOkCancel != null) {
+ dateField.setShowOkCancel(showOkCancel.booleanValue());
+ }
+ dateField.addPropertyChangeListener("value", new
PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ controlValueChanged(dateField.getValue());
+ }
+ });
+ // TODO: implement ValueCommitPolicies (copied from
TextComponentBinding)
+ // new AsYouTypeTextComponentAdapter(textComponent, valueModel);
+ return dateField;
+ }
+
+ protected void valueModelChanged(Object newValue) {
+ dateField.setValue((Date) newValue);
+ }
+
+ protected void readOnlyChanged() {
+ dateField.setEnabled(isEnabled() && !isReadOnly());
+ }
+
+ protected void enabledChanged() {
+ dateField.setEnabled(isEnabled() && !isReadOnly());
+ }
+
+}
\ No newline at end of file
Added:
trunk/spring-richclient/sandbox/src/test/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinderTests.java
===================================================================
---
trunk/spring-richclient/sandbox/src/test/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinderTests.java
(rev 0)
+++
trunk/spring-richclient/sandbox/src/test/java/org/springframework/richclient/form/binding/swing/NachoCalendarDateFieldBinderTests.java
2006-06-27 09:54:09 UTC (rev 1216)
@@ -0,0 +1,106 @@
+/*
+ * 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 net.sf.nachocalendar.components.DateField;
+import org.springframework.binding.form.FieldMetadata;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for NachoCalendarDateFieldBinder and NachoCalendarDateFieldBinding
+ *
+ * @author Geoffrey De Smet
+ */
+public class NachoCalendarDateFieldBinderTests extends BindingAbstractTests {
+
+ private NachoCalendarDateFieldBinder binder;
+
+ private NachoCalendarDateFieldBinding binding;
+
+ private DateField dateField;
+
+ protected String setUpBinding() {
+// Application.load(null);
+// new Application(new DefaultApplicationLifecycleAdvisor());
+// StaticApplicationContext applicationContext = new
StaticApplicationContext();
+// Application.services().setApplicationContext(applicationContext);
+// applicationContext.refresh();
+
+ Map context = new HashMap();
+
+ binder = new NachoCalendarDateFieldBinder();
+ binding = (NachoCalendarDateFieldBinding) binder.bind(fm,
"dateProperty", context);
+ dateField = (DateField) binding.getControl();
+
+ return "dateProperty";
+ }
+
+ public void testInitialValue() {
+ Date date = createDate(1981, 10, 16);
+ vm.setValue(date);
+ assertNotNull(vm.getValue());
+ }
+
+ private Date createDate(int year, int month, int day) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(year, month, day, 0, 0, 0);
+ Date date = calendar.getTime();
+ return date;
+ }
+
+ public void testComponentTracksEnabledChanges() {
+ assertEquals(true, dateField.isEnabled());
+ fm.setEnabled(false);
+ assertEquals(false, dateField.isEnabled());
+ fm.setEnabled(true);
+ assertEquals(true, dateField.isEnabled());
+ }
+
+ public void testComponentTracksReadOnlyChanges() {
+ FieldMetadata state = fm.getFieldMetadata("dateProperty");
+ assertEquals(true, dateField.isEnabled());
+ state.setReadOnly(true);
+ assertEquals(false, dateField.isEnabled());
+ state.setReadOnly(false);
+ assertEquals(true, dateField.isEnabled());
+ }
+
+ public void testComponentUpdatesValueModel() {
+ Date date1 = createDate(1981, 10, 16);
+ dateField.setValue(date1);
+ assertEquals(date1, vm.getValue());
+ dateField.setValue(null);
+ assertEquals(null, vm.getValue());
+ Date date2 = createDate(1999, 11, 31);
+ dateField.setValue(date2);
+ assertEquals(date2, vm.getValue());
+ }
+
+ public void testValueModelUpdatesComponent() {
+ Date date1 = createDate(1981, 10, 16);
+ vm.setValue(date1);
+ assertEquals(date1, dateField.getValue());
+ vm.setValue(null);
+ assertEquals(null, dateField.getValue());
+ Date date2 = createDate(1999, 11, 31);
+ vm.setValue(date2);
+ assertEquals(date2, dateField.getValue());
+ }
+}
\ No newline at end of file
Modified: trunk/spring-richclient/support/pom.xml
===================================================================
--- trunk/spring-richclient/support/pom.xml 2006-06-27 07:52:17 UTC (rev
1215)
+++ trunk/spring-richclient/support/pom.xml 2006-06-27 09:54:09 UTC (rev
1216)
@@ -114,6 +114,11 @@
<groupId>net.java.dev.glazedlists</groupId>
<artifactId>glazedlists</artifactId>
</dependency>
+ <dependency>
+ <groupId>net.sf.nachocalendar</groupId>
+ <artifactId>nachocalendar</artifactId>
+ <optional>true</optional>
+ </dependency>
<!-- Utils -->
<dependency>
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-27 07:52:17 UTC (rev 1215)
+++
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
2006-06-27 09:54:09 UTC (rev 1216)
@@ -17,14 +17,18 @@
import java.util.List;
import java.util.Map;
+import java.util.Date;
/**
* @author Oliver Hutchison
+ * @author Geoffrey De Smet
*/
public class TestBean {
private String simpleProperty;
+ private Date dateProperty;
+
public TestLabeledEnum enumProperty;
private Map mapProperty;
@@ -38,7 +42,7 @@
public Object readOnly;
public Object writeOnly;
-
+
public Number numberProperty;
public Number getNumberProperty() {
@@ -57,6 +61,14 @@
this.simpleProperty = simpleProperty;
}
+ public Date getDateProperty() {
+ return dateProperty;
+ }
+
+ public void setDateProperty(Date dateProperty) {
+ this.dateProperty = dateProperty;
+ }
+
public TestLabeledEnum getEnumProperty() {
return enumProperty;
}
@@ -104,4 +116,5 @@
public void setWriteOnly(Object writeOnly) {
this.writeOnly = writeOnly;
}
+
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs