Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ddfbd57df8d247865eb023c876414829cb74c2ee (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
/*
 * Copyright (c) 2010 Artem Tikhomirov and others
 * 
 * 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:
 *    Artem Tikhomirov (independent) - Initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»

«EXTENSION xpt::StringOperations»

«EXTENSION impl::parsers::expression»

«DEFINE Main FOR gmfgen::ExpressionLabelParser-»
«EXPAND xpt::Common::copyright FOR holder.editorGen-»
«EXPAND xpt::Common::packageStatement FOR self.getQualifiedClassName()»

«EXPAND xpt::Common::generatedClassComment»
public class «self.getQualifiedClassName().xpandSplit('\\.')->last()»«EXPAND extendsList»«EXPAND implementsList» {
«EXPAND impl::parsers::ExpressionLabelParser::fields-»
«EXPAND impl::parsers::ExpressionLabelParser::cons(getQualifiedClassName().xpandSplit('\\.')->last())-»
«EXPAND body»
«EXPAND additions»
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::ExpressionLabelParser»«ENDDEFINE»
«DEFINE extendsList FOR gmfgen::ExpressionLabelParser»
	«IF isViewExpressionDefinedAndOcl()-»		
		«IF isImpactAnalyzerKind()-»
			extends org.eclipse.gmf.tooling.runtime.ocl.parsers.ImpactAnalyzerParserBase
		«ELSE-»
			extends org.eclipse.gmf.tooling.runtime.ocl.parsers.ActiveOclParserBase
		«ENDIF-»
	«ENDIF-»
«ENDDEFINE»
«DEFINE implementsList FOR gmfgen::ExpressionLabelParser-»
	«IF not(isViewExpressionDefinedAndOcl())-»
		implements org.eclipse.gmf.runtime.common.ui.services.parser.IParser	    
	«ENDIF-»
«ENDDEFINE»

«DEFINE body FOR gmfgen::ExpressionLabelParser»

«IF isViewExpressionDefinedAndOcl()-»
	«EXPAND xpt::Common::generatedMemberComment»
	@Override	
	protected String getExpressionBody() {
		return «EXPAND impl::parsers::ExpressionLabelParser::getExpression(self, viewExpression) FOR viewExpression.provider».body();
	}
«ELSE-»
	«EXPAND xpt::Common::generatedMemberComment»
	public String getPrintString(org.eclipse.core.runtime.IAdaptable element, int flags) {
		«EXPAND impl::parsers::ExpressionLabelParser::accessViewExpression-»
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public boolean isAffectingEvent(Object event, int flags) {
		// XXX Any event is recognized as important, unless there's a way to extract this information from expression itself.
		// TODO analyze expressions (e.g. using OCL parser) to find out structural features in use  
		return true;
	}
«ENDIF-»

	«EXPAND xpt::Common::generatedMemberComment»
	public String getEditString(org.eclipse.core.runtime.IAdaptable element, int flags) {
		«EXPAND impl::parsers::ExpressionLabelParser::accessEditExpression-»
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus isValidEditString(org.eclipse.core.runtime.IAdaptable element, String editString) {
		«EXPAND impl::parsers::ExpressionLabelParser::accessValidateExpression-»
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.gmf.runtime.common.core.command.ICommand getParseCommand(org.eclipse.core.runtime.IAdaptable element, final String newString, int flags) {
		final org.eclipse.emf.ecore.EObject target = (org.eclipse.emf.ecore.EObject) element.getAdapter(org.eclipse.emf.ecore.EObject.class);
		if (!validateValues(target, newString)) {
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
		}
		org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(target);
		if (editingDomain == null) {
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
		}
		org.eclipse.core.resources.IFile affectedFile = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(target.eResource());
		return new org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand(editingDomain, "Set Values", affectedFile == null ? null : java.util.Collections.singletonList(affectedFile)) {«EXPAND xpt::Common::nonNLS» 
			protected org.eclipse.gmf.runtime.common.core.command.CommandResult doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info) throws org.eclipse.core.commands.ExecutionException {
				return new org.eclipse.gmf.runtime.common.core.command.CommandResult(updateValues(target, newString));
			}
		};
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.jface.text.contentassist.IContentAssistProcessor getCompletionProcessor(org.eclipse.core.runtime.IAdaptable element) {
    	return null;
	}
	
	«EXPAND xpt::Common::generatedMemberComment»
	private boolean validateValues(org.eclipse.emf.ecore.EObject target, String newString) {
		// TODO implement as needed«REM»with default 'true' I assume isValidEditString() has been called prior to getParseCommand and generally I don't need to do anything else here«ENDREM»
		return true;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.core.runtime.IStatus updateValues(org.eclipse.emf.ecore.EObject target, String newString) throws org.eclipse.core.commands.ExecutionException {
		// TODO implement this method
		// DO NOT FORGET to remove @generated tag or mark method @generated NOT
		throw new org.eclipse.core.commands.ExecutionException("Please implement parsing and value modification"); 
	}
«EXPAND impl::parsers::ExpressionLabelParser::extraMethods-»
«ENDDEFINE»

Back to the top