Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5c8128b4e012515982d62b13b987639b3d1b668b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 * Copyright (c) 2007, 2008 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Dmitry Stadnik (Borland) - initial implementation
 *    Artem Tikhomirov (Borland) - [235113] alternative parser access
 *                                 [244419] custom parsers
 *                                 initial API
 */

«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»

«EXTENSION impl::parsers::i18n»

«DEFINE Main FOR gmfgen::PredefinedParser»
«EXPAND xpt::Common::copyright FOR holder.editorGen-»
package «holder.implPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «className» extends «EXPAND impl::parsers::AbstractParser::qualifiedClassName FOR holder» {

«EXPAND fields»
«EXPAND cons»
«EXPAND aux_methods»
«EXPAND parser_getEditStringMethod»
«EXPAND parser_isValidEditStringMethod»
«EXPAND parser_getParseCommandMethod»
«EXPAND parser_getPrintStringMethod»
«EXPAND parser_isAffectingEventMethod»
«EXPAND parser_getCompletionProcessorMethod»
«EXPAND additions»
}
«ENDDEFINE» 

«DEFINE additions FOR gmfgen::PredefinedParser»«ENDDEFINE»

«DEFINE fields FOR gmfgen::PredefinedParser-»
«IF viewMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT or viewMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
	«EXPAND xpt::Common::generatedMemberComment»
	private String defaultPattern;

	«EXPAND xpt::Common::generatedMemberComment»
	private String defaultEditablePattern;
«ENDIF-»
«IF viewMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT»
	«EXPAND xpt::Common::generatedMemberComment»
	private java.text.MessageFormat viewProcessor;

	«EXPAND xpt::Common::generatedMemberComment»
	private java.text.MessageFormat editorProcessor;
«ENDIF-»
«IF editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT»
	«EXPAND xpt::Common::generatedMemberComment»
	private java.text.MessageFormat editProcessor;
«ENDIF-»
«ENDDEFINE»

