comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.d @ 85:6be48cf9f95c

Work on databinding
author Frank Benoit <benoit@tionex.de>
date Sat, 18 Apr 2009 13:54:50 +0200
parents 0a55d2d5a946
children
comparison
equal deleted inserted replaced
84:fcf926c91ca4 85:6be48cf9f95c
30 * string representation may not cover the sub-second range, time-only string 30 * string representation may not cover the sub-second range, time-only string
31 * representations will be counted from the beginning of the era, etc. 31 * representations will be counted from the beginning of the era, etc.
32 * </p> 32 * </p>
33 */ 33 */
34 public abstract class DateConversionSupport { 34 public abstract class DateConversionSupport {
35 private final static int DATE_FORMAT=DateFormat.SHORT; 35 private const static int DATE_FORMAT=DateFormat.SHORT;
36 private final static int DEFAULT_FORMATTER_INDEX=0; 36 private const static int DEFAULT_FORMATTER_INDEX=0;
37 37
38 private final static int NUM_VIRTUAL_FORMATTERS=1; 38 private const static int NUM_VIRTUAL_FORMATTERS=1;
39 39
40 /** 40 /**
41 * Alternative formatters for date, time and date/time. 41 * Alternative formatters for date, time and date/time.
42 * Raw milliseconds are covered as a special case. 42 * Raw milliseconds are covered as a special case.
43 */ 43 */
44 // TODO: These could be shared, but would have to be synchronized. 44 // TODO: These could be shared, but would have to be synchronized.
45 private DateFormat[] formatters = { 45 private static DateFormat[] formatters;
46 new SimpleDateFormat(BindingMessages.getStringcast(BindingMessages.DATE_FORMAT_DATE_TIME)), 46 static this(){
47 new SimpleDateFormat(BindingMessages.getStringcast(BindingMessages.DATEFORMAT_TIME)), 47 formatters = [ cast(DateFormat)
48 new SimpleDateFormat(BindingMessages.getString(BindingMessages.DATE_FORMAT_DATE_TIME)),
49 new SimpleDateFormat(BindingMessages.getString(BindingMessages.DATEFORMAT_TIME)),
48 DateFormat.getDateTimeInstance(DATE_FORMAT, DateFormat.SHORT), 50 DateFormat.getDateTimeInstance(DATE_FORMAT, DateFormat.SHORT),
49 DateFormat.getDateInstancecast(DATE_FORMAT), 51 DateFormat.getDateInstance(DATE_FORMAT),
50 DateFormat.getTimeInstancecast(DateFormat.SHORT), 52 DateFormat.getTimeInstance(DateFormat.SHORT),
51 DateFormat.getDateTimeInstance(DATE_FORMAT,DateFormat.MEDIUM), 53 DateFormat.getDateTimeInstance(DATE_FORMAT,DateFormat.MEDIUM),
52 DateFormat.getTimeInstancecast(DateFormat.MEDIUM) 54 DateFormat.getTimeInstance(DateFormat.MEDIUM)
53 }; 55 ];
56 }
54 57
55 /** 58 /**
56 * Tries all available formatters to parse the given string according to the 59 * Tries all available formatters to parse the given string according to the
57 * default locale or as a raw millisecond value and returns the result of the 60 * default locale or as a raw millisecond value and returns the result of the
58 * first successful run. 61 * first successful run.
102 105
103 protected String format(Date date,int formatterIdx) { 106 protected String format(Date date,int formatterIdx) {
104 if(formatterIdx>=0) { 107 if(formatterIdx>=0) {
105 return formatters[formatterIdx].format(date); 108 return formatters[formatterIdx].format(date);
106 } 109 }
107 return String.valueOf(date.getTime()); 110 return String_valueOf(date.getTime());
108 } 111 }
109 112
110 protected int numFormatters() { 113 protected int numFormatters() {
111 return formatters.length+NUM_VIRTUAL_FORMATTERS; 114 return formatters.length+NUM_VIRTUAL_FORMATTERS;
112 } 115 }
121 * @param index 124 * @param index
122 * @return date format 125 * @return date format
123 */ 126 */
124 protected DateFormat getDateFormat(int index) { 127 protected DateFormat getDateFormat(int index) {
125 if (index < 0 || index >= formatters.length) { 128 if (index < 0 || index >= formatters.length) {
126 throw new IllegalArgumentException("'index' [" + index + "] is out of bounds."); //$NON-NLS-1$//$NON-NLS-2$ 129 throw new IllegalArgumentException(Format("'index' [{}] is out of bounds.", index )); //$NON-NLS-1$//$NON-NLS-2$
127 } 130 }
128 131
129 return formatters[index]; 132 return formatters[index];
130 } 133 }
131 } 134 }