|
Lines 8-17
Link Here
|
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
| 10 |
* Sebastian Davids: sdavids@gmx.de - see bug 25376 |
10 |
* Sebastian Davids: sdavids@gmx.de - see bug 25376 |
|
|
11 |
* Pramod Goyal: pramod.goyal@gmail.com - this is a bug - https://bugs.eclipse.org/75981 |
| 11 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
| 12 |
package org.eclipse.jface.text.templates; |
13 |
package org.eclipse.jface.text.templates; |
| 13 |
|
14 |
|
|
|
15 |
import java.util.List; |
| 16 |
import java.util.Locale; |
| 17 |
|
| 14 |
import com.ibm.icu.text.DateFormat; |
18 |
import com.ibm.icu.text.DateFormat; |
|
|
19 |
import com.ibm.icu.text.SimpleDateFormat; |
| 15 |
import com.ibm.icu.util.Calendar; |
20 |
import com.ibm.icu.util.Calendar; |
| 16 |
|
21 |
|
| 17 |
/** |
22 |
/** |
|
Lines 113-120
Link Here
|
| 113 |
public Date() { |
118 |
public Date() { |
| 114 |
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ |
119 |
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ |
| 115 |
} |
120 |
} |
| 116 |
protected String resolve(TemplateContext context) { |
121 |
|
| 117 |
return DateFormat.getDateInstance().format(new java.util.Date()); |
122 |
public void resolve(TemplateVariable variable, TemplateContext context) { |
|
|
123 |
List params= variable.getVariableType().getParams(); |
| 124 |
DateFormat dateFormat = null; |
| 125 |
if (params.size() == 0) { |
| 126 |
dateFormat= DateFormat.getDateInstance(); |
| 127 |
} |
| 128 |
else if (params.size() == 1) { |
| 129 |
dateFormat= new SimpleDateFormat((String)params.get(0)); |
| 130 |
} |
| 131 |
else if (params.size() == 2) { |
| 132 |
String localeString= (String)params.get(1); |
| 133 |
String[] localeParts= localeString.split("_"); |
| 134 |
if (localeParts.length == 1) { |
| 135 |
dateFormat= new SimpleDateFormat((String)params.get(0), new Locale(localeParts[0])); |
| 136 |
} |
| 137 |
else if (localeParts.length == 2) { |
| 138 |
dateFormat= new SimpleDateFormat((String)params.get(0), new Locale(localeParts[0], localeParts[1])); |
| 139 |
} |
| 140 |
} |
| 141 |
if (dateFormat != null) { |
| 142 |
variable.setValue(dateFormat.format(new java.util.Date())); |
| 143 |
variable.setUnambiguous(true); |
| 144 |
} |
| 145 |
else { |
| 146 |
super.resolve(variable, context); |
| 147 |
} |
| 118 |
} |
148 |
} |
| 119 |
} |
149 |
} |
| 120 |
|
150 |
|