«DEFINE cons FOR gmfgen::PredefinedParser-»
	«EXPAND xpt::Common::generatedMemberComment»
	public «className»(org.eclipse.emf.ecore.EAttribute[] features) {
		super(features);
«IF viewMethod = gmfgen::LabelTextAccessMethod::NATIVE or editMethod = gmfgen::LabelTextAccessMethod::NATIVE-»
		if (features.length != 1) {
			throw new IllegalArgumentException(java.util.Arrays.toString(features));
		}
«ENDIF-»
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public «className»(org.eclipse.emf.ecore.EAttribute[] features, org.eclipse.emf.ecore.EAttribute[] editableFeatures) {
		super(features, editableFeatures);
«IF viewMethod = gmfgen::LabelTextAccessMethod::NATIVE or editMethod = gmfgen::LabelTextAccessMethod::NATIVE-»
		if (features.length != 1) {
			throw new IllegalArgumentException(java.util.Arrays.toString(features));
		}
		if (editableFeatures.length != 1) {
			throw new IllegalArgumentException(java.util.Arrays.toString(editableFeatures));
		}
«ENDIF-»
	}
«ENDDEFINE»

«DEFINE aux_methods FOR gmfgen::PredefinedParser-»
«IF viewMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected String getDefaultPattern() {
		if (defaultPattern == null) {
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < features.length; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append('{');
				sb.append(i);
				sb.append('}');
			}
			defaultPattern = sb.toString();
		}
		return defaultPattern;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void setViewPattern(String viewPattern) {
		super.setViewPattern(viewPattern);
		viewProcessor = null;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void setEditorPattern(String editorPattern) {
		super.setEditorPattern(editorPattern);
		editorProcessor = null;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected java.text.MessageFormat getViewProcessor() {
		if (viewProcessor == null) {
			viewProcessor = new java.text.MessageFormat(getViewPattern() == null ? getDefaultPattern() : getViewPattern());
		}
		return viewProcessor;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected java.text.MessageFormat getEditorProcessor() {
		if (editorProcessor == null) {
			editorProcessor = new java.text.MessageFormat(getEditorPattern() == null ? getDefaultEditablePattern() : getEditorPattern());
		}
		return editorProcessor;
	}
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected String getDefaultPattern() {
		if (defaultPattern == null) {
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < features.length; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append('%');
				sb.append(i + 1);
				sb.append('$');
				sb.append('s');
			}
			defaultPattern = sb.toString();
		}
		return defaultPattern;
	}
«ENDIF-»
«IF viewMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT or editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected String getDefaultEditablePattern() {
		if (defaultEditablePattern == null) {
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < editableFeatures.length; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append('{');
				sb.append(i);
				sb.append('}');
			}
			defaultEditablePattern = sb.toString();
		}
		return defaultEditablePattern;
	}
«ENDIF-»
«IF viewMethod = gmfgen::LabelTextAccessMethod::PRINTF or editMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
	«EXPAND xpt::Common::generatedMemberComment»
	protected String getDefaultEditablePattern() {
		if (defaultEditablePattern == null) {
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < editableFeatures.length; i++) {
				if (i > 0) {
					sb.append(' ');
				}
				sb.append('%');
				sb.append(i + 1);
				sb.append('$');
				sb.append('s');
			}
			defaultEditablePattern = sb.toString();
		}
		return defaultEditablePattern;
	}
«ENDIF-»
«IF editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
	«EXPAND xpt::Common::generatedMemberComment»
	public void setEditPattern(String editPattern) {
		super.setEditPattern(editPattern);
		editProcessor = null;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected java.text.MessageFormat getEditProcessor() {
		if (editProcessor == null) {
			editProcessor = new java.text.MessageFormat(getEditPattern() == null ? getDefaultEditablePattern() : getEditPattern());
		}
		return editProcessor;
	}
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::REGEXP-»
	«EXPAND xpt::Common::generatedMemberComment»
	public String getEditPattern() {
		String pattern = super.getEditPattern();
		return pattern != null ? pattern : " ";«EXPAND xpt::Common::nonNLS»
	}
«ENDIF-»
«ENDDEFINE»

«DEFINE parser_getEditStringMethod FOR gmfgen::PredefinedParser-»
	«EXPAND xpt::Common::generatedMemberComment»
	public String getEditString(org.eclipse.core.runtime.IAdaptable adapter, int flags) {
«IF viewMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
		org.eclipse.emf.ecore.EObject element =	(org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
		return getEditorProcessor().format(getEditableValues(element), new StringBuffer(),	new java.text.FieldPosition(0)).toString();
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
		org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
		String pattern = getEditorPattern() == null ? getDefaultEditablePattern() : getEditorPattern();
		return String.format(pattern, getEditableValues(element));
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::REGEXP-»
		return "";«EXPAND xpt::Common::nonNLS»
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::NATIVE-»
		org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
		String s = org.eclipse.emf.ecore.util.EcoreUtil.convertToString(editableFeatures[0].getEAttributeType(), element.eGet(editableFeatures[0]));
		return s != null ? s : "";«EXPAND xpt::Common::nonNLS»
«ENDIF-»
	}
«ENDDEFINE»

«DEFINE parser_isValidEditStringMethod FOR gmfgen::PredefinedParser-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus isValidEditString(org.eclipse.core.runtime.IAdaptable adapter, String editString) {
«IF editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
		java.text.ParsePosition pos = new java.text.ParsePosition(0);
		Object[] values = getEditProcessor().parse(editString, pos);
		if (values == null) {
			return new org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus(
					«holder.editorGen.plugin.getActivatorQualifiedClassName()».ID,
					org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus.UNEDITABLE,
					org.eclipse.osgi.util.NLS.bind(
							«EXPAND xpt::Externalizer::accessorCall(i18nKeyForMessageFormatParserInvalidInputError()) FOR holder.editorGen»,
							new Integer(pos.getErrorIndex())));
		}
		return validateNewValues(values);
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
		return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.UNEDITABLE_STATUS;
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::REGEXP-»
		if (editString == null) {
			return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.UNEDITABLE_STATUS;
		}
		Object[] values = editString.split(getEditPattern());
		return validateNewValues(values);
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::NATIVE-»
		return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.EDITABLE_STATUS;
«ENDIF-»
	}
«ENDDEFINE»

«DEFINE parser_getParseCommandMethod FOR gmfgen::PredefinedParser-»
	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.common.core.command.ICommand getParseCommand(org.eclipse.core.runtime.IAdaptable adapter, String newString, int flags) {
«IF editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
		Object[] values = getEditProcessor().parse(newString, new java.text.ParsePosition(0));
		return getParseCommand(adapter, values, flags);
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
		return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::REGEXP-»
		if (newString == null) {
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
		}
		Object[] values = newString.split(getEditPattern());
		return super.getParseCommand(adapter, values, flags);
«ELSEIF editMethod = gmfgen::LabelTextAccessMethod::NATIVE-»
		Object value = org.eclipse.emf.ecore.util.EcoreUtil.createFromString(editableFeatures[0].getEAttributeType(), newString);
		return getParseCommand(adapter, new Object[] { value }, flags);
«ENDIF-»
	}
«ENDDEFINE»

«DEFINE parser_getPrintStringMethod FOR gmfgen::PredefinedParser-»
	«EXPAND xpt::Common::generatedMemberComment»
	public String getPrintString(org.eclipse.core.runtime.IAdaptable adapter, int flags) {
«IF viewMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT-»
		org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
		return getViewProcessor().format(getValues(element), new StringBuffer(), new java.text.FieldPosition(0)).toString();
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::PRINTF-»
		org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
		return String.format(getViewPattern() == null ? getDefaultPattern() : getViewPattern(), getValues(element));
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::REGEXP-»
		return "";«EXPAND xpt::Common::nonNLS»
«ELSEIF viewMethod = gmfgen::LabelTextAccessMethod::NATIVE-»
		org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
		String s = org.eclipse.emf.ecore.util.EcoreUtil.convertToString(features[0].getEAttributeType(), element.eGet(features[0]));
		return s != null ? s : "";«EXPAND xpt::Common::nonNLS»
«ENDIF-»
	}
«ENDDEFINE»

«DEFINE parser_isAffectingEventMethod FOR gmfgen::PredefinedParser-»
«REM»NO-OP, rely on superclass for now«ENDREM-»
«ENDDEFINE»

«DEFINE parser_getCompletionProcessorMethod FOR gmfgen::PredefinedParser-»
«REM»NO-OP, rely on superclass for now«ENDREM-»
«ENDDEFINE»

«DEFINE i18nValues FOR gmfgen::GenParsers-»
«IF (implementations)[gmfgen::PredefinedParser]->exists(p | p.editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT)»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForMessageFormatParserInvalidInputError(), 'Invalid input at {0}')-»
«ENDIF-»
«ENDDEFINE»

«DEFINE i18nAccessors FOR gmfgen::GenParsers-»
«IF (implementations)[gmfgen::PredefinedParser]->exists(p | p.editMethod = gmfgen::LabelTextAccessMethod::MESSAGE_FORMAT)»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForMessageFormatParserInvalidInputError())-»
«ENDIF-»
«ENDDEFINE»

Back to the top