carbidecpp22devenv/plugins/org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/codegen.templates/xpt/parsers/NativeParser.xpt
changeset 422 033392511bf7
equal deleted inserted replaced
421:631a44165bcf 422:033392511bf7
       
     1 /*
       
     2  * Copyright (c) 2007 Borland Software Corporation
       
     3  * 
       
     4  * All rights reserved. This program and the accompanying materials
       
     5  * are made available under the terms of the Eclipse Public License v1.0
       
     6  * which accompanies this distribution, and is available at
       
     7  * http://www.eclipse.org/legal/epl-v10.html
       
     8  *
       
     9  * Contributors:
       
    10  *    Dmitry Stadnik (Borland) - initial API and implementation
       
    11  */
       
    12 
       
    13 «IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
       
    14 «IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
       
    15 «IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
       
    16 
       
    17 «DEFINE className FOR gmfgen::GenDiagram»NativeParser«ENDDEFINE»
       
    18 
       
    19 «DEFINE qualifiedClassName FOR gmfgen::GenDiagram»«parsersPackageName».«EXPAND className»«ENDDEFINE»
       
    20 
       
    21 «DEFINE NativeParser FOR gmfgen::GenDiagram-»
       
    22 «EXPAND xpt::Common::copyright FOR editorGen-»
       
    23 package «parsersPackageName»;
       
    24 
       
    25 «EXPAND xpt::Common::generatedClassComment»
       
    26 public class «EXPAND className» extends «EXPAND xpt::parsers::AbstractParser::qualifiedClassName» {
       
    27 
       
    28 	«EXPAND xpt::Common::generatedMemberComment»
       
    29 	public «EXPAND className»(org.eclipse.emf.ecore.EAttribute[] features) {
       
    30 		super(features);
       
    31 		if (features.length != 1) {
       
    32 			throw new IllegalArgumentException(java.util.Arrays.toString(features));
       
    33 		}
       
    34 	}
       
    35 
       
    36 	«EXPAND xpt::Common::generatedMemberComment»
       
    37 	protected org.eclipse.emf.ecore.EAttribute getAttribute() {
       
    38 		return features[0];
       
    39 	}
       
    40 
       
    41 	«EXPAND xpt::Common::generatedMemberComment»
       
    42 	public String getPrintString(org.eclipse.core.runtime.IAdaptable adapter, int flags) {
       
    43 		org.eclipse.emf.ecore.EObject element =
       
    44 				(org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
       
    45 		org.eclipse.emf.ecore.EAttribute feature = getAttribute();
       
    46 		String s = org.eclipse.emf.ecore.util.EcoreUtil.convertToString(
       
    47 				feature.getEAttributeType(), element.eGet(feature));
       
    48 		return s != null ? s : ""; «EXPAND xpt::Common::nonNLS»
       
    49 	}
       
    50 
       
    51 	«EXPAND xpt::Common::generatedMemberComment»
       
    52 	public String getEditString(org.eclipse.core.runtime.IAdaptable adapter, int flags) {
       
    53 		return getPrintString(adapter, flags);
       
    54 	}
       
    55 
       
    56 	«EXPAND xpt::Common::generatedMemberComment»
       
    57 	public org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus isValidEditString(
       
    58 			org.eclipse.core.runtime.IAdaptable adapter, String editString) {
       
    59 		return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.EDITABLE_STATUS;
       
    60 	}
       
    61 
       
    62 	«EXPAND xpt::Common::generatedMemberComment»
       
    63 	public org.eclipse.gmf.runtime.common.core.command.ICommand getParseCommand(
       
    64 			org.eclipse.core.runtime.IAdaptable adapter, String newString, int flags) {
       
    65 		org.eclipse.emf.ecore.EAttribute feature = getAttribute();
       
    66 		Object value = org.eclipse.emf.ecore.util.EcoreUtil.createFromString(feature.getEAttributeType(), newString);
       
    67 		return getParseCommand(adapter, new Object[] { value }, flags);
       
    68 	}
       
    69 	«EXPAND additions-»
       
    70 }
       
    71 «ENDDEFINE»
       
    72 
       
    73 «DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»