blob: 71e968c880dc5df1b12a9d74abeb7cd5696371c8 [file] [log] [blame]
/*
* 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()-»
extends org.eclipse.gmf.tooling.runtime.parsers.ExpressionLabelParserBase
«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»