Re: [Microba-controls] commitEdit of a null Date value
Brought to you by:
michaelbaranov
From: Michael B. <mic...@gm...> - 2007-10-19 10:50:30
|
Chris, Thanks for digging in! One more question before we go on: DateFormat vs. DateFormatter. You're using DateFormatter and even suggest to update the API for it. But what's the purpose? What's the difference? Can't you do the same null/empty check with DateFormat? DateFormat is in the API already. About the deep-buried UI: it was the initial idea to hide the implementation, the fact that DatePicker is really composed of a text edit and a button. Maybe it's a good idea to expose the parts from their UI delegates and make them accessible like this: ( (DatePickerUI)picker.getUI() ).getButton() // etc... Is this what you mean? Chris, please get the latest sources from sourceforge. If you can't make a patch for me, plz send me back the modified sources. Cheers! Michael. > Hi Michael, > > Send me your latest source file for BasicDatePickerUI and I'll do a > patch if you like (have never done such a thing before); however all > that needs to be done is to use this new inner class > NullCapableDateFormatter instead of DateFormatter as your code has it. I > have since made the new inner class private and static as well - but > haven't really tested it. Apart from that all the necessary code is as > sent. Alternatively you could change the code so that API users can put > in their own DateFormatter. One small problem with this I see is that > your UIs seem to be hard to get to - there is no reference to them from > the controller as I would expect. I have had to code this method: > > public static Component getDisplay( DatePicker dp) > > { > > Component result; > > Component components[] = dp.getComponents(); > > //Print.prArray( components, "Which one is a text field?"); > > //A: > > //value: null, class: com.michaelbaranov.microba.calendar.ui.basic.BasicDatePickerUI$MyJFormattedTextField > > //value: null, class: javax.swing.JButton > > result = components[0]; > > return result; > > } > > Is there a better way? > > I experienced the problem when programmatically setting the date to > null. What would happen was that a null wouldn't get through the > commitEdit() validation (which presumably happened at the time of a > focus change), and the last successfully committed value would come back > to being the actual value. This was a difficult thing to track down, and > indeed also exists on MDateEntryField, and was the reason that I came to > your Component - hoping it would allow null date values. > > - Chris Murphy (www.strandz.org) > > Michael Baranov wrote: > >> Chris, >> >> Thanks for the path! But can you describe the effect of the change >> from the point of view of a user? What was wrong (but now OK)? Can you >> please send me a regular machine-processable patch for >> BasicDatePicketUI against the latest sources (so I ca patch a local >> copy free of mistakes)? >> >> Thanks for using Microba and contributing! >> >> Chris Murphy wrote: >> >>> Hi Michael, >>> >>> I found something for your consideration, which has required changing >>> the microba source as configuration was not possible. The problem is >>> that JFormattedTextField does not properly support the concept of a >>> null date. A null date can't be committed (commitEdit()) to a >>> JFormattedTextField. As you can see from the code Sun's bug database >>> offers a workaround that I've implemented on your code. This code is >>> from changes I've made to BasicDatePickerUI: >>> >>> private DefaultFormatterFactory createFormatterFactory() { >>> return new DefaultFormatterFactory(new >>> NullCapableDateFormatter(peer >>> .getDateFormat())); >>> } >>> >>> >>> /** >>> * To do this enhancement: >>> * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048 >>> */ >>> public class NullCapableDateFormatter extends DateFormatter >>> { >>> public NullCapableDateFormatter(DateFormat dateFormat) >>> { >>> super( dateFormat); >>> } >>> >>> public Object stringToValue(String string) >>> throws ParseException >>> { >>> if(string == null || string.length() == 0) >>> { >>> return null; >>> } >>> return super.stringToValue(string); >>> } >>> } >>> >>> >>> thanks - Chris >>> >>> ------------------------------------------------------------------------- >>> >>> This SF.net email is sponsored by: Splunk Inc. >>> Still grepping through log files to find problems? Stop. >>> Now Search log events and configuration files using AJAX and a browser. >>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>> _______________________________________________ >>> Microba-controls mailing list >>> Mic...@li... >>> https://lists.sourceforge.net/lists/listinfo/microba-controls >>> >>> >>> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > > |