1 12 package org.eclipse.jface.text.templates; 13 14 import com.ibm.icu.text.DateFormat; 15 import com.ibm.icu.util.Calendar; 16 17 25 public class GlobalTemplateVariables { 26 27 28 public static final String SELECTION= "selection"; 30 33 public static class Cursor extends SimpleTemplateVariableResolver { 34 35 36 public static final String NAME= "cursor"; 38 41 public Cursor() { 42 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); setEvaluationString(""); } 45 } 46 47 51 public static class WordSelection extends SimpleTemplateVariableResolver { 52 53 54 public static final String NAME= "word_selection"; 56 59 public WordSelection() { 60 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); } 62 protected String resolve(TemplateContext context) { 63 String selection= context.getVariable(SELECTION); 64 if (selection == null) 65 return ""; return selection; 67 } 68 } 69 70 74 public static class LineSelection extends SimpleTemplateVariableResolver { 75 76 77 public static final String NAME= "line_selection"; 79 82 public LineSelection() { 83 super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); } 85 protected String resolve(TemplateContext context) { 86 String selection= context.getVariable(SELECTION); 87 if (selection == null) 88 return ""; return selection; 90 } 91 } 92 93 96 public static class Dollar extends SimpleTemplateVariableResolver { 97 100 public Dollar() { 101 super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); setEvaluationString("$"); } 104 } 105 106 109 public static class Date extends SimpleTemplateVariableResolver { 110 113 public Date() { 114 super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); } 116 protected String resolve(TemplateContext context) { 117 return DateFormat.getDateInstance().format(new java.util.Date ()); 118 } 119 } 120 121 124 public static class Year extends SimpleTemplateVariableResolver { 125 128 public Year() { 129 super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); } 131 protected String resolve(TemplateContext context) { 132 return Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); 133 } 134 } 135 136 139 public static class Time extends SimpleTemplateVariableResolver { 140 143 public Time() { 144 super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); } 146 147 150 protected String resolve(TemplateContext context) { 151 return DateFormat.getTimeInstance().format(new java.util.Date ()); 152 } 153 } 154 155 158 public static class User extends SimpleTemplateVariableResolver { 159 162 public User() { 163 super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); } 165 166 169 protected String resolve(TemplateContext context) { 170 return System.getProperty("user.name"); } 172 } 173 } 174 | Popular Tags |