|
Lines 11-17
Link Here
|
| 11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.jface.text.templates; |
12 |
package org.eclipse.jface.text.templates; |
| 13 |
|
13 |
|
|
|
14 |
import java.util.List; |
| 15 |
import java.util.Locale; |
| 16 |
|
| 14 |
import com.ibm.icu.text.DateFormat; |
17 |
import com.ibm.icu.text.DateFormat; |
|
|
18 |
import com.ibm.icu.text.SimpleDateFormat; |
| 15 |
import com.ibm.icu.util.Calendar; |
19 |
import com.ibm.icu.util.Calendar; |
| 16 |
|
20 |
|
| 17 |
/** |
21 |
/** |
|
Lines 113-121
Link Here
|
| 113 |
public Date() { |
117 |
public Date() { |
| 114 |
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ |
118 |
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ |
| 115 |
} |
119 |
} |
| 116 |
protected String resolve(TemplateContext context) { |
120 |
|
| 117 |
return DateFormat.getDateInstance().format(new java.util.Date()); |
121 |
public void resolve(TemplateVariable variable, TemplateContext context) { |
|
|
122 |
List params= variable.getVariableType().getParams(); |
| 123 |
|
| 124 |
Locale locale=Locale.getDefault(); |
| 125 |
if (params.size()>=2) { |
| 126 |
String localeString= (String)params.get(1); |
| 127 |
String[] localeParts=localeString.split("_"); //$NON-NLS-1$ |
| 128 |
if (localeParts.length==1) { |
| 129 |
locale= new Locale(localeParts[0]); |
| 130 |
} else if (localeParts.length==2) { |
| 131 |
locale= new Locale(localeParts[0], localeParts[1]); |
| 132 |
} else { |
| 133 |
throw new IllegalArgumentException(localeString); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
DateFormat format; |
| 138 |
if (params.size()>=1) { |
| 139 |
format= new SimpleDateFormat((String)params.get(0), locale); |
| 140 |
} else { |
| 141 |
format= DateFormat.getDateInstance(DateFormat.MEDIUM, locale); |
| 142 |
} |
| 143 |
|
| 144 |
variable.setValue(format.format(new java.util.Date())); |
| 118 |
} |
145 |
} |
|
|
146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 119 |
} |
150 |
} |
| 120 |
|
151 |
|
| 121 |
/** |
152 |
/** |