• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: D2W Timestamp attribute component
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: D2W Timestamp attribute component


  • Subject: Re: D2W Timestamp attribute component
  • From: Daniel Beatty <email@hidden>
  • Date: Wed, 26 Jan 2011 09:13:18 -0800

Greetings Mark,
It works for me.  Thank you so much.

Thank you,

Dan Beatty, ABD
Ph.D. Student
Texas Tech University
email@hidden
http://web.me.com/danielbeatty/My_Home_Page/Welcome.html
(806)438-6620
On Jan 19, 2011, at 1:31 PM, Mark Wardle wrote:

> This is probably hopelessly broken but it seems to work for me:
>
> Add the rule "shouldEditTime" for the property.
>
> ****************
> RSD2WDatePicker.html
> <webobject name="ChooseDate"/><webobject
> name="ShouldEditTime"><webobject name="Hours"/><webobject
> name="Minutes"/></webobject>
>
> ****************
> RSD2WDatePicker.wod
> ChooseDate: AjaxDatePicker {
> 	value = objectPropertyValue;
> 	format = format;
> }
>
> ShouldEditTime: WOConditional {
> 	condition = shouldEditTime;
> }
>
> Hours: WOPopUpButton {
> 	list = hoursList;
> 	selection = hours;
> }
> Minutes: WOPopUpButton {
> 	list = minutesList;
> 	selection = minutes;
> }
>
> ****************
> RSD2WDatePicker.java
>
> package com.eldrix.rsd2w;
>
> import java.util.Calendar;
> import java.util.Date;
> import java.util.GregorianCalendar;
>
> import com.webobjects.appserver.WOContext;
> import com.webobjects.appserver.WORequest;
> import com.webobjects.foundation.NSArray;
> import com.webobjects.foundation.NSMutableArray;
> import com.webobjects.foundation.NSTimestamp;
> import com.webobjects.foundation.NSValidation;
>
> import er.directtoweb.components.ERDCustomEditComponent;
> import er.extensions.formatters.ERXTimestampFormatter;
>
> /**
> * D2W component to edit a date.
> * Uses Chuck Hill's AjaxDatePicker
> *
> * @binding formatter : a text string (format) for the date format
> * @binding shouldEditTime : whether to edit the time as well?
> *
> * FIXME: This doesn't use localisation...
> *
> * @author mark
> * @see er.ajax.AjaxDatePicker
> */
> public class RSD2WDatePicker extends ERDCustomEditComponent {
> 	protected String _format;
> 	protected GregorianCalendar _calendar;
> 	protected static final NSArray<String> _hoursList = new
> NSMutableArray<String>() {{
> 			for(int i=0; i < 24; i++) {
> 				add(String.format("d", i));
> 			}
> 	}};
> 	protected static final NSArray<String> _minutesList = new
> NSMutableArray<String>() {{
> 		for (int i=0; i < 60; i++) {
> 			add(String.format("d", i));
> 		}
> 	}};
>
> 	public interface Keys extends ERDCustomEditComponent.Keys {
> 		public static final String formatter = "formatter";
> 		public static final String shouldEditTime = "shouldEditTime";
> 	}
>
> 	public RSD2WDatePicker(WOContext context) {
> 		super(context);
> 	}
>
> 	public NSArray<String> hoursList() {
> 		return _hoursList;
> 	}
> 	public NSArray<String> minutesList() {
> 		return _minutesList;
> 	}
>
> 	/**
> 	 * Initialises calendar from the current property value.
> 	 * @return
> 	 */
> 	public GregorianCalendar calendar() {
> 		if (_calendar == null) {
> 			_calendar = new GregorianCalendar();
> 			_calendar.setLenient(true);
> 			if (date() != null) {
> 				_calendar.setTime(date());
> 			}
> 		}
> 		return _calendar;
> 	}
>
> 	public String hours() {
> 		return String.format("d", calendar().get(Calendar.HOUR_OF_DAY));
> 	}
> 	public String minutes() {
> 		return String.format("d", calendar().get(Calendar.MINUTE));
> 	}
>
> 	public void setHours(String hours) {
> 		calendar().set(Calendar.HOUR_OF_DAY, Integer.parseInt(hours));
> 	}
> 	public void setMinutes(String minutes) {
> 		calendar().set(Calendar.MINUTE, Integer.parseInt(minutes));
> 	}
>
> 	/**
> 	 * We try to keep our calendar object up to date with property changes.
> 	 */
> 	@Override public void setObjectPropertyValue(Object value) {
> 		if (value == null || value instanceof Date) {
> 			if (value != null) {
> 				calendar().setTime((Date)value);
> 			}
> 			super.setObjectPropertyValue(value);
> 		}
> 		else throw new IllegalArgumentException("RSD2WDatePicker must be
> used with an NSTimestamp");
> 	}
>
> 	public NSTimestamp date() {
> 		Object o = objectPropertyValue();
> 		if (o == null || o instanceof NSTimestamp) {
> 			return (NSTimestamp) o;
> 		}
> 		throw new IllegalArgumentException("RSD2WDatePicker must be used
> with an NSTimestamp");
> 	}
>
> 	@Override public boolean synchronizesVariablesWithBindings() {
> 		return false;
> 	}
>
> 	public String format() {
> 		if(_format == null) {
> 			_format = (String)valueForBinding("formatter");
> 		}
> 		if(_format == null || _format.length() == 0) {
> 			_format = ERXTimestampFormatter.DEFAULT_PATTERN;
> 		}
> 		return _format;
> 	}
>
> 	public void setFormatter(String format) {
> 		_format = format;
> 	}
>
> 	public boolean shouldEditTime() {
> 		return booleanValueForBinding(Keys.shouldEditTime);
> 	}
>
> 	public void takeValuesFromRequest (WORequest request, WOContext context) {
> 		super.takeValuesFromRequest (request,context);
> 		if (_calendar != null && objectPropertyValue() != null) {
> 			NSTimestamp date = new NSTimestamp(calendar().getTime());
> 			try {
> 				object().validateTakeValueForKeyPath(date, key());
> 			} catch (NSValidation.ValidationException v) {
> 				parent().validationFailedWithException(v,date,key());
> 			} catch(Exception e) {
> 				parent().validationFailedWithException(e,date,key());
> 			}
> 		}
> 	}
> }
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >D2W Timestamp attribute component (From: Dan Beatty <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Ramsey Gurley <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Travis Britt <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Ramsey Gurley <email@hidden>)
 >Re: D2W Timestamp attribute component (From: David Avendasora <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Ramsey Gurley <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Chuck Hill <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Ramsey Gurley <email@hidden>)
 >Re: D2W Timestamp attribute component (From: Mark Wardle <email@hidden>)

  • Prev by Date: Re: java.lang.NoClassDefFoundError
  • Next by Date: Replacing XServes
  • Previous by thread: Re: D2W Timestamp attribute component
  • Next by thread: Re: D2W Timestamp attribute component
  • Index(es):
    • Date
    • Thread