Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashatalin2008-12-29 07:41:38 -0500
committerashatalin2008-12-29 07:41:38 -0500
commitfc1dfb3b462e159eec1b6031bb41ab79c762474b (patch)
tree66acb7873f68640147106dcd919a5041ecbc918b /plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers
parent7f3bb1960b122d5d9c4edae8dc1c330032c9cf60 (diff)
downloadorg.eclipse.gmf-tooling-fc1dfb3b462e159eec1b6031bb41ab79c762474b.tar.gz
org.eclipse.gmf-tooling-fc1dfb3b462e159eec1b6031bb41ab79c762474b.tar.xz
org.eclipse.gmf-tooling-fc1dfb3b462e159eec1b6031bb41ab79c762474b.zip
QVTO-based xpand implementation was merged to HEAD
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/EditPartProvider.xpt125
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.qvto78
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.xpt177
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementTypes.xpt258
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/IconProvider.xpt39
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MarkerNavigationProvider.xpt86
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricProvider.xpt436
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/Metrics.qvto26
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricsResultView.xpt277
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ModelingAssistantProvider.xpt253
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ParserUtils.qvto17
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ShortcutsDecoratorProvider.xpt110
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationDecoratorProvider.xpt393
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationProvider.xpt322
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt226
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/extensions.xpt181
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/i18n.qvto15
17 files changed, 3019 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/EditPartProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/EditPartProvider.xpt
new file mode 100644
index 000000000..68daef73e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/EditPartProvider.xpt
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2007 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 API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+
+«DEFINE EditPartProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «editPartProviderClassName»
+ extends org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.gef.EditPartFactory factory;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private boolean allowCaching;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private java.lang.ref.WeakReference cachedPart;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private java.lang.ref.WeakReference cachedView;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public «editPartProviderClassName»() {
+ setFactory(new «getEditPartFactoryQualifiedClassName()»());
+ setAllowCaching(true);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public final org.eclipse.gef.EditPartFactory getFactory() {
+ return factory;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected void setFactory(org.eclipse.gef.EditPartFactory factory) {
+ this.factory = factory;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public final boolean isAllowCaching() {
+ return allowCaching;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected synchronized void setAllowCaching(boolean allowCaching) {
+ this.allowCaching = allowCaching;
+ if (!allowCaching) {
+ cachedPart = null;
+ cachedView = null;
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart createEditPart(
+ org.eclipse.gmf.runtime.notation.View view) {
+ org.eclipse.gef.EditPart part = factory.createEditPart(null, view);
+ if (part instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) {
+ return (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) part;
+ }
+ return null;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart getCachedPart(
+ org.eclipse.gmf.runtime.notation.View view) {
+ if (cachedView != null && cachedView.get() == view) {
+ return (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) cachedPart.get();
+ }
+ return null;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public synchronized org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart createGraphicEditPart(
+ org.eclipse.gmf.runtime.notation.View view) {
+ if (isAllowCaching()) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart part = getCachedPart(view);
+ cachedPart = null;
+ cachedView = null;
+ if (part != null) {
+ return part;
+ }
+ }
+ return createEditPart(view);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public synchronized boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
+ if (operation instanceof org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation) {
+ org.eclipse.gmf.runtime.notation.View view =
+ ((org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation) operation).getView();
+ if (!«getEditPartQualifiedClassName()».MODEL_ID.equals(
+ «getVisualIDRegistryQualifiedClassName()».getModelID(view))) {
+ return false;
+ }
+ if (isAllowCaching() && getCachedPart(view) != null) {
+ return true;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart part = createEditPart(view);
+ if (part != null) {
+ if (isAllowCaching()) {
+ cachedPart = new java.lang.ref.WeakReference(part);
+ cachedView = new java.lang.ref.WeakReference(view);
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.qvto b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.qvto
new file mode 100644
index 000000000..48fe4242b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.qvto
@@ -0,0 +1,78 @@
+import xpt.GenModelUtils;
+
+modeltype genModel uses "http://www.eclipse.org/gmf/2008/GenModel";
+modeltype genModel_1 uses "http://www.eclipse.org/emf/2002/GenModel";
+
+library ElementInitializers;
+
+helper genModel_1::GenClassifier::expressionResultNeedsCast() : Boolean {
+ return false
+}
+
+helper genModel_1::GenClass::expressionResultNeedsCast() : Boolean {
+ return false
+}
+
+helper genModel_1::GenDataType::expressionResultNeedsCast() : Boolean {
+ return self.isNumberObject() or self.isPrimitiveNumberType()
+}
+
+helper genModel_1::GenEnum::expressionResultNeedsCast() : Boolean {
+ return true
+}
+
+helper javaMethodName(de : genModel::GenCommonBase, valueSpec : genModel::GenFeatureValueSpec) : String {
+ return valueSpec.feature.ecoreFeature.name + '_' + de.getUniqueIdentifier()
+}
+
+helper recurseCollectValueSpec(si : genModel::GenFeatureSeqInitializer) : Sequence(genModel::GenFeatureValueSpec) {
+ return (si.initializers)[genModel::GenFeatureValueSpec]->asSequence()->union((si.initializers)[genModel::GenReferenceNewElementSpec].newElementInitializers->collect(it | recurseCollectValueSpec(it))->flatten())->asOrderedSet()->asSequence()
+}
+
+helper getSuffixes(newSuffix : Integer) : Sequence(Integer) {
+ return ((Sequence { })[Integer]->including(newSuffix))[Integer]
+}
+
+helper getSuffixes(suffixes : Sequence(Integer), newSuffix : Integer) : Sequence(Integer) {
+ return ((Sequence { })[Integer]->union(suffixes)->including(newSuffix))[Integer]
+}
+
+helper getVariableName(prefix : String, suffixes : Sequence(Integer)) : String {
+ return prefix + getSuffix(suffixes)
+}
+
+helper genModel_1::GenClassifier::isNumberObject() : Boolean {
+ return false
+}
+
+helper genModel_1::GenClass::isNumberObject() : Boolean {
+ return false
+}
+
+helper genModel_1::GenDataType::isNumberObject() : Boolean {
+ return Sequence { 'java.math.BigDecimal', 'java.math.BigInteger', 'java.lang.Byte', 'java.lang.Double', 'java.lang.Float', 'java.lang.Integer', 'java.lang.Long', 'java.lang.Short' }->includes(self.ecoreDataType.instanceClassName)
+}
+
+helper genModel_1::GenEnum::isNumberObject() : Boolean {
+ return false
+}
+
+helper genModel_1::GenClassifier::isPrimitiveNumberType() : Boolean {
+ return false
+}
+
+helper genModel_1::GenClass::isPrimitiveNumberType() : Boolean {
+ return false
+}
+
+helper genModel_1::GenDataType::isPrimitiveNumberType() : Boolean {
+ return Sequence { 'byte', 'double', 'float', 'int', 'long', 'short' }->includes(self.ecoreDataType.instanceClassName)
+}
+
+helper genModel_1::GenEnum::isPrimitiveNumberType() : Boolean {
+ return false
+}
+
+helper getSuffix(suffixes : Sequence(Integer)) : String {
+ return '_' + suffixes->first().repr() + (if suffixes->size() > 1 then getSuffix((let tmpVar = suffixes in if tmpVar->size() < 2 then Sequence{}[Integer] else tmpVar->subSequence(2, tmpVar->size()) endif)[Integer]) else '' endif)
+}
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.xpt
new file mode 100644
index 000000000..96639db2e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementInitializers.xpt
@@ -0,0 +1,177 @@
+/*
+ * 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 API and implementation
+ * Artem Tikhomirov (Borland) - refactored javaInitilizers not to use methods from GMFGen model
+ * [221347] Got rid of generated interfaces
+ * (IObjectInitializer, IFeatureInitializer) and implementation thereof
+ */
+
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+
+«EXTENSION xpt::providers::ElementInitializers»
+«EXTENSION xpt::GenModelUtils»
+«EXTENSION xpt::NativeGenModelUtils»
+«EXTENSION xpt::StringOperations»
+
+«DEFINE ElementInitializers FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class ElementInitializers {
+ «EXPAND Initializers»
+ «EXPAND JavaSupport»
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE Initializers FOR gmfgen::GenDiagram-»
+ «EXPAND initMethod FOREACH getAllNodes()-»
+ «EXPAND initMethod FOREACH links-»
+«ENDDEFINE»
+
+«DEFINE JavaSupport FOR gmfgen::GenDiagram-»
+«IF editorGen.expressionProviders <> null and not (editorGen.expressionProviders.providers)[gmfgen::GenJavaExpressionProvider]->isEmpty()-»
+ «EXPAND javaMethod FOREACH getAllNodes()-»
+ «EXPAND javaMethod FOREACH links-»
+«ENDIF-»
+«ENDDEFINE»
+
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
+
+
+«REM»
+ Definitions of initializer objects.
+«ENDREM»
+
+«DEFINE initMethod FOR gmfgen::GenNode»«EXPAND initMethod(self) FOR modelFacet»«ENDDEFINE»
+«DEFINE initMethod FOR gmfgen::GenLink»«EXPAND initMethod(self) FOR modelFacet»«ENDDEFINE»
+
+«DEFINE initMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::ModelFacet»«ENDDEFINE»
+
+«DEFINE initMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::TypeModelFacet-»
+«EXPAND initMethod(diagramElement) FOR modelElementInitializer-»
+«ENDDEFINE»
+
+«DEFINE initMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenElementInitializer»«ERROR 'No idea how to init using ' + self.repr()»«ENDDEFINE»
+
+«DEFINE initMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenFeatureSeqInitializer-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static void init_«diagramElement.getUniqueIdentifier()»(«EXPAND MetaModel::QualifiedClassName FOR elementClass» instance) {
+ try {
+ «FOREACH initializers->asSequence() AS i»«EXPAND performInit(diagramElement, 'instance', elementClass, getSuffixes((initializers->indexOf(i) - 1))) FOR i»«ENDFOREACH-»
+ } catch(RuntimeException e) {
+ «diagramElement.getDiagram().editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Element initialization failed", e); //$NON-NLS-1$
+ }
+ }
+«ENDDEFINE»
+
+«DEFINE performInit(diagramElement : gmfgen::GenCommonBase, instanceVar : String, instanceClass : genmodel::GenClass, counters : Sequence(Integer)) FOR gmfgen::GenFeatureInitializer»«ENDDEFINE»
+
+«REM»
+ FIXME: need cleaner appoach to provider's language switch (not to mix if == literal and polymorphism)
+«ENDREM»
+«DEFINE performInit(diagramElement : gmfgen::GenCommonBase, instanceVar : String, instanceClass : genmodel::GenClass, counters : Sequence(Integer)) FOR gmfgen::GenFeatureValueSpec-»
+«IF value.provider.getLanguage() = gmfgen::GenLanguage::literal-»
+ «EXPAND MetaModel::modifyFeature(instanceVar, instanceClass, value.body) FOR feature»
+«ELSE-»
+«LET getVariableName('value', counters) AS expressionVarName-»
+ Object «expressionVarName» = «EXPAND evaluateExpr(diagramElement, self, instanceVar) FOR value.provider»;
+«IF isListType(feature)-»
+ if («expressionVarName» instanceof java.util.Collection) {
+ «EXPAND MetaModel::getFeatureValue(instanceVar, instanceClass, true) FOR feature».clear();
+«IF getTypeGenClassifier(feature).expressionResultNeedsCast()-»
+ for (java.util.Iterator it = ((java.util.Collection) «expressionVarName»).iterator(); it.hasNext(); ) {
+ Object next = «diagramElement.getDiagram().editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()».performCast(it.next(), «EXPAND MetaModel::MetaClass FOR getTypeGenClassifier(feature)»);
+ «EXPAND MetaModel::getFeatureValue(instanceVar, instanceClass, true) FOR feature».add(next);
+ }
+«ELSE-»
+ «EXPAND MetaModel::getFeatureValue(instanceVar, instanceClass, true) FOR feature».addAll(((java.util.Collection) «expressionVarName»));
+«ENDIF-»
+ } else {
+«IF getTypeGenClassifier(feature).expressionResultNeedsCast()-»
+ «expressionVarName» = «diagramElement.getDiagram().editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()».performCast(«expressionVarName», «EXPAND MetaModel::MetaClass FOR getTypeGenClassifier(feature)»);
+«ENDIF-»
+ «EXPAND MetaModel::getFeatureValue(instanceVar, instanceClass, true) FOR feature».add((«EXPAND MetaModel::QualifiedClassName /*XXX sorta hack, better would be MM::setFeatureValue that supports lists*/FOR getTypeGenClassifier(feature)») «expressionVarName»);
+ }
+«ELSE-»
+«IF getTypeGenClassifier(feature).expressionResultNeedsCast()»
+ «expressionVarName» = «diagramElement.getDiagram().editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()».performCast(«expressionVarName», «EXPAND MetaModel::MetaClass FOR getTypeGenClassifier(feature)»);
+«ENDIF-»
+ «EXPAND MetaModel::setFeatureValue(instanceVar, instanceClass, expressionVarName, true) FOR feature»;
+«ENDIF /*isListType*/-»
+«ENDLET-»
+«ENDIF /*is literal expression*/-»
+«ENDDEFINE»
+
+«DEFINE performInit(diagramElement : gmfgen::GenCommonBase, instanceVar : String, instanceClass : genmodel::GenClass, counters : Sequence(Integer)) FOR gmfgen::GenReferenceNewElementSpec-»
+«FOREACH newElementInitializers->asSequence() AS newElemInit-»
+«LET getSuffixes(counters, (newElementInitializers->indexOf(newElemInit) - 1)) AS initializerCounters-»
+«LET getVariableName('newInstance', initializerCounters) AS newInstanceVar-»
+«EXPAND MetaModel::NewInstance(newInstanceVar) FOR newElemInit.elementClass»
+«EXPAND MetaModel::modifyFeature(instanceVar, instanceClass, newInstanceVar) FOR feature»;
+«FOREACH newElemInit.initializers->asSequence() AS i»«EXPAND performInit(diagramElement, newInstanceVar, newElemInit.elementClass, getSuffixes(initializerCounters, (newElemInit.initializers->indexOf(i) - 1))) FOR i»«ENDFOREACH»
+«ENDLET-»
+«ENDLET-»
+«ENDFOREACH-»
+«ENDDEFINE»
+
+/////////////////////////////////
+
+«DEFINE evaluateExpr(diagramElement : gmfgen::GenCommonBase, valueExpr : gmfgen::GenFeatureValueSpec, instanceVar : String) FOR gmfgen::GenExpressionProviderBase»«ENDDEFINE»
+
+// XXX perhaps, using instance.eClass() is better option than MetaModel::MetaClass (though, need to rely on instance variable name/type)
+«DEFINE evaluateExpr(diagramElement : gmfgen::GenCommonBase, valueExpr : gmfgen::GenFeatureValueSpec, instanceVar : String) FOR gmfgen::GenExpressionInterpreter-»
+«EXPAND xpt::expressions::getExpression::getExpression(valueExpr.value, valueExpr.featureSeqInitializer.elementClass)».evaluate(«instanceVar»)«-»
+«ENDDEFINE»
+
+«REM»
+ XXX revisit: if emf java merge doesn't support genereated NOT methods with modified
+ return type, there's no much sense to keep Object value = invokeJavaMethodWithSpecificReturnType,
+ as client won't benefit from such code (he can't modify return type and thus would get duplicated methods on regeneration)
+ However, if merge does ignore method return type when merging, allowing Object as return type may help.
+«ENDREM»
+«DEFINE evaluateExpr(diagramElement : gmfgen::GenCommonBase, valueExpr : gmfgen::GenFeatureValueSpec, instanceVar : String) FOR gmfgen::GenJavaExpressionProvider-»
+«javaMethodName(diagramElement, valueExpr)»(«instanceVar»)«-»
+«ENDDEFINE»
+
+/////////////////////////////////
+
+«DEFINE javaMethod FOR gmfgen::GenNode»«EXPAND javaMethod(self) FOR modelFacet»«ENDDEFINE»
+«DEFINE javaMethod FOR gmfgen::GenLink»«EXPAND javaMethod(self) FOR modelFacet»«ENDDEFINE»
+«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::ModelFacet»«ENDDEFINE»
+«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::TypeModelFacet-»
+«EXPAND javaMethod(diagramElement) FOR modelElementInitializer-»
+«ENDDEFINE»
+
+«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenElementInitializer»«ERROR 'No idea how to handle ' + self.repr()»«ENDDEFINE»
+«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenFeatureSeqInitializer-»
+«FOREACH recurseCollectValueSpec(self) AS vs»«EXPAND javaMethod(diagramElement, vs) FOR vs.value.provider»«ENDFOREACH-»
+«ENDDEFINE»
+
+«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase, vs : gmfgen::GenFeatureValueSpec) FOR gmfgen::GenExpressionProviderBase-»«ENDDEFINE»
+«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase, vs : gmfgen::GenFeatureValueSpec) FOR gmfgen::GenJavaExpressionProvider-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static «EXPAND MetaModel::featureTargetType FOR vs.feature» «javaMethodName(diagramElement, vs)»(«EXPAND MetaModel::QualifiedClassName FOR vs.featureSeqInitializer.elementClass» self) {
+«IF injectExpressionBody and (vs.value.body <> null and vs.value.body.xpandLength() <> 0)-»
+ «vs.value.body»
+«ELSEIF throwException or (injectExpressionBody and (vs.value.body = null or vs.value.body.xpandLength() = 0))-»
+ // TODO: implement this method to return value
+ // for «EXPAND MetaModel::MetaFeature FOR vs.feature»
+ // Ensure that you remove @generated or mark it @generated NOT
+ throw new java.lang.UnsupportedOperationException("No user java implementation provided in '«javaMethodName(diagramElement, vs)»' operation");«EXPAND xpt::Common::nonNLS»
+«ELSE-»
+ return null;
+«ENDIF-»
+ }
+«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementTypes.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementTypes.xpt
new file mode 100644
index 000000000..ac9b774f7
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ElementTypes.xpt
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2006, 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 API and implementation
+ */
+
+«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 xpt::diagram::Utils»
+«EXTENSION xpt::GenModelUtils»
+
+«DEFINE ElementTypes FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «elementTypesClassName» extends ElementInitializers {
+
+ «EXPAND _constructor-»
+
+ «EXPAND attributes-»
+
+ «EXPAND elementTypeField FOREACH getElements(self)-»
+
+ «EXPAND getImageRegistry-»
+
+ «EXPAND getImageRegistryKey-»
+
+ «EXPAND getProvidedImageDescriptor-»
+
+ «EXPAND getNamedElementImageDescriptor-»
+
+ «EXPAND getNamedElementImage-»
+
+ «EXPAND getAdaptableImageDescriptor-»
+
+ «EXPAND getAdaptableImage-»
+
+ «EXPAND getElement-»
+
+ «EXPAND getElementType-»
+
+ «EXPAND isKnownElementType-»
+
+ «EXPAND getElementTypeByVisualID-»
+
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE _constructor FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private «elementTypesClassName»() {
+}
+«ENDDEFINE»
+
+«DEFINE attributes FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private static java.util.Map elements;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+private static org.eclipse.jface.resource.ImageRegistry imageRegistry;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+private static java.util.Set KNOWN_ELEMENT_TYPES;
+«ENDDEFINE»
+
+
+«DEFINE getImageRegistry FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private static org.eclipse.jface.resource.ImageRegistry getImageRegistry() {
+ if (imageRegistry == null) {
+ imageRegistry = new org.eclipse.jface.resource.ImageRegistry();
+ }
+ return imageRegistry;
+}
+«ENDDEFINE»
+
+«DEFINE getImageRegistryKey FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private static String getImageRegistryKey(org.eclipse.emf.ecore.ENamedElement element) {
+ return element.getName();
+}
+«ENDDEFINE»
+
+«DEFINE getProvidedImageDescriptor FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private static org.eclipse.jface.resource.ImageDescriptor getProvidedImageDescriptor(org.eclipse.emf.ecore.ENamedElement element) {
+ if (element instanceof org.eclipse.emf.ecore.EStructuralFeature) {
+ org.eclipse.emf.ecore.EStructuralFeature feature = ((org.eclipse.emf.ecore.EStructuralFeature) element);
+ org.eclipse.emf.ecore.EClass eContainingClass = feature.getEContainingClass();
+ org.eclipse.emf.ecore.EClassifier eType = feature.getEType();
+ if (eContainingClass != null && !eContainingClass.isAbstract()){
+ element = eContainingClass;
+ } else if (eType instanceof org.eclipse.emf.ecore.EClass && !((org.eclipse.emf.ecore.EClass)eType).isAbstract()){
+ element = eType;
+ }
+ }
+ if (element instanceof org.eclipse.emf.ecore.EClass) {
+ org.eclipse.emf.ecore.EClass eClass = (org.eclipse.emf.ecore.EClass) element;
+ if (!eClass.isAbstract()) {
+ return «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemImageDescriptor(
+ eClass.getEPackage().getEFactoryInstance().create(eClass));
+ }
+ }
+ // TODO : support structural features
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE getNamedElementImageDescriptor FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(org.eclipse.emf.ecore.ENamedElement element) {
+ String key = getImageRegistryKey(element);
+ org.eclipse.jface.resource.ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
+ if (imageDescriptor == null) {
+ «EXPAND loadProvidedImageDescriptor-»
+ }
+ return imageDescriptor;
+}
+«ENDDEFINE»
+
+«DEFINE loadProvidedImageDescriptor FOR gmfgen::GenDiagram-»
+imageDescriptor = getProvidedImageDescriptor(element);
+if (imageDescriptor == null) {
+ imageDescriptor = org.eclipse.jface.resource.ImageDescriptor.getMissingImageDescriptor();
+}
+getImageRegistry().put(key, imageDescriptor);
+«ENDDEFINE»
+
+«DEFINE getNamedElementImage FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static org.eclipse.swt.graphics.Image getImage(org.eclipse.emf.ecore.ENamedElement element) {
+ String key = getImageRegistryKey(element);
+ org.eclipse.swt.graphics.Image image = getImageRegistry().get(key);
+ if (image == null) {
+ org.eclipse.jface.resource.ImageDescriptor «EXPAND loadProvidedImageDescriptor-»
+ image = getImageRegistry().get(key);
+ }
+ return image;
+}
+«ENDDEFINE»
+
+«DEFINE getAdaptableImageDescriptor FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(org.eclipse.core.runtime.IAdaptable hint) {
+ «EXPAND getNamedElement-»
+ return getImageDescriptor(element);
+}
+«ENDDEFINE»
+
+«DEFINE getNamedElement FOR gmfgen::GenDiagram-»
+org.eclipse.emf.ecore.ENamedElement element = getElement(hint);
+if (element == null) {
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE getAdaptableImage FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static org.eclipse.swt.graphics.Image getImage(org.eclipse.core.runtime.IAdaptable hint) {
+ «EXPAND getNamedElement-»
+ return getImage(element);
+}
+«ENDDEFINE»
+
+«DEFINE getElement FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment('Returns ''type'' of the ecore object associated with the hint.
+')»
+public static org.eclipse.emf.ecore.ENamedElement getElement(org.eclipse.core.runtime.IAdaptable hint) {
+ Object type = hint.getAdapter(org.eclipse.gmf.runtime.emf.type.core.IElementType.class);
+ if (elements == null) {
+ elements = new java.util.IdentityHashMap();
+ «EXPAND bindUniqueIdentifierToNamedElement(getUniqueIdentifier()) FOR domainDiagramElement-»
+ «FOREACH getNodes(self) AS node-»
+ «EXPAND bindUniqueIdentifierToNamedElement(node.getUniqueIdentifier()) FOR node.modelFacet-»
+ «ENDFOREACH-»
+ «FOREACH links->asSequence() AS link-»
+ «EXPAND bindUniqueIdentifierToNamedElement(link.getUniqueIdentifier()) FOR link.modelFacet-»
+ «ENDFOREACH-»
+ }
+ return (org.eclipse.emf.ecore.ENamedElement) elements.get(type);
+}
+«ENDDEFINE»
+
+«DEFINE bindUniqueIdentifierToNamedElement(id : String) FOR genmodel::GenClass»
+ elements.put(«id», «EXPAND MetaModel::MetaClass»);
+«ENDDEFINE»
+
+«DEFINE bindUniqueIdentifierToNamedElement(id : String) FOR gmfgen::ModelFacet»
+ «ERROR 'Unsupported model facet: ' + self.repr()-»
+«ENDDEFINE»
+
+«DEFINE bindUniqueIdentifierToNamedElement(id : String) FOR gmfgen::TypeModelFacet»
+ «EXPAND bindUniqueIdentifierToNamedElement(id) FOR metaClass-»
+«ENDDEFINE»
+
+«DEFINE bindUniqueIdentifierToNamedElement(id : String) FOR gmfgen::FeatureLinkModelFacet»
+ elements.put(«id», «EXPAND MetaModel::MetaFeature FOR metaFeature»);
+«ENDDEFINE»
+
+«DEFINE elementTypeField FOR gmfgen::GenCommonBase-»
+ «IF null <> elementType-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static final org.eclipse.gmf.runtime.emf.type.core.IElementType «getUniqueIdentifier()» = getElementType("«elementType.uniqueIdentifier»"); «EXPAND xpt::Common::nonNLS»
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE accessElementType FOR gmfgen::GenCommonBase»«getDiagram().getElementTypesQualifiedClassName()».«getUniqueIdentifier()»«ENDDEFINE»
+
+«DEFINE getElementType FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+private static org.eclipse.gmf.runtime.emf.type.core.IElementType getElementType(String id) {
+ return org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry.getInstance().getType(id);
+}
+«ENDDEFINE»
+
+«DEFINE isKnownElementType FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static boolean isKnownElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType elementType) {
+ if (KNOWN_ELEMENT_TYPES == null) {
+ KNOWN_ELEMENT_TYPES = new java.util.HashSet();
+ «EXPAND addKnownElementType FOREACH getElements(self)-»
+ }
+ return KNOWN_ELEMENT_TYPES.contains(elementType);
+}
+«ENDDEFINE»
+
+«DEFINE addKnownElementType FOR gmfgen::GenCommonBase-»
+ «IF null <> elementType-»
+KNOWN_ELEMENT_TYPES.add(«getUniqueIdentifier()»);
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE getElementTypeByVisualID FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static org.eclipse.gmf.runtime.emf.type.core.IElementType getElementType(int visualID) {
+ switch (visualID) {
+ «EXPAND caseElementType FOREACH getElements(self)->select(el | el.elementType <> null)-»
+ }
+ return null;
+ }
+«ENDDEFINE»
+
+«DEFINE caseElementType FOR gmfgen::GenCommonBase-»
+ «EXPAND xpt::Common::caseVisualID-»
+ return «getUniqueIdentifier()»;
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/IconProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/IconProvider.xpt
new file mode 100644
index 000000000..43493d77e
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/IconProvider.xpt
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007 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 API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+
+«DEFINE IconProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «iconProviderClassName» extends org.eclipse.gmf.runtime.common.core.service.AbstractProvider
+ implements org.eclipse.gmf.runtime.common.ui.services.icon.IIconProvider {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.swt.graphics.Image getIcon(org.eclipse.core.runtime.IAdaptable hint, int flags) {
+ return «getElementTypesQualifiedClassName()».getImage(hint);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
+ if (operation instanceof org.eclipse.gmf.runtime.common.ui.services.icon.GetIconOperation) {
+ return ((org.eclipse.gmf.runtime.common.ui.services.icon.GetIconOperation) operation).execute(this) != null;
+ }
+ return false;
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram-»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MarkerNavigationProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MarkerNavigationProvider.xpt
new file mode 100644
index 000000000..4c99ec092
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MarkerNavigationProvider.xpt
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2007 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 API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+
+«DEFINE MarkerNavigationProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «markerNavigationProviderClassName»
+ extends org.eclipse.gmf.runtime.emf.ui.providers.marker.AbstractModelMarkerNavigationProvider {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static final String MARKER_TYPE =
+ «editorGen.plugin.getActivatorQualifiedClassName()».ID + ".«getValidationDiagnosticMarkerType()»"; «EXPAND xpt::Common::nonNLS»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected void doGotoMarker(org.eclipse.core.resources.IMarker marker) {
+ String elementId = marker.getAttribute(org.eclipse.gmf.runtime.common.core.resources.IMarker.ELEMENT_ID, null);
+ if (elementId == null || !(getEditor() instanceof org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor)) {
+ return;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor editor =
+ (org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor) getEditor();
+ java.util.Map editPartRegistry = editor.getDiagramGraphicalViewer().getEditPartRegistry();
+ org.eclipse.emf.ecore.EObject targetView = editor.getDiagram().eResource().getEObject(elementId);
+ if (targetView == null) {
+ return;
+ }
+ org.eclipse.gef.EditPart targetEditPart = (org.eclipse.gef.EditPart) editPartRegistry.get(targetView);
+ if (targetEditPart != null) {
+ «getDiagramEditorUtilQualifiedClassName()».selectElementsInDiagram(
+ editor, java.util.Arrays.asList(new org.eclipse.gef.EditPart[] { targetEditPart }));
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static void deleteMarkers(org.eclipse.core.resources.IResource resource) {
+ try {
+ resource.deleteMarkers(MARKER_TYPE, true, org.eclipse.core.resources.IResource.DEPTH_ZERO);
+ } catch (org.eclipse.core.runtime.CoreException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Failed to delete validation markers", e); «EXPAND xpt::Common::nonNLS»
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static org.eclipse.core.resources.IMarker addMarker(org.eclipse.core.resources.IFile file,
+ String elementId, String location, String message, int statusSeverity) {
+ org.eclipse.core.resources.IMarker marker = null;
+ try {
+ marker = file.createMarker(MARKER_TYPE);
+ marker.setAttribute(org.eclipse.core.resources.IMarker.MESSAGE, message);
+ marker.setAttribute(org.eclipse.core.resources.IMarker.LOCATION, location);
+ marker.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, elementId);
+ int markerSeverity = org.eclipse.core.resources.IMarker.SEVERITY_INFO;
+ if (statusSeverity == org.eclipse.core.runtime.IStatus.WARNING) {
+ markerSeverity = org.eclipse.core.resources.IMarker.SEVERITY_WARNING;
+ } else if (statusSeverity == org.eclipse.core.runtime.IStatus.ERROR ||
+ statusSeverity == org.eclipse.core.runtime.IStatus.CANCEL) {
+ markerSeverity = org.eclipse.core.resources.IMarker.SEVERITY_ERROR;
+ }
+ marker.setAttribute(org.eclipse.core.resources.IMarker.SEVERITY, markerSeverity);
+ } catch (org.eclipse.core.runtime.CoreException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Failed to create validation marker", e); «EXPAND xpt::Common::nonNLS»
+ }
+ return marker;
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricProvider.xpt
new file mode 100644
index 000000000..624425573
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricProvider.xpt
@@ -0,0 +1,436 @@
+/*
+ * 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 API and implementation
+ * Artem Tikhomirov (Borland) - refactoring (https://bugs.eclipse.org/230014)
+ */
+
+«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 xpt::GenModelUtils»
+«EXTENSION xpt::EMFUtils»
+«EXTENSION xpt::providers::Metrics»
+«EXTENSION xpt::StringOperations»
+«EXTENSION xpt::NativeEMFUtils»
+
+«DEFINE MetricProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «metricProviderClassName» {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static class MetricsAction extends org.eclipse.jface.action.Action {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.ui.IWorkbenchPage page;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public MetricsAction(org.eclipse.ui.IWorkbenchPage page) {
+ setText("Metrics");
+ this.page = page;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void run() {
+ org.eclipse.ui.IWorkbenchPart workbenchPart = page.getActivePart();
+ org.eclipse.ui.IViewPart metricsView = null;
+ try {
+ metricsView = page.findView(«EXPAND resultViewID»);
+ if (metricsView == null) {
+ metricsView = page.showView(«EXPAND resultViewID»);
+ } else {
+ if (metricsView != null && workbenchPart instanceof org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart) {
+ final org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart part = (org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart) workbenchPart;
+ ((ResultView) metricsView).setInput(part);
+ }
+ page.activate(metricsView);
+ }
+ } catch (org.eclipse.ui.PartInitException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Diagram metric view failure", e);«EXPAND xpt::Common::nonNLS»
+ }
+ }
+ }
+
+«EXPAND calculateMetricsMethods-»
+
+«EXPAND formatNotationElementNameMethod-»
+«EXPAND formatSemanticElementNameMethod-»
+
+«EXPAND metricsClasses»
+
+«EXPAND keysAndToolTipsMethods FOR editorGen.metrics»
+
+«EXPAND metricCalcField FOREACH editorGen.metrics.metrics->select(m | m.rule <> null and (m.target <> null and m.target.getContext() <> null))»
+«EXPAND metricCalcMethod FOREACH editorGen.metrics.metrics->select(m | m.rule <> null and (m.target <> null and m.target.getContext() <> null))»
+
+«EXPAND MetricsResultView::Class»
+
+«EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE resultViewQualifiedClassName FOR gmfgen::GenDiagram»«providersPackageName».«metricProviderClassName».«EXPAND MetricsResultView::className»«ENDDEFINE»
+«DEFINE resultViewID FOR gmfgen::GenDiagram»«EXPAND resultViewQualifiedClassName».VIEW_ID«ENDDEFINE»
+
+
+//////////////////////////////////////////////////////////////////////////
+
+«DEFINE calculateMetricsMethods FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ static java.util.List calculateMetrics(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart diagramPart) {
+ final org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart diagramEditPart = diagramPart.getDiagramEditPart();
+ try {
+ return (java.util.List) diagramPart.getDiagramEditPart().getEditingDomain().runExclusive(
+ new org.eclipse.emf.transaction.RunnableWithResult.Impl() {
+
+ public void run() {
+ org.eclipse.gmf.runtime.notation.Diagram diagram = diagramEditPart.getDiagramView();
+ java.util.ArrayList/*<ElementMetrics>*/ metrics = new java.util.ArrayList/*<ElementMetrics>*/(50);
+«IF not getNotationMetrics(editorGen.metrics)->isEmpty()-»
+ calculateNotationElementMetrics(diagram, metrics);
+«ENDIF-»
+«IF not getDiagramMetrics(editorGen.metrics)->isEmpty()-»
+ calculateDiagramElementMetrics(diagram, metrics);
+«ENDIF-»
+«IF not getDomainMetrics(editorGen.metrics)->isEmpty()-»
+ calculateSemanticElementMetrics(diagramEditPart, metrics);
+«ENDIF-»
+ setResult(metrics);
+ }
+ });
+ } catch (InterruptedException e) {
+ return java.util.Collections.EMPTY_LIST;
+ }
+ }
+
+«IF not getNotationMetrics(editorGen.metrics)->isEmpty()»«EXPAND calcNotationMetricsMethod FOR editorGen»«ENDIF»
+«IF not getDiagramMetrics(editorGen.metrics)->isEmpty()»«EXPAND calcDiagramMetricsMethod FOR editorGen»«ENDIF»
+«IF not getDomainMetrics(editorGen.metrics)->isEmpty()»«EXPAND calcDomainMetricsMethod FOR editorGen»«ENDIF»
+«ENDDEFINE»
+
+
+«DEFINE metricsClasses FOR gmfgen::GenDiagram»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static class ElementMetrics {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final Metric[] metrics;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final String targetElementQName;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final org.eclipse.swt.graphics.Image elementImage;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ String diagramElementID; «REM»FIXME add specific constructor for View elements, set diagramElementID from there«ENDREM»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ ElementMetrics(org.eclipse.emf.ecore.EObject target, String name, Metric[] metrics) {
+ «EXPAND xpt::Common::_assert('metrics.length > 0')-»
+ «EXPAND xpt::Common::_assert('name != null')-»
+ this.metrics = metrics;
+ this.targetElementQName = name;
+ org.eclipse.emf.ecore.EClass imageTarget = target.eClass();
+ if (target instanceof org.eclipse.gmf.runtime.notation.View) {
+ org.eclipse.gmf.runtime.notation.View viewTarget = (org.eclipse.gmf.runtime.notation.View) target;
+ if ("".equals(viewTarget.getType()) && viewTarget.getElement() != null) {«EXPAND xpt::Common::nonNLS»
+ imageTarget = viewTarget.getElement().eClass();
+ }
+ }
+ this.elementImage = «EXPAND getImageAccessor('imageTarget')»;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ Metric getMetricByKey(String key) {
+ for (int i = 0; i < metrics.length; i++) {
+ if (metrics[i].key.equals(key)) {
+ return metrics[i];
+ }
+ }
+ return null;
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static class Metric implements Comparable {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final String key;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final Double value;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final Double lowLimit;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final Double highLimit;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ final String displayValue;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ Metric(String key, Double value) {
+ this(key, value, null, null);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ Metric(String key, Double value, Double low, Double high) {
+ «EXPAND xpt::Common::_assert('key != null')-»
+ this.key = key;
+ this.value = value;
+ this.lowLimit = low;
+ this.highLimit = high;
+ this.displayValue = (value != null) ? java.text.NumberFormat.getInstance().format(value) : "null"; //$NON-NLS-1$
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public int compareTo(Object other) {
+ Metric otherMetric = (Metric) other;
+ if (value != null && otherMetric.value != null) {
+ return (value.longValue() < otherMetric.value.longValue()) ? -1
+ : (value.longValue() == otherMetric.value.longValue() ? 0 : 1);
+ }
+ return (value == null && otherMetric.value == null) ? 0
+ : (value == null) ? -1 : 1;
+ }
+ }
+«ENDDEFINE»
+
+«DEFINE getImageAccessor(imageClassVar : String) FOR gmfgen::GenDiagram»«getElementTypesQualifiedClassName()».getImage(«imageClassVar»)«ENDDEFINE»
+
+«DEFINE calcNotationMetricsMethod FOR gmfgen::GenEditorGenerator-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ static void calculateNotationElementMetrics(org.eclipse.gmf.runtime.notation.Diagram diagram, java.util.List/*<ElementMetrics>*/ metricsList) {
+ ElementMetrics row = null;
+«LET getNotationMetrics(metrics)->select(m | m.target.oclAsType(gmfgen::GenNotationElementTarget).element.ecoreClass.name = 'Diagram') AS diagramMetrics-»
+«IF not diagramMetrics->isEmpty()-»
+ row = new ElementMetrics(diagram, formatViewName(diagram), new Metric[] {
+«EXPAND metricResult('diagram', false) FOREACH diagramMetrics SEPARATOR ',
+'»
+ });
+ row.diagramElementID = diagram.eResource().getURIFragment(diagram);
+ metricsList.add(row);
+«ENDIF-»
+«ENDLET-»
+«LET getNotationMetrics(metrics)->collect(m | m.target.oclAsType(gmfgen::GenNotationElementTarget).element)->asOrderedSet() AS notationTargets»
+ for (java.util.Iterator it = diagram.eAllContents(); it.hasNext(); ) {
+ Object next = it.next();
+«FOREACH (notationTargets)[genmodel::GenClass]->asSequence() AS nt-»
+ if («EXPAND MetaModel::IsInstance('next') FOR nt») {
+ «EXPAND MetaModel::DeclareAndAssign('_' + nt.ecoreClass.name.toLower(), 'next', true) FOR nt»
+ row = new ElementMetrics(«'_' + nt.ecoreClass.name.toLower()», formatViewName(«'_' + nt.ecoreClass.name.toLower()»), new Metric[] {«-»
+ «FOREACH getNotationMetrics(metrics)->select(m | m.target.oclAsType(gmfgen::GenNotationElementTarget).element = nt) AS m SEPARATOR ','»
+ «EXPAND metricResult('_' + nt.ecoreClass.name.toLower(), false) FOR m-»
+ «ENDFOREACH»
+ });
+ row.diagramElementID = «'_' + nt.ecoreClass.name.toLower()».eResource().getURIFragment(«'_' + nt.ecoreClass.name.toLower()»);
+ metricsList.add(row);
+ }
+«ENDFOREACH-»
+ }
+«ENDLET-»
+ }
+«ENDDEFINE»
+
+«DEFINE calcDiagramMetricsMethod FOR gmfgen::GenEditorGenerator-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ static void calculateDiagramElementMetrics(org.eclipse.gmf.runtime.notation.Diagram diagram, java.util.List/*<ElementMetrics>*/ metricsList) {
+ org.eclipse.emf.ecore.EObject next = diagram;
+ java.util.Iterator/*<EObject>*/ it = diagram.eAllContents();
+ do {
+ if (next instanceof org.eclipse.gmf.runtime.notation.View) {
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) next;
+ final int vid = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR diagram»(view);
+ java.util.ArrayList/*<Metric>*/ res = new java.util.ArrayList/*<Metric>*/(5);
+ switch (vid) {
+«FOREACH (getDiagramMetrics(metrics)->collect(m | m.target.oclAsType(gmfgen::GenDiagramElementTarget).element)->flatten()->asOrderedSet())[gmfgen::GenCommonBase]->asSequence() AS cb-»
+ case «EXPAND xpt::editor::VisualIDRegistry::visualID FOR cb» : {«-»
+«FOREACH getDiagramMetrics(metrics)->select(m | m.target.oclAsType(gmfgen::GenDiagramElementTarget).element->includes(cb)) AS m»
+ res.add(«EXPAND metricResult('view', true) FOR m»);
+«ENDFOREACH-»
+ break;
+ }
+«ENDFOREACH-»
+ }
+ if (!res.isEmpty()) {
+ ElementMetrics row = new ElementMetrics(view, formatViewName(view), (Metric[]) res.toArray(new Metric[res.size()]));
+ row.diagramElementID = view.eResource().getURIFragment(view);
+ metricsList.add(row);
+ }
+ }
+ next = it.hasNext() ? (org.eclipse.emf.ecore.EObject) it.next() : null;
+ } while (next != null);
+ }
+«ENDDEFINE»
+
+/*
+ * FIXME:
+ * for now, keep approach from old implementation, i.e. iterate content
+ * of element associated with diagram. Smarter approach would be
+ * iteration over diagram elements, then accessing their respective
+ * semantic elements (if set), and collecting metrics for them.
+ */
+«DEFINE calcDomainMetricsMethod FOR gmfgen::GenEditorGenerator»
+ «EXPAND xpt::Common::generatedMemberComment('NOTE: metrics are being collected for domain elements contained in the semantic element associated with diagram view, actual diagram content (elements present there) is not taken into account.')»
+ static void calculateSemanticElementMetrics(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart diagramEditPart, java.util.List/*<ElementMetrics>*/ metricsList) {
+ org.eclipse.gmf.runtime.notation.Diagram diagram = diagramEditPart.getDiagramView();
+ org.eclipse.emf.ecore.EObject next = diagram.getElement();
+ java.util.Iterator/*<EObject>*/ it = next != null ? next.eAllContents() : java.util.Collections.EMPTY_LIST.iterator();
+ java.util.HashMap/*<EObject, ElementMetrics>*/ target2row = new java.util.HashMap/*<EObject, ElementMetrics>*/();
+ while (next != null) {
+ java.util.ArrayList/*<Metric>*/ res = new java.util.ArrayList/*<Metric>*/(5);
+«FOREACH ((metrics.metrics.target)[gmfgen::GenDomainElementTarget].element->asOrderedSet()->asSequence())[genmodel::GenClass] AS e-»
+ if («EXPAND MetaModel::MetaClass FOR e».isInstance(next)) {
+«FOREACH metrics.metrics->select(m | m.target.getContext() = e)->asSequence() AS m-»
+ res.add(«EXPAND metricResult('next', true) FOR m»);
+«ENDFOREACH-»
+ }
+«ENDFOREACH-»
+ if (!res.isEmpty()) {
+ ElementMetrics row = new ElementMetrics(next, formatElementName(next), (Metric[]) res.toArray(new Metric[res.size()]));
+ metricsList.add(row);
+ target2row.put(next, row);
+ }
+ next = it.hasNext() ? (org.eclipse.emf.ecore.EObject) it.next() : null;
+ }
+ if (!target2row.isEmpty()) { // list was modified, need to process only semantic metrics
+ // bind semantic elements to notation
+ «diagram.getDiagramEditorUtilQualifiedClassName()».LazyElement2ViewMap element2ViewMap = new «diagram.getDiagramEditorUtilQualifiedClassName()».LazyElement2ViewMap(diagram, target2row.keySet());
+ for (java.util.Iterator it2 = target2row.entrySet().iterator(); it2.hasNext();) {
+ java.util.Map.Entry entry = (java.util.Map.Entry) it2.next();
+ org.eclipse.emf.ecore.EObject semanticElement = (org.eclipse.emf.ecore.EObject) entry.getKey();
+ org.eclipse.gmf.runtime.notation.View targetView = «diagram.getDiagramEditorUtilQualifiedClassName()».findView(diagramEditPart, semanticElement, element2ViewMap);
+ ElementMetrics elementMetrics = (ElementMetrics) entry.getValue();
+ elementMetrics.diagramElementID = targetView.eResource().getURIFragment(targetView);
+ }
+ }
+ }
+«ENDDEFINE»
+
+«DEFINE formatNotationElementNameMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static String formatViewName(org.eclipse.gmf.runtime.notation.View viewTarget) {
+ StringBuffer notationQNameBuf = new StringBuffer();
+ notationQNameBuf.append(formatElementName(viewTarget));
+ if (viewTarget.getElement() != null) {
+ notationQNameBuf.append("->").append(formatElementName(viewTarget.getElement())); «EXPAND xpt::Common::nonNLS»
+ }
+ int visualID = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(viewTarget);
+ notationQNameBuf.append('[').append(visualID < 0 ? Integer.toString(System.identityHashCode(viewTarget)) : Integer.toString(visualID)).append(']');
+ return notationQNameBuf.toString();
+ }
+«ENDDEFINE»
+
+«DEFINE formatSemanticElementNameMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static String formatElementName(org.eclipse.emf.ecore.EObject object) {
+ return org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil.getQualifiedName(object, true);
+ }
+«ENDDEFINE»
+
+«DEFINE metricCalcMethod FOR gmfgen::GenMetricRule»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static«REM»FIXME: (1) refactor to get rid of statics (2) 'public' only those referenced from audits«ENDREM» Double «calcMethodName(self)»(«EXPAND calcMethodArgs(self) FOR target») {
+ «EXPAND calcMethodBody(self) FOR rule.provider-»
+ }
+«ENDDEFINE»
+
+«DEFINE calcMethodArgs(metric : gmfgen::GenMetricRule) FOR gmfgen::GenMeasurable»«ERROR 'Unrecognized metric target: ' + self.repr()»«ENDDEFINE»
+
+«DEFINE calcMethodArgs(metric : gmfgen::GenMetricRule) FOR gmfgen::GenDomainElementTarget»«EXPAND MetaModel::QualifiedClassName FOR element» target«ENDDEFINE»
+
+«REM»
+ We do check all elements to be of specific kind to provide most narrow type cast
+ However, GenDiagramElementTargetImpl#getContext uses first element's notation class only
+«ENDREM»
+«DEFINE calcMethodArgs(metric : gmfgen::GenMetricRule) FOR gmfgen::GenDiagramElementTarget-»
+«IF (element)[gmfgen::GenNode]->size() = element->size()»org.eclipse.gmf.runtime.notation.Node«-»
+«ELSEIF (element)[gmfgen::GenLink]->size() = element->size()»org.eclipse.gmf.runtime.notation.Edge«-»
+«ELSEIF (element)[gmfgen::GenDiagram]->size() = element->size()»org.eclipse.gmf.runtime.notation.Diagram«-»
+«ELSE»org.eclipse.gmf.runtime.notation.View«ENDIF» target«ENDDEFINE»
+
+«REM»Note, use of QualifiedClassName here assumes it always works the same for the notation model, regardless of 'dynamic model' use (i.e. always gives qName of oeg.runtime.notation.* Java class)«ENDREM»
+«DEFINE calcMethodArgs(metric : gmfgen::GenMetricRule) FOR gmfgen::GenNotationElementTarget»«EXPAND MetaModel::QualifiedClassName FOR element» target«ENDDEFINE»
+
+
+«DEFINE calcMethodBody(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionProviderBase»«ERROR 'No idea how to calculate metric''s value for ' + self.repr()»«ENDDEFINE»
+
+«DEFINE calcMethodBody(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionInterpreter-»
+ if («exprFieldName(metric)» == null) {
+ «exprFieldName(metric)» = «EXPAND xpt::expressions::getExpression::getExpression(metric.rule, metric.target.getContext())»;
+ }
+ Object val = «exprFieldName(metric)».evaluate(target);
+ if (val instanceof Number) {
+ return val.getClass() == Double.class ? (Double) val : new Double(((Number) val).doubleValue());
+ }
+ return null;
+«ENDDEFINE»
+
+«DEFINE calcMethodBody(metric : gmfgen::GenMetricRule) FOR gmfgen::GenJavaExpressionProvider-»
+«IF injectExpressionBody and (metric.rule.body <> null and metric.rule.body.xpandLength() <> 0)-»
+ «metric.rule.body»
+«ELSEIF throwException or (injectExpressionBody and (metric.rule.body = null or metric.rule.body.xpandLength() = 0))-»
+ // TODO: implement this method
+ // Ensure that you remove @generated or mark it @generated NOT
+ throw new java.lang.UnsupportedOperationException("No user java implementation provided");«EXPAND xpt::Common::nonNLS»
+«ELSE-»
+ return new Double(Double.NaN);
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE metricCalcField FOR gmfgen::GenMetricRule-»
+«EXPAND metricCalcField(self) FOR rule.provider-»
+«ENDDEFINE»
+
+«DEFINE metricCalcField(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionProviderBase»«REM»NO-OP«ENDREM»«ENDDEFINE»
+«DEFINE metricCalcField(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionInterpreter-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static«REM»FIXME: refactor to get rid of static fields«ENDREM» «container.getAbstractExpressionQualifiedClassName()» «exprFieldName(metric)»;
+«ENDDEFINE»
+
+«DEFINE invokeCalcMethod(accessor : String, isSpecific : Boolean) FOR gmfgen::GenMetricRule»
+«container.editorGen.diagram.getMetricProviderQualifiedClassName()».«calcMethodName(self)»(«IF not isSpecific /*CastEObject would be better, however need GenClassifier*/»(«EXPAND MetaModel::QualifiedClassName FOR target.getContext()») «ENDIF»«accessor»)«ENDDEFINE»
+
+
+/*
+ * Next two methods should return arrays of identical length, hence are placed into a single template
+ */
+«DEFINE keysAndToolTipsMethods FOR gmfgen::GenMetricContainer»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static String[] getMetricKeys() {
+ return new String[] {
+ «FOREACH metrics->asSequence() AS m SEPARATOR ',
+'»«toStringLiteral(m.key)»«ENDFOREACH»
+ };
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static String[] getMetricToolTips() {
+ return new String[] {
+ «FOREACH metrics->asSequence() AS m SEPARATOR ',
+'-»
+«toStringLiteral((if m.name = null then m.key else m.name endif))»«IF m.description <> null» + '\n' + «toStringLiteral(m.description)» + '\n'«ENDIF»«IF null <> m.lowLimit» + «toStringLiteral('low: ' + m.lowLimit.repr())»«ENDIF»«IF null <> m.highLimit» + «toStringLiteral('high: ' + m.highLimit.repr())»«ENDIF-»
+ «ENDFOREACH»
+ };
+ }
+«ENDDEFINE»
+
+«DEFINE metricResult(targetAccessor : String, isJustEObject : Boolean) FOR gmfgen::GenMetricRule-»
+new Metric(«toStringLiteral(key)», «calcMethodName(self)»(«IF isJustEObject and not (Sequence { target.getContext() })[genmodel::GenClass]->isEmpty()»«EXPAND MetaModel::CastEObject(targetAccessor) FOR target.getContext().oclAsType(genmodel::GenClass)»«ELSE»«targetAccessor»«ENDIF»), «IF null = lowLimit»null«ELSE»new Double(«lowLimit»)«ENDIF», «IF null = highLimit»null«ELSE»new Double(«highLimit»)«ENDIF»)
+«ENDDEFINE»
+
+
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/Metrics.qvto b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/Metrics.qvto
new file mode 100644
index 000000000..5b8868b63
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/Metrics.qvto
@@ -0,0 +1,26 @@
+import xpt.providers.NativeMetrics;
+
+modeltype genModel uses "http://www.eclipse.org/gmf/2008/GenModel";
+
+library Metrics;
+
+helper getNotationMetrics(c : genModel::GenMetricContainer) : Sequence(genModel::GenMetricRule) {
+ return c.metrics->select(m | not (Sequence { m.target })[genModel::GenNotationElementTarget]->isEmpty())->asSequence()
+}
+
+helper getDiagramMetrics(c : genModel::GenMetricContainer) : Sequence(genModel::GenMetricRule) {
+ return c.metrics->select(m | not (Sequence { m.target })[genModel::GenDiagramElementTarget]->isEmpty())->asSequence()
+}
+
+helper getDomainMetrics(c : genModel::GenMetricContainer) : Sequence(genModel::GenMetricRule) {
+ return c.metrics->select(m | not (Sequence { m.target })[genModel::GenDomainElementTarget]->isEmpty())->asSequence()
+}
+
+helper exprFieldName(m : genModel::GenMetricRule) : String {
+ return 'expression' + validJavaIdentifier(m.key).firstToUpper()
+}
+
+helper calcMethodName(m : genModel::GenMetricRule) : String {
+ return 'calc' + validJavaIdentifier(m.key).firstToUpper()
+}
+
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricsResultView.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricsResultView.xpt
new file mode 100644
index 000000000..5a1146a32
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/MetricsResultView.xpt
@@ -0,0 +1,277 @@
+/*
+ * 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 API and implementation
+ * Artem Tikhomirov (Borland) - refactoring (https://bugs.eclipse.org/230014)
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+
+«DEFINE className FOR gmfgen::GenDiagram»ResultView«ENDDEFINE»
+
+«DEFINE Class FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static class «EXPAND className» «EXPAND supertypes» «EXPAND implements»{
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static final String VIEW_ID = "«getMetricViewID()»";«EXPAND xpt::Common::nonNLS»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static int MAX_VISIBLE_KEY_CHAR_COUNT = 8;
+
+ «EXPAND viewerField-»
+
+ «EXPAND inputField-»
+
+ «EXPAND setInputMethod-»
+
+ «EXPAND adjustLayoutMethod-»
+
+ «EXPAND createPartControlMethod-»
+
+ «EXPAND handleOpenMethod-»
+
+ «EXPAND calcMetricMaxValueStrLenMapMethod-»
+
+ «EXPAND setFocusMethod-»
+
+ «EXPAND labelProviderClass-»
+
+ «EXPAND additions-»
+ }
+«ENDDEFINE»
+
+«DEFINE supertypes FOR gmfgen::GenDiagram»extends org.eclipse.ui.part.ViewPart«ENDDEFINE»
+«DEFINE implements FOR gmfgen::GenDiagram»implements org.eclipse.jface.viewers.IOpenListener«ENDDEFINE»
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
+
+«DEFINE viewerField FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.jface.viewers.TableViewer viewer;
+«ENDDEFINE»
+
+«DEFINE inputField FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.emf.ecore.resource.Resource diagramResource;
+«ENDDEFINE»
+
+
+«DEFINE setInputMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ void setInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart diagramPart) {
+ diagramResource = diagramPart.getDiagram().eResource();
+ setTitleToolTip(diagramResource.getURI().path());
+ java.util.List metrics = calculateMetrics(diagramPart);
+ adjustLayout(metrics);
+ viewer.setInput(metrics);
+ }
+«ENDDEFINE»
+
+«DEFINE adjustLayoutMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private void adjustLayout(java.util.List metricResultList) {
+ java.util.Map maxValStrMap = calcMetricMaxValueStrLenMap(metricResultList);
+ org.eclipse.swt.widgets.Table table = viewer.getTable();
+ org.eclipse.jface.viewers.TableLayout layout = new org.eclipse.jface.viewers.TableLayout();
+ org.eclipse.swt.graphics.GC gc = new org.eclipse.swt.graphics.GC(table);
+
+ gc.setFont(org.eclipse.jface.resource.JFaceResources.getDialogFont());
+ int padding = gc.stringExtent("X").x * 2;«EXPAND xpt::Common::nonNLS»
+ for (int i = 0; i < getMetricKeys().length; i++) {
+ final String nextKey = getMetricKeys()[i];
+ String valueStr = (String) maxValStrMap.get(nextKey);
+ int minWidth = valueStr != null ? gc.stringExtent(valueStr).x + padding : 20;
+ layout.addColumnData(new org.eclipse.jface.viewers.ColumnPixelData(minWidth, true));
+ }
+ gc.dispose();
+
+ layout.addColumnData(new org.eclipse.jface.viewers.ColumnWeightData(1, 50, true));
+ viewer.getTable().setLayout(layout);
+ viewer.getTable().layout(true, true);
+ }
+«ENDDEFINE»
+
+«DEFINE createPartControlMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void createPartControl(org.eclipse.swt.widgets.Composite parent) {
+ this.viewer = new org.eclipse.jface.viewers.TableViewer(parent, org.eclipse.swt.SWT.FULL_SELECTION);
+ final org.eclipse.swt.widgets.Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+
+ for (int i = 0; i < getMetricKeys().length; i++) {
+ org.eclipse.swt.widgets.TableColumn column = new org.eclipse.swt.widgets.TableColumn(table, org.eclipse.swt.SWT.NONE);
+ column.setAlignment(org.eclipse.swt.SWT.RIGHT);
+ column.setMoveable(true);
+ column.setText(getMetricKeys()[i]);
+ column.setToolTipText(getMetricToolTips()[i]);
+ }
+
+ org.eclipse.swt.widgets.TableColumn objectColumn = new org.eclipse.swt.widgets.TableColumn(table, org.eclipse.swt.SWT.NONE);
+ objectColumn.setText("Element");
+ objectColumn.setToolTipText("Measurement element");
+
+ viewer.setLabelProvider(new Labels());
+ viewer.setContentProvider(new org.eclipse.jface.viewers.ArrayContentProvider());
+ viewer.addOpenListener(this);
+
+ org.eclipse.swt.events.SelectionListener headerSelListener = new org.eclipse.swt.events.SelectionListener() {
+ public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
+ table.setSortColumn((org.eclipse.swt.widgets.TableColumn) e.getSource());
+ table.setSortDirection((table.getSortDirection() != org.eclipse.swt.SWT.DOWN) ? org.eclipse.swt.SWT.DOWN : org.eclipse.swt.SWT.UP);
+ viewer.refresh();
+ }
+ public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
+ }
+ };
+ org.eclipse.swt.widgets.TableColumn[] columns = viewer.getTable().getColumns();
+ for (int i = 0; i < columns.length; i++) {
+ columns[i].addSelectionListener(headerSelListener);
+ }
+
+ viewer.setSorter(new org.eclipse.jface.viewers.ViewerSorter() {
+ public int compare(org.eclipse.jface.viewers.Viewer viewer, Object e1, Object e2) {
+ org.eclipse.swt.widgets.TableColumn c = table.getSortColumn();
+ int result = 0;
+ if (c != null) {
+ Metric mc1 = ((ElementMetrics) e1).getMetricByKey(c.getText());
+ Metric mc2 = ((ElementMetrics) e2).getMetricByKey(c.getText());
+ result = (mc1 != null && mc2 != null) ?
+ mc1.compareTo(mc2) : (mc1 == null ? -1 : 1);
+ } else {
+ result = ((ElementMetrics) e1).targetElementQName.compareTo(((ElementMetrics) e2).targetElementQName);
+ }
+ return table.getSortDirection() == org.eclipse.swt.SWT.DOWN ? result : -result;
+ }
+ });
+ «EXPAND createPartControlMethod_refreshInput FOR editorGen.editor-»
+ }
+«ENDDEFINE»
+
+«DEFINE createPartControlMethod_refreshInput FOR gmfgen::GenEditorView-»
+ org.eclipse.ui.IEditorPart editor = getSite().getPage().getActiveEditor();
+ if (editor != null && editor.getClass().equals(«editorGen.editor.getQualifiedClassName()».class)) {
+ setInput((«editorGen.editor.getQualifiedClassName()») editor);
+ }
+«ENDDEFINE»
+
+«DEFINE handleOpenMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void open(org.eclipse.jface.viewers.OpenEvent event) {
+ try {
+ org.eclipse.ui.IEditorPart editorPart = getSite().getPage().openEditor(
+ new org.eclipse.ui.part.FileEditorInput(org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(diagramResource)),
+ «editorGen.editor.getQualifiedClassName()».ID);
+ if (editorPart == null) {
+ return;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart diagramPart =
+ (org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart) editorPart.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart.class);
+ ElementMetrics selection = (ElementMetrics) ((org.eclipse.jface.viewers.IStructuredSelection) event.getSelection()).getFirstElement();
+ String viewID = selection.diagramElementID;
+ if (viewID != null) {
+ org.eclipse.gmf.runtime.notation.View targetView = (org.eclipse.gmf.runtime.notation.View) diagramPart.getDiagram().eResource().getEObject(viewID);
+ if (targetView != null) {
+ org.eclipse.gef.EditPart targetEditPart = (org.eclipse.gef.EditPart) diagramPart.getDiagramGraphicalViewer().getEditPartRegistry().get(targetView);
+ if (targetEditPart != null) {
+ «getDiagramEditorUtilQualifiedClassName()».selectElementsInDiagram(diagramPart, java.util.Collections.singletonList(targetEditPart));
+ }
+ }
+ }
+ } catch (org.eclipse.ui.PartInitException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Can't open diagram editor", e); //$NON-NLS-1$
+ }
+ }
+«ENDDEFINE»
+
+«DEFINE calcMetricMaxValueStrLenMapMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static java.util.Map calcMetricMaxValueStrLenMap(java.util.List allMetrics) {
+ java.util.Map metric2MaxStrLen = new java.util.HashMap();
+ for (int i = 0; i < getMetricKeys().length; i++) {
+ String nextKey = getMetricKeys()[i];
+ int trimPos = Math.min(nextKey.length(), MAX_VISIBLE_KEY_CHAR_COUNT);
+ metric2MaxStrLen.put(nextKey, nextKey.substring(0, trimPos));
+ }
+ for (java.util.Iterator it = allMetrics.iterator(); it.hasNext();) {
+ ElementMetrics elementMetrics = (ElementMetrics) it.next();
+ for (int i = 0; i < elementMetrics.metrics.length; i++) {
+ Metric metric = elementMetrics.metrics[i];
+ String valueStr = (String) metric2MaxStrLen.get(metric.key);
+ if (valueStr == null || metric.displayValue.length() > valueStr.length()) {
+ metric2MaxStrLen.put(metric.key, metric.displayValue);
+ }
+ }
+ }
+ return metric2MaxStrLen;
+ }
+«ENDDEFINE»
+
+«DEFINE setFocusMethod FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void setFocus() {
+ }
+«ENDDEFINE»
+
+«DEFINE labelProviderClass FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private class Labels extends org.eclipse.jface.viewers.LabelProvider implements org.eclipse.jface.viewers.ITableLabelProvider, org.eclipse.jface.viewers.ITableColorProvider {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private boolean isElementColumn(int columnIndex) {
+ return columnIndex >= getMetricKeys().length;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.swt.graphics.Image getColumnImage(Object element, int columnIndex) {
+ return isElementColumn(columnIndex) ? ((ElementMetrics) element).elementImage : null;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String getColumnText(Object element, int columnIndex) {
+ ElementMetrics elementMetrics = (ElementMetrics) element;
+ if (columnIndex == getMetricKeys().length) {
+ return elementMetrics.targetElementQName;
+ }
+ final String key = getMetricKeys()[columnIndex];
+ Metric metric = elementMetrics.getMetricByKey(key);
+ return (metric != null) ? metric.displayValue : "-"; //$NON-NLS-1$
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.swt.graphics.Color getBackground(Object element, int columnIndex) {
+ return null;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.swt.graphics.Color getForeground(Object element, int columnIndex) {
+ if (isElementColumn(columnIndex)) {
+ return null;
+ }
+ ElementMetrics columnElement = (ElementMetrics) element;
+ final String key = getMetricKeys()[columnIndex];
+ Metric metric = columnElement.getMetricByKey(key);
+ if (metric != null && metric.value != null) {
+ if (metric.highLimit != null && metric.highLimit.longValue() < metric.value.longValue()) {
+ return «EXPAND labelProvider_colorMore»;
+ } else if (metric.lowLimit != null && metric.lowLimit.longValue() > metric.value.longValue()) {
+ return «EXPAND labelProvider_colorLess»;
+ }
+ }
+ return null;
+ }
+ }
+«ENDDEFINE»
+
+«DEFINE labelProvider_colorMore FOR gmfgen::GenDiagram»org.eclipse.draw2d.ColorConstants.red«ENDDEFINE»
+«DEFINE labelProvider_colorLess FOR gmfgen::GenDiagram»org.eclipse.draw2d.ColorConstants.blue«ENDDEFINE»
+
+
+ \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ModelingAssistantProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ModelingAssistantProvider.xpt
new file mode 100644
index 000000000..5eb871f8a
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ModelingAssistantProvider.xpt
@@ -0,0 +1,253 @@
+/*
+ * 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 API and implementation
+ * Michael Golubev (Borland) - #244970 (GenChildLabelNode can't be link's source/target)
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+
+«EXTENSION xpt::diagram::editparts::Utils»
+«EXTENSION xpt::diagram::Utils»
+«EXTENSION xpt::providers::i18n»
+
+«DEFINE ModelingAssistantProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «modelingAssistantProviderClassName»
+ extends org.eclipse.gmf.runtime.emf.ui.services.modelingassistant.ModelingAssistantProvider {
+
+ «EXPAND getTypesForPopupBar-»
+
+ «EXPAND getRelTypesOnSource-»
+
+ «EXPAND getRelTypesOnTarget-»
+
+ «EXPAND getRelTypesOnSourceAndTarget-»
+
+ «EXPAND getTypesForSource-»
+
+ «EXPAND getTypesForTarget-»
+
+ «EXPAND selectExistingElementForSource-»
+
+ «EXPAND selectExistingElementForTarget-»
+
+ «EXPAND selectExistingElement-»
+
+ «EXPAND isApplicableElement-»
+
+ «EXPAND selectElement-»
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE getTypesForPopupBar FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public java.util.List getTypesForPopupBar(org.eclipse.core.runtime.IAdaptable host) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) host.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ «FOREACH getAllContainers()->asSequence() AS container-»
+ «IF container.getAssistantNodes()->size() > 0-»
+ if (editPart instanceof «container.getEditPartQualifiedClassName()») {
+ java.util.ArrayList types = new java.util.ArrayList(«container.getAssistantNodes()->size()»);
+ «FOREACH container.getAssistantNodes()->asSequence() AS node-»
+ types.add(«EXPAND xpt::providers::ElementTypes::accessElementType FOR node»);
+ «ENDFOREACH-»
+ return types;
+ }
+ «ENDIF-»
+ «ENDFOREACH-»
+ return java.util.Collections.EMPTY_LIST;
+ }
+«ENDDEFINE»
+
+«DEFINE getRelTypesOnSource FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public java.util.List getRelTypesOnSource(org.eclipse.core.runtime.IAdaptable source) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart sourceEditPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) source.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ «FOREACH getNodes(self) AS source-»
+ «IF getAssistantOutgoingLinks(source)->size() > 0-»
+ if (sourceEditPart instanceof «source.getEditPartQualifiedClassName()») {
+ return ((«source.getEditPartQualifiedClassName()») sourceEditPart).getMARelTypesOnSource();
+ }
+ «ENDIF-»
+ «ENDFOREACH-»
+ return java.util.Collections.EMPTY_LIST;
+ }
+«ENDDEFINE»
+
+«DEFINE getRelTypesOnTarget FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public java.util.List getRelTypesOnTarget(org.eclipse.core.runtime.IAdaptable target) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart targetEditPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) target.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ «FOREACH getNodes(self) AS target-»
+ «IF getAssistantIncomingLinks(target)->size() > 0-»
+ if (targetEditPart instanceof «target.getEditPartQualifiedClassName()») {
+ return ((«target.getEditPartQualifiedClassName()») targetEditPart).getMARelTypesOnTarget();
+ }
+ «ENDIF-»
+ «ENDFOREACH-»
+ return java.util.Collections.EMPTY_LIST;
+ }
+«ENDDEFINE»
+
+«DEFINE getRelTypesOnSourceAndTarget FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public java.util.List getRelTypesOnSourceAndTarget(
+ org.eclipse.core.runtime.IAdaptable source, org.eclipse.core.runtime.IAdaptable target) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart sourceEditPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) source.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart targetEditPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) target.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ «FOREACH getNodes(self) AS source-»
+ «IF getAssistantOutgoingLinks(source)->size() > 0-»
+ if (sourceEditPart instanceof «source.getEditPartQualifiedClassName()») {
+ return ((«source.getEditPartQualifiedClassName()») sourceEditPart).getMARelTypesOnSourceAndTarget(targetEditPart);
+ }
+ «ENDIF-»
+ «ENDFOREACH-»
+ return java.util.Collections.EMPTY_LIST;
+ }
+«ENDDEFINE»
+
+«DEFINE getTypesForSource FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public java.util.List getTypesForSource(org.eclipse.core.runtime.IAdaptable target,
+ org.eclipse.gmf.runtime.emf.type.core.IElementType relationshipType) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart targetEditPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) target.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ «FOREACH getNodes(self) AS target-»
+ «IF getAssistantIncomingLinks(target)->size() > 0-»
+ if (targetEditPart instanceof «target.getEditPartQualifiedClassName()») {
+ return ((«target.getEditPartQualifiedClassName()») targetEditPart).getMATypesForSource(relationshipType);
+ }
+ «ENDIF-»
+ «ENDFOREACH-»
+ return java.util.Collections.EMPTY_LIST;
+ }
+«ENDDEFINE»
+
+«DEFINE getTypesForTarget FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public java.util.List getTypesForTarget(org.eclipse.core.runtime.IAdaptable source,
+ org.eclipse.gmf.runtime.emf.type.core.IElementType relationshipType) {
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart sourceEditPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) source.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ «FOREACH getNodes(self) AS source-»
+ «IF getAssistantOutgoingLinks(source)->size() > 0-»
+ if (sourceEditPart instanceof «source.getEditPartQualifiedClassName()») {
+ return ((«source.getEditPartQualifiedClassName()») sourceEditPart).getMATypesForTarget(relationshipType);
+ }
+ «ENDIF-»
+ «ENDFOREACH-»
+ return java.util.Collections.EMPTY_LIST;
+ }
+«ENDDEFINE»
+
+«DEFINE selectExistingElementForSource FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.emf.ecore.EObject selectExistingElementForSource(
+ org.eclipse.core.runtime.IAdaptable target,
+ org.eclipse.gmf.runtime.emf.type.core.IElementType relationshipType) {
+ return selectExistingElement(target, getTypesForSource(target, relationshipType));
+ }
+«ENDDEFINE»
+
+«DEFINE selectExistingElementForTarget FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.emf.ecore.EObject selectExistingElementForTarget(
+ org.eclipse.core.runtime.IAdaptable source,
+ org.eclipse.gmf.runtime.emf.type.core.IElementType relationshipType) {
+ return selectExistingElement(source, getTypesForTarget(source, relationshipType));
+ }
+«ENDDEFINE»
+
+«DEFINE selectExistingElement FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.emf.ecore.EObject selectExistingElement(
+ org.eclipse.core.runtime.IAdaptable host, java.util.Collection types) {
+ if (types.isEmpty()) {
+ return null;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart =
+ (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) host.getAdapter(
+ org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.class);
+ if (editPart == null) {
+ return null;
+ }
+ org.eclipse.gmf.runtime.notation.Diagram diagram =
+ (org.eclipse.gmf.runtime.notation.Diagram) editPart.getRoot().getContents().getModel();
+ java.util.Collection elements = new java.util.HashSet();
+ for (java.util.Iterator it = diagram.getElement().eAllContents(); it.hasNext();) {
+ org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) it.next();
+ if (isApplicableElement(element, types)) {
+ elements.add(element);
+ }
+ }
+ if (elements.isEmpty()) {
+ return null;
+ }
+ return selectElement((org.eclipse.emf.ecore.EObject[]) elements.toArray(
+ new org.eclipse.emf.ecore.EObject[elements.size()]));
+ }
+«ENDDEFINE»
+
+«DEFINE isApplicableElement FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected boolean isApplicableElement(org.eclipse.emf.ecore.EObject element, java.util.Collection types) {
+ org.eclipse.gmf.runtime.emf.type.core.IElementType type =
+ org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry.getInstance().getElementType(element);
+ return types.contains(type);
+ }
+«ENDDEFINE»
+
+«DEFINE selectElement FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.emf.ecore.EObject selectElement(org.eclipse.emf.ecore.EObject[] elements) {
+ org.eclipse.swt.widgets.Shell shell = org.eclipse.swt.widgets.Display.getCurrent().getActiveShell();
+ org.eclipse.jface.viewers.ILabelProvider labelProvider =
+ new org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider(
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemProvidersAdapterFactory());
+ org.eclipse.ui.dialogs.ElementListSelectionDialog dialog =
+ new org.eclipse.ui.dialogs.ElementListSelectionDialog(shell, labelProvider);
+ dialog.setMessage(«EXPAND xpt::Externalizer::accessorCall(messageKey(i18nKeyForModelingAssistantProvider(self))) FOR editorGen»);
+ dialog.setTitle(«EXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForModelingAssistantProvider(self))) FOR editorGen»);
+ dialog.setMultipleSelection(false);
+ dialog.setElements(elements);
+ org.eclipse.emf.ecore.EObject selected = null;
+ if (dialog.open() == org.eclipse.jface.window.Window.OK) {
+ selected = (org.eclipse.emf.ecore.EObject) dialog.getFirstResult();
+ }
+ return selected;
+ }
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram-»«ENDDEFINE»
+
+«DEFINE i18nValues FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForModelingAssistantProvider(self)), 'Select domain model element')-»
+«EXPAND xpt::Externalizer::messageEntry(messageKey(i18nKeyForModelingAssistantProvider(self)), 'Available domain model elements:')-»
+«ENDDEFINE»
+
+«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForModelingAssistantProvider(self)))-»
+ «EXPAND xpt::Externalizer::accessorField(messageKey(i18nKeyForModelingAssistantProvider(self)))-»
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ParserUtils.qvto b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ParserUtils.qvto
new file mode 100644
index 000000000..5958104c8
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ParserUtils.qvto
@@ -0,0 +1,17 @@
+import xpt.StringOperations;
+
+modeltype genModel uses "http://www.eclipse.org/gmf/2008/GenModel";
+
+library ParserUtils;
+
+helper parserFieldName(element : genModel::GenCommonBase) : String {
+ return element.getUniqueIdentifier().xpandToFirstLower() + 'Parser'
+}
+
+helper parserAccessorName(element : genModel::GenCommonBase) : String {
+ return 'get' + element.getUniqueIdentifier().firstToUpper() + 'Parser'
+}
+
+helper isPatternSpecified(pattern : String) : Boolean {
+ return pattern <> null and pattern.xpandLength() > 0
+}
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ShortcutsDecoratorProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ShortcutsDecoratorProvider.xpt
new file mode 100644
index 000000000..11c9dddbc
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ShortcutsDecoratorProvider.xpt
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2006,2007 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:
+ * Alexander Shatalin (Borland) - initial API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+
+«DEFINE ShortcutsDecoratorProvider FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+ «EXPAND xpt::Common::generatedClassComment»
+public class «shortcutsDecoratorProviderClassName» extends org.eclipse.gmf.runtime.common.core.service.AbstractProvider implements org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider {
+
+ «EXPAND attributes-»
+
+ «EXPAND provides-»
+
+ «EXPAND createDecorators-»
+
+ «EXPAND ShortcutsDecorator-»
+
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE attributes FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public static final String SHORTCUTS_DECORATOR_ID = "shortcuts"; «EXPAND xpt::Common::nonNLS»
+«ENDDEFINE»
+
+«DEFINE provides FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
+ if (!(operation instanceof org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation)) {
+ return false;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget = ((org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation) operation).getDecoratorTarget();
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) decoratorTarget.getAdapter(org.eclipse.gmf.runtime.notation.View.class);
+ return view != null && «EXPAND xpt::editor::VisualIDRegistry::modelID».equals(«EXPAND xpt::editor::VisualIDRegistry::getModelIDMethodCall»(view));
+}
+«ENDDEFINE»
+
+«DEFINE createDecorators FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget) {
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) decoratorTarget.getAdapter(org.eclipse.gmf.runtime.notation.View.class);
+ if (view != null) {
+ org.eclipse.emf.ecore.EAnnotation annotation = view.getEAnnotation("Shortcut"); «EXPAND xpt::Common::nonNLS»
+ if (annotation != null) {
+ decoratorTarget.installDecorator(SHORTCUTS_DECORATOR_ID, new ShortcutsDecorator(decoratorTarget));
+ }
+ }
+}
+«ENDDEFINE»
+
+«DEFINE ShortcutsDecorator FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedClassComment»
+protected class ShortcutsDecorator extends org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator {
+
+ «EXPAND SD_constructor-»
+
+ «EXPAND SD_activate-»
+
+ «EXPAND SD_refresh-»
+
+ «EXPAND SD_additions-»
+}
+«ENDDEFINE»
+
+«DEFINE SD_constructor FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public ShortcutsDecorator(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget) {
+ super(decoratorTarget);
+}
+«ENDDEFINE»
+
+«DEFINE SD_activate FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void activate() {
+ refresh();
+}
+«ENDDEFINE»
+
+«DEFINE SD_refresh FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+public void refresh() {
+ removeDecoration();
+ org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) getDecoratorTarget().getAdapter(org.eclipse.gef.EditPart.class);
+ org.eclipse.swt.graphics.Image image = «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getBundledImage("icons/shortcut.gif"); «EXPAND xpt::Common::nonNLS»
+ if (editPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart) {
+ setDecoration(getDecoratorTarget().addShapeDecoration(image, org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget.Direction.SOUTH_WEST, 0, false));
+ } else if (editPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) {
+ setDecoration(getDecoratorTarget().addConnectionDecoration(image, 50, false));
+ }
+}
+«ENDDEFINE»
+
+«DEFINE SD_additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram-»
+«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationDecoratorProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationDecoratorProvider.xpt
new file mode 100644
index 000000000..96bdd1697
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationDecoratorProvider.xpt
@@ -0,0 +1,393 @@
+/*
+ * Copyright (c) 2007 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 API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+
+«DEFINE ValidationDecoratorProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «validationDecoratorProviderClassName»
+ extends org.eclipse.gmf.runtime.common.core.service.AbstractProvider
+ implements org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static final String KEY = "validationStatus"; «EXPAND xpt::Common::nonNLS»
+ «IF editorGen.application = null-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static final String MARKER_TYPE = «editorGen.plugin.getActivatorQualifiedClassName()».ID +
+ ".«getValidationDiagnosticMarkerType()»"; «EXPAND xpt::Common::nonNLS»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static MarkerObserver fileObserver;
+ «ENDIF-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static java.util.Map/*<String, List<IDecorator>>*/ allDecorators = new java.util.HashMap();
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget) {
+ org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) decoratorTarget.getAdapter(org.eclipse.gef.EditPart.class);
+ if (editPart instanceof org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart ||
+ editPart instanceof org.eclipse.gef.editparts.AbstractConnectionEditPart) {
+ Object model = editPart.getModel();
+ if ((model instanceof org.eclipse.gmf.runtime.notation.View)) {
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) model;
+ if (!(view instanceof org.eclipse.gmf.runtime.notation.Edge) && !view.isSetElement()) {
+ return;
+ }
+ }
+ org.eclipse.gef.EditDomain ed = editPart.getViewer().getEditDomain();
+ if (!(ed instanceof org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain)) {
+ return;
+ }
+ if (((org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain) ed).getEditorPart() instanceof
+ «editorGen.editor.getQualifiedClassName()») {
+ decoratorTarget.installDecorator(KEY, new StatusDecorator(decoratorTarget));
+ }
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean provides(org.eclipse.gmf.runtime.common.core.service.IOperation operation) {
+ if (!(operation instanceof org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation)) {
+ return false;
+ }
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget =
+ ((org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation) operation).getDecoratorTarget();
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) decoratorTarget.getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ return view != null && «EXPAND xpt::editor::VisualIDRegistry::modelID».equals(«EXPAND xpt::editor::VisualIDRegistry::getModelIDMethodCall»(view));
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static void refreshDecorators(org.eclipse.gmf.runtime.notation.View view) {
+ refreshDecorators(org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr(view), view.getDiagram());
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static void refreshDecorators(String viewId, org.eclipse.gmf.runtime.notation.Diagram diagram) {
+ final java.util.List decorators = viewId != null ? (java.util.List) allDecorators.get(viewId) : null;
+ if (decorators == null || decorators.isEmpty() || diagram == null) {
+ return;
+ }
+ final org.eclipse.gmf.runtime.notation.Diagram fdiagram = diagram;
+ org.eclipse.ui.PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ try {
+ org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(fdiagram).runExclusive(new Runnable() {
+
+ public void run() {
+ for (java.util.Iterator it = decorators.iterator(); it.hasNext();) {
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator decorator =
+ (org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator) it.next();
+ decorator.refresh();
+ }
+ }
+ });
+ } catch (Exception e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Decorator refresh failure", e); «EXPAND xpt::Common::nonNLS»
+ }
+ }
+ });
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static class StatusDecorator extends org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String viewId;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public StatusDecorator(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget decoratorTarget) {
+ super(decoratorTarget);
+ try {
+ final org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) getDecoratorTarget().getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() {
+
+ public void run() {
+ StatusDecorator.this.viewId = view != null ?
+ org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr(view) : null;
+ }
+ });
+ } catch (Exception e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "ViewID access failure", e); «EXPAND xpt::Common::nonNLS»
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void refresh() {
+ removeDecoration();
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) getDecoratorTarget().getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ if (view == null || view.eResource() == null) {
+ return;
+ }
+ org.eclipse.gef.EditPart editPart = (org.eclipse.gef.EditPart) getDecoratorTarget().getAdapter(org.eclipse.gef.EditPart.class);
+ if (editPart == null || editPart.getViewer() == null) {
+ return;
+ }
+
+ // query for all the validation markers of the current resource
+ «IF editorGen.application = null-»
+ String elementId = org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.getIdStr(view);
+ if (elementId == null) {
+ return;
+ }
+ int severity = org.eclipse.core.resources.IMarker.SEVERITY_INFO;
+ org.eclipse.core.resources.IMarker foundMarker = null;
+ org.eclipse.core.resources.IResource resource = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(view.eResource());
+ if (resource == null || !resource.exists()) {
+ return;
+ }
+ org.eclipse.core.resources.IMarker[] markers = null;
+ try {
+ markers = resource.findMarkers(MARKER_TYPE, true, org.eclipse.core.resources.IResource.DEPTH_INFINITE);
+ } catch (org.eclipse.core.runtime.CoreException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Validation markers refresh failure", e); «EXPAND xpt::Common::nonNLS»
+ }
+ «ELSE-»
+ int severity = org.eclipse.core.runtime.IStatus.INFO;
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName» foundMarker = null;
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName»[] markers =
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName».getMarkers(editPart.getViewer(), viewId);
+ «ENDIF-»
+ if (markers == null || markers.length == 0) {
+ return;
+ }
+ org.eclipse.draw2d.Label toolTip = null;
+ for (int i = 0; i < markers.length; i++) {
+ «IF editorGen.application = null-»
+ org.eclipse.core.resources.IMarker marker = markers[i];
+ String attribute = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); «EXPAND xpt::Common::nonNLS»
+ if (attribute.equals(elementId)) {
+ int nextSeverity = marker.getAttribute(org.eclipse.core.resources.IMarker.SEVERITY,
+ org.eclipse.core.resources.IMarker.SEVERITY_INFO);
+ «ELSE-»
+ «EXPAND xpt::editor::ValidationMarker::qualifiedClassName» marker = markers[i];
+ int nextSeverity = marker.getStatusSeverity();
+ «ENDIF-»
+ org.eclipse.swt.graphics.Image nextImage = getImage(nextSeverity);
+ if (foundMarker == null) {
+ foundMarker = marker;
+ toolTip = new org.eclipse.draw2d.Label(
+ «IF editorGen.application = null-»
+ marker.getAttribute(org.eclipse.core.resources.IMarker.MESSAGE, ""), «EXPAND xpt::Common::nonNLS»
+ «ELSE-»
+ marker.getMessage(),
+ «ENDIF-»
+ nextImage);
+ } else {
+ if (toolTip.getChildren().isEmpty()) {
+ org.eclipse.draw2d.Label comositeLabel = new org.eclipse.draw2d.Label();
+ org.eclipse.draw2d.FlowLayout fl = new org.eclipse.draw2d.FlowLayout(false);
+ fl.setMinorSpacing(0);
+ comositeLabel.setLayoutManager(fl);
+ comositeLabel.add(toolTip);
+ toolTip = comositeLabel;
+ }
+ toolTip.add(new org.eclipse.draw2d.Label(
+ «IF editorGen.application = null-»
+ marker.getAttribute(org.eclipse.core.resources.IMarker.MESSAGE, ""), «EXPAND xpt::Common::nonNLS»
+ «ELSE-»
+ marker.getMessage(),
+ «ENDIF-»
+ nextImage));
+ }
+ severity = (nextSeverity > severity) ? nextSeverity : severity;
+ «IF editorGen.application = null-»
+ }
+ «ENDIF-»
+ }
+ if (foundMarker == null) {
+ return;
+ }
+
+ // add decoration
+ if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
+ if (view instanceof org.eclipse.gmf.runtime.notation.Edge) {
+ setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true));
+ } else {
+ int margin = -1;
+ if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
+ margin = org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil.getMapMode(
+ ((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()).DPtoLP(margin);
+ }
+ setDecoration(getDecoratorTarget().addShapeDecoration(getImage(severity),
+ org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget.Direction.NORTH_EAST, margin, true));
+ }
+ getDecoration().setToolTip(toolTip);
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.swt.graphics.Image getImage(int severity) {
+ String imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_ERROR_TSK;
+ switch (severity) {
+ «IF editorGen.application = null-»
+ case org.eclipse.core.resources.IMarker.SEVERITY_ERROR:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_ERROR_TSK;
+ break;
+ case org.eclipse.core.resources.IMarker.SEVERITY_WARNING:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_WARN_TSK;
+ break;
+ «ELSE-»
+ case org.eclipse.core.runtime.IStatus.ERROR:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_ERROR_TSK;
+ break;
+ case org.eclipse.core.runtime.IStatus.WARNING:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_WARN_TSK;
+ break;
+ «ENDIF-»
+ default:
+ imageName = org.eclipse.ui.ISharedImages.IMG_OBJS_INFO_TSK;
+ }
+ return org.eclipse.ui.PlatformUI.getWorkbench().getSharedImages().getImage(imageName);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void activate() {
+ if (viewId == null) {
+ return;
+ }
+
+ // add self to global decorators registry
+ java.util.List list = (java.util.List) allDecorators.get(viewId);
+ if (list == null) {
+ list = new java.util.ArrayList(2);
+ list.add(this);
+ allDecorators.put(viewId, list);
+ } else if (!list.contains(this)) {
+ list.add(this);
+ }
+ «IF editorGen.application = null-»
+
+ // start listening to changes in resources
+ org.eclipse.gmf.runtime.notation.View view = (org.eclipse.gmf.runtime.notation.View) getDecoratorTarget().getAdapter(
+ org.eclipse.gmf.runtime.notation.View.class);
+ if (view == null) {
+ return;
+ }
+ org.eclipse.gmf.runtime.notation.Diagram diagramView = view.getDiagram();
+ if (diagramView == null) {
+ return;
+ }
+ if (fileObserver == null) {
+ org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager.getInstance().addFileObserver(
+ fileObserver = new MarkerObserver(diagramView));
+ }
+ «ENDIF-»
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void deactivate() {
+ if (viewId == null) {
+ return;
+ }
+
+ // remove self from global decorators registry
+ java.util.List list = (java.util.List) allDecorators.get(viewId);
+ if (list != null) {
+ list.remove(this);
+ if (list.isEmpty()) {
+ allDecorators.remove(viewId);
+ }
+ }
+ «IF editorGen.application = null-»
+
+ // stop listening to changes in resources if there are no more decorators
+ if (fileObserver != null && allDecorators.isEmpty()) {
+ org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager.getInstance().removeFileObserver(fileObserver);
+ fileObserver = null;
+ }
+ «ENDIF-»
+ super.deactivate();
+ }
+ }
+ «IF editorGen.application = null-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ static class MarkerObserver implements org.eclipse.gmf.runtime.common.ui.resources.IFileObserver {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.gmf.runtime.notation.Diagram diagram;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private MarkerObserver(org.eclipse.gmf.runtime.notation.Diagram diagram) {
+ this.diagram = diagram;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileRenamed(org.eclipse.core.resources.IFile oldFile, org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileMoved(org.eclipse.core.resources.IFile oldFile, org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileDeleted(org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleFileChanged(org.eclipse.core.resources.IFile file) {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleMarkerAdded(org.eclipse.core.resources.IMarker marker) {
+ if (marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, null) != null) {
+ handleMarkerChanged(marker);
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleMarkerDeleted(org.eclipse.core.resources.IMarker marker, java.util.Map attributes) {
+ String viewId = (String) attributes.get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID);
+ refreshDecorators(viewId, diagram);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void handleMarkerChanged(org.eclipse.core.resources.IMarker marker) {
+ if (!MARKER_TYPE.equals(getType(marker))) {
+ return;
+ }
+ String viewId = marker.getAttribute(
+ org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); «EXPAND xpt::Common::nonNLS»
+ refreshDecorators(viewId, diagram);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private String getType(org.eclipse.core.resources.IMarker marker) {
+ try {
+ return marker.getType();
+ } catch (org.eclipse.core.runtime.CoreException e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
+ "Validation marker refresh failure", e); «EXPAND xpt::Common::nonNLS»
+ return ""; «EXPAND xpt::Common::nonNLS»
+ }
+ }
+ }
+ «ENDIF-»
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationProvider.xpt
new file mode 100644
index 000000000..4a5019174
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ValidationProvider.xpt
@@ -0,0 +1,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 API and implementation
+ * Artem Tikhomirov (Borland) - introduced GenAuditContext entity
+ * straightforward and simple #validate() implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+
+«EXTENSION xpt::GenModelUtils»
+«EXTENSION xpt::EMFUtils»
+«EXTENSION xpt::GenAuditRoot»
+«EXTENSION xpt::GenEditorGenerator»
+«EXTENSION xpt::StringOperations»
+
+
+«DEFINE ValidationProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «validationProviderClassName» {
+
+ «EXPAND constraintsActive-»
+
+ «EXPAND shouldConstraintsBePrivate-»
+
+ «EXPAND runWithActiveConstraints-»
+
+ «EXPAND isInDefaultEditorContext-»
+
+«EXPAND selectors FOR editorGen.audits-»
+
+«EXPAND strategy_support»
+
+«EXPAND constraintAdapters(self) FOR editorGen.audits-»
+
+«EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE constraintsActive FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::generatedMemberComment»
+private static boolean constraintsActive = false;
+«ENDDEFINE»
+
+«DEFINE shouldConstraintsBePrivate FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::generatedMemberComment»
+public static boolean shouldConstraintsBePrivate() {
+ return false;
+}
+«ENDDEFINE»
+
+«DEFINE runWithActiveConstraints FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::generatedMemberComment»
+public static void runWithConstraints(org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain, Runnable operation) {
+ final Runnable op = operation;
+ Runnable task = new Runnable() {
+ public void run() {
+ try {
+ constraintsActive = true;
+ op.run();
+ } finally {
+ constraintsActive = false;
+ }
+ }
+ };
+ if(editingDomain != null) {
+ try {
+ editingDomain.runExclusive(task);
+ } catch (Exception e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Validation failed", e); «EXPAND xpt::Common::nonNLS»
+ }
+ } else {
+ task.run();
+ }
+}
+«ENDDEFINE»
+
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
+
+«DEFINE selectors FOR gmfgen::GenAuditRoot-»
+«FOREACH clientContexts->asSequence() AS ctx»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static class «ctx.className» implements org.eclipse.emf.validation.model.IClientSelector {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean selects(Object object) {
+«IF (ctx.ruleTargets)[gmfgen::GenDiagramElementTarget]->size() > 0 -»
+ if (isInDefaultEditorContext(object) && object instanceof org.eclipse.gmf.runtime.notation.View) {
+ final int id = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR editorGen.diagram»((org.eclipse.gmf.runtime.notation.View) object);
+ boolean result = false;
+«FOREACH getTargetDiagramElements(ctx) AS e-»
+ result = result || id == «EXPAND xpt::editor::VisualIDRegistry::visualID FOR e»;
+«ENDFOREACH-»
+ return result;
+ }
+ return false;
+«ELSE-»
+ return isInDefaultEditorContext(object);
+«ENDIF-»
+ }
+ }
+«ENDFOREACH-»
+«ENDDEFINE»
+
+«DEFINE isInDefaultEditorContext FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::generatedMemberComment»
+static boolean isInDefaultEditorContext(Object object) {
+ if(shouldConstraintsBePrivate() && !constraintsActive) {
+ return false;
+ }
+ if (object instanceof org.eclipse.gmf.runtime.notation.View) {
+ return constraintsActive && «EXPAND xpt::editor::VisualIDRegistry::modelID».equals(«EXPAND xpt::editor::VisualIDRegistry::getModelIDMethodCall»((org.eclipse.gmf.runtime.notation.View) object));
+ }
+ return true;
+}
+«ENDDEFINE»
+
+
+«DEFINE strategy_support FOR gmfgen::GenDiagram-»
+«IF hasDiagramElementTargetRule(editorGen.audits)-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static org.eclipse.emf.validation.service.ITraversalStrategy getNotationTraversalStrategy(
+ org.eclipse.emf.validation.service.IBatchValidator validator) {
+ return new CtxSwitchStrategy(validator);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static class CtxSwitchStrategy implements org.eclipse.emf.validation.service.ITraversalStrategy {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.emf.validation.service.ITraversalStrategy defaultStrategy;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private int currentSemanticCtxId = -1;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private boolean ctxChanged = true;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.emf.ecore.EObject currentTarget;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.emf.ecore.EObject preFetchedNextTarget;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final int[] contextSwitchingIdentifiers;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ CtxSwitchStrategy(org.eclipse.emf.validation.service.IBatchValidator validator) {
+ this.defaultStrategy = validator.getDefaultTraversalStrategy();
+ this.contextSwitchingIdentifiers = new int[] {
+ «EXPAND xpt::editor::VisualIDRegistry::visualID FOREACH getAllTargetDiagramElements(editorGen.audits) SEPARATOR ','»
+ };
+ java.util.Arrays.sort(this.contextSwitchingIdentifiers);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void elementValidated(org.eclipse.emf.ecore.EObject element,
+ org.eclipse.core.runtime.IStatus status) {
+ defaultStrategy.elementValidated(element, status);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean hasNext() {
+ return defaultStrategy.hasNext();
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public boolean isClientContextChanged() {
+ if (preFetchedNextTarget == null) {
+ preFetchedNextTarget = next();
+ prepareNextClientContext(preFetchedNextTarget);
+ }
+ return ctxChanged;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.emf.ecore.EObject next() {
+ org.eclipse.emf.ecore.EObject nextTarget = preFetchedNextTarget;
+ if (nextTarget == null) {
+ nextTarget = defaultStrategy.next();
+ }
+ this.preFetchedNextTarget = null;
+ return this.currentTarget = nextTarget;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void startTraversal(java.util.Collection traversalRoots, org.eclipse.core.runtime.IProgressMonitor monitor) {
+ defaultStrategy.startTraversal(traversalRoots, monitor);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private void prepareNextClientContext(org.eclipse.emf.ecore.EObject nextTarget) {
+ if (nextTarget != null && currentTarget != null) {
+ if (nextTarget instanceof org.eclipse.gmf.runtime.notation.View) {
+ final int id = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR editorGen.diagram»((org.eclipse.gmf.runtime.notation.View) nextTarget);
+ int nextSemanticId = (id != -1 && java.util.Arrays.binarySearch(contextSwitchingIdentifiers, id) >= 0) ? id : -1;
+ if ((currentSemanticCtxId != -1 && currentSemanticCtxId != nextSemanticId)
+ || (nextSemanticId != -1 && nextSemanticId != currentSemanticCtxId)) {
+ this.ctxChanged = true;
+ }«/*[artem] not sure why not ctxChanged = <expr>, is it intentional not to reset ctxChanged if condition did not match? I doubt. FIXME?*/»
+ currentSemanticCtxId = nextSemanticId;
+ } else {
+ // context of domain model
+ this.ctxChanged = currentSemanticCtxId != -1;
+ currentSemanticCtxId = -1;
+ }
+ } else {
+ this.ctxChanged = false;
+ }
+ }
+ }
+«ENDIF-»
+«ENDDEFINE»
+
+
+«DEFINE constraintAdapters(diagram : gmfgen::GenDiagram) FOR gmfgen::GenAuditRoot-»
+«IF diagram.editorGen.expressionProviders <> null-»
+«EXPAND constraintAdapter(diagram.editorGen.expressionProviders) FOREACH rules->select(a | a.requiresConstraintAdapter)-»
+«IF not rules->select(a | a.requiresConstraintAdapter)->isEmpty()»
+«EXPAND constraintAdapters_formatMethod»
+«ENDIF»
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE constraintAdapter(container : gmfgen::GenExpressionProviderContainer) FOR gmfgen::GenAuditRule-»
+«IF target <> null and target.getContext() <> null-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static class «getConstraintAdapterLocalClassName()» extends org.eclipse.emf.validation.AbstractModelConstraint {
+
+«IF rule.provider.getLanguage() <> gmfgen::GenLanguage::java-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «container.getAbstractExpressionQualifiedClassName()» expression;
+
+«ENDIF-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.core.runtime.IStatus validate(org.eclipse.emf.validation.IValidationContext ctx) {
+ «EXPAND constraintAdapter_initContext(self) FOR target-»
+ «EXPAND constraintAdapter_validateMethod(self) FOR rule.provider-»
+ }
+ }
+«ENDIF-»
+«ENDDEFINE»
+
+
+«DEFINE constraintAdapters_formatMethod FOR gmfgen::GenAuditRoot-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ static String formatElement(org.eclipse.emf.ecore.EObject object) {
+ return org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil.getQualifiedName(object, true);
+ }
+«ENDDEFINE»
+
+/*
+ * Expects 'context' variable to be initialized
+ */
+«DEFINE constraintAdapter_validateMethod(audit : gmfgen::GenAuditRule) FOR gmfgen::GenExpressionProviderBase»«ERROR 'No idea how to evaluate an audit rule for ' + self.repr()»«ENDDEFINE»
+
+«DEFINE constraintAdapter_validateMethod(audit : gmfgen::GenAuditRule) FOR gmfgen::GenExpressionInterpreter-»
+ if (expression == null) {
+ expression = «EXPAND xpt::expressions::getExpression::getExpression(audit.rule, audit.target.getContext())»;
+ }
+ Object result = expression.evaluate(context);
+ if (result instanceof Boolean && ((Boolean) result).booleanValue()) {
+ return org.eclipse.core.runtime.Status.OK_STATUS;«REM»XXX why not ctx.createSuccessStatus()???«ENDREM»
+ }
+ return ctx.createFailureStatus(new Object[] { formatElement(ctx.getTarget()) });
+«ENDDEFINE»
+
+«DEFINE constraintAdapter_validateMethod(audit : gmfgen::GenAuditRule) FOR gmfgen::GenJavaExpressionProvider-»
+«IF injectExpressionBody and (audit.rule.body <> null and audit.rule.body.xpandLength() <> 0)-»
+ «audit.rule.body»
+«ELSEIF throwException or (injectExpressionBody and (audit.rule.body = null or audit.rule.body.xpandLength() = 0))-»
+ // TODO: put validation code here
+ // Ensure that you remove @generated tag or use @generated NOT
+ //
+ // To construct approprate return value, use ctx.createSuccessStatus()
+ // or ctx.createFailureStatus(...)
+ throw new java.lang.UnsupportedOperationException("No user java implementation provided for #validate(IValidationContext) operation");«EXPAND xpt::Common::nonNLS»
+«ELSE-»
+ return ctx.createFailureStatus(new Object[] { "No user java implementation provided for #validate(IValidationContext) operation" });«EXPAND xpt::Common::nonNLS»
+«ENDIF-»
+«ENDDEFINE»
+
+/*
+ * Contract: declare variable with the name 'context' of appropriate type
+ */
+«DEFINE constraintAdapter_initContext(audit : gmfgen::GenAuditRule) FOR gmfgen::GenAuditable-»
+«EXPAND MetaModel::DeclareAndAssign('context', 'ctx.getTarget()', false) FOR getContext()»
+«ENDDEFINE»
+
+«DEFINE constraintAdapter_initContext(audit : gmfgen::GenAuditRule) FOR gmfgen::GenDomainAttributeTarget-»
+ final Object«REM»Actual context type is genDomainAttributeTarget.getContext()«ENDREM» context = ctx.getTarget().eGet(«EXPAND MetaModel::MetaFeature FOR attribute»);
+«REM»
+ For now, leave reflective access that gives Object-compatible result.
+
+ FIXME: introduce MetaModel::DeclareAndAssignAttributeValueAsObject, that would
+ check if attibute type is primitive and wrap accordingly, but access attribute directly!
+«ENDREM-»
+ if (context == null) {
+«IF nullAsError-»
+ return ctx.createFailureStatus(new Object[] { formatElement(ctx.getTarget()) });
+«ELSE-»
+ return org.eclipse.core.runtime.Status.OK_STATUS;
+«ENDIF-»
+ }
+«ENDDEFINE»
+
+«DEFINE constraintAdapter_initContext(audit : gmfgen::GenAuditRule) FOR gmfgen::GenAuditedMetricTarget-»
+final Number context = «IF metric = null /*though metamodel constraint should not allow this*/»null /*FIXME: metric target was not correctly specified in the model*/«ELSE»«EXPAND MetricProvider::invokeCalcMethod('ctx.getTarget()', false) FOR metric»«ENDIF»;
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt
new file mode 100644
index 000000000..b1abb033a
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/ViewProvider.xpt
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2007 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:
+ * Alexander Shatalin (Borland) - initial API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+
+«EXTENSION xpt::diagram::Utils»
+
+«DEFINE ViewProvider FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR getDiagram().editorGen-»
+package «providersPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «notationViewProviderClassName» extends org.eclipse.gmf.runtime.diagram.core.providers.AbstractViewProvider {
+ «EXPAND getDiagramViewClass-»
+ «EXPAND getNodeViewClass-»
+ «EXPAND getEdgeViewClass-»
+ «EXPAND getSemanticElementType-»
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE getDiagramViewClass FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getDiagramViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter, String diagramKind) {
+ «REM»When diagram domain element is null only diagram kind is checked«ENDREM-»
+ «EXPAND defineSemanticElement FOR domainDiagramElement-»
+ if («EXPAND xpt::editor::VisualIDRegistry::modelID».equals(diagramKind)«EXPAND checkSemanticElement(self) FOR domainDiagramElement») {
+ return «getNotationViewFactoryQualifiedClassName()».class;
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE defineSemanticElement FOR genmodel::GenClass-»
+org.eclipse.emf.ecore.EObject semanticElement = getSemanticElement(semanticAdapter);
+«ENDDEFINE»
+
+«DEFINE checkSemanticElement(diagram : gmfgen::GenDiagram) FOR genmodel::GenClass» && «EXPAND xpt::editor::VisualIDRegistry::getDiagramVisualIDMethodCall FOR diagram»(semanticElement) != -1«ENDDEFINE»
+
+«DEFINE getNodeViewClass FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getNodeViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter,
+ org.eclipse.gmf.runtime.notation.View containerView, String semanticHint) {
+ if (containerView == null) {
+ return null;
+ }
+ org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = getSemanticElementType(semanticAdapter);
+ org.eclipse.emf.ecore.EObject domainElement = getSemanticElement(semanticAdapter);
+ int visualID;
+ if (semanticHint == null) {
+ // Semantic hint is not specified. Can be a result of call from CanonicalEditPolicy.
+ // In this situation there should be NO elementType, visualID will be determined
+ // by VisualIDRegistry.getNodeVisualID() for domainElement.
+ if (elementType != null || domainElement == null) {
+ return null;
+ }
+ visualID = «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement);
+ } else {
+ visualID = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(semanticHint);
+ if (elementType != null) {
+ // Semantic hint is specified together with element type.
+ // Both parameters should describe exactly the same diagram element.
+ // In addition we check that visualID returned by VisualIDRegistry.getNodeVisualID() for
+ // domainElement (if specified) is the same as in element type.
+ if (!«getElementTypesQualifiedClassName()».isKnownElementType(elementType)
+ || (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) {
+ return null; // foreign element type
+ }
+ String elementTypeHint = ((org.eclipse.gmf.runtime.emf.type.core.IHintedType) elementType).getSemanticHint();
+ if (!semanticHint.equals(elementTypeHint)) {
+ return null; // if semantic hint is specified it should be the same as in element type
+ }
+ if (domainElement != null && visualID != «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement)) {
+ return null; // visual id for node EClass should match visual id from element type
+ }
+ } else {
+ // Element type is not specified. Domain element should be present (except pure design elements).
+ // This method is called with EObjectAdapter as parameter from:
+ // - ViewService.createNode(View container, EObject eObject, String type, PreferencesHint preferencesHint)
+ // - generated ViewFactory.decorateView() for parent element
+ «IF getElements(self)->select(e | e.elementType <> null)->size() > 0-»
+ if (!«getEditPartQualifiedClassName()».MODEL_ID.equals(«getVisualIDRegistryQualifiedClassName()».getModelID(containerView))) {
+ return null; // foreign diagram
+ }
+ switch (visualID) {
+ «IF ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::NotationType]->size() > 0-»
+ «EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::NotationType]-»
+ break; // pure design element
+ «ENDIF-»
+ «IF ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::MetamodelType]->size() > 0 or ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::SpecializationType]->size() > 0-»
+ «EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::MetamodelType]-»
+ «EXPAND caseVisualID FOREACH ((getElements(self))[gmfgen::GenNode].elementType)[gmfgen::SpecializationType]-»
+ if (domainElement == null || visualID != «EXPAND xpt::editor::VisualIDRegistry::getNodeVisualIDMethodCall»(containerView, domainElement)) {
+ return null; // visual id in semantic hint should match visual id for domain element
+ }
+ break;
+ «ENDIF-»
+ «EXPAND checkChildrenVisualIDs FOREACH getElements(self)->select(e | e.elementType <> null)-»
+ default:
+ return null;
+ }
+ «ELSE-»
+ return null;
+ «ENDIF-»
+ }
+ }
+ return getNodeViewClass(containerView, visualID);
+}
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getNodeViewClass(org.eclipse.gmf.runtime.notation.View containerView, int visualID) {
+ if (containerView == null || !«EXPAND xpt::editor::VisualIDRegistry::canCreateNodeMethodCall»(containerView, visualID)) {
+ return null;
+ }
+ switch (visualID) {
+ «EXPAND caseContainerVisualID FOREACH getAllChildContainers()-»
+ «EXPAND caseEntry FOREACH links.labels-»
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE caseVisualID FOR gmfgen::ElementType-»
+ «EXPAND xpt::Common::caseVisualID FOR diagramElement»
+«ENDDEFINE»
+
+«DEFINE checkChildrenVisualIDs FOR gmfgen::GenCommonBase-»
+«ENDDEFINE»
+
+«DEFINE checkChildrenVisualIDs FOR gmfgen::GenNode-»
+ «EXPAND xpt::Common::caseVisualID FOREACH labels-»
+ «EXPAND xpt::Common::caseVisualID FOREACH compartments-»
+ «IF not labels->isEmpty() or not compartments->isEmpty()-»
+if («EXPAND xpt::editor::VisualIDRegistry::visualID» != «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR getDiagram()»(containerView)
+ || containerView.getElement() != domainElement) {
+ return null; // wrong container
+}
+break;
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE checkChildrenVisualIDs FOR gmfgen::GenLink-»
+ «EXPAND xpt::Common::caseVisualID FOREACH labels-»
+ «IF not labels->isEmpty()-»
+if («EXPAND xpt::editor::VisualIDRegistry::visualID» != «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall FOR getDiagram()»(containerView)
+ || containerView.getElement() != domainElement) {
+ return null; // wrong container
+}
+break;
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE caseContainerVisualID FOR gmfgen::GenChildContainer-»
+ «EXPAND caseEntry-»
+«ENDDEFINE»
+
+«DEFINE caseContainerVisualID FOR gmfgen::GenNode-»
+ «EXPAND caseEntry-»
+ «EXPAND caseEntry FOREACH labels-»
+«ENDDEFINE»
+
+«DEFINE caseEntry FOR gmfgen::GenCommonBase-»
+ «EXPAND xpt::Common::caseVisualID» return «getNotationViewFactoryQualifiedClassName()».class;
+«ENDDEFINE»
+
+«DEFINE getEdgeViewClass FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getEdgeViewClass(org.eclipse.core.runtime.IAdaptable semanticAdapter,
+ org.eclipse.gmf.runtime.notation.View containerView, String semanticHint) {
+ org.eclipse.gmf.runtime.emf.type.core.IElementType elementType = getSemanticElementType(semanticAdapter);
+ if (!«getElementTypesQualifiedClassName()».isKnownElementType(elementType)
+ || (!(elementType instanceof org.eclipse.gmf.runtime.emf.type.core.IHintedType))) {
+ return null; // foreign element type
+ }
+ String elementTypeHint = ((org.eclipse.gmf.runtime.emf.type.core.IHintedType) elementType).getSemanticHint();
+ if (elementTypeHint == null) {
+ return null; // our hint is visual id and must be specified
+ }
+ if (semanticHint != null && !semanticHint.equals(elementTypeHint)) {
+ return null; // if semantic hint is specified it should be the same as in element type
+ }
+ int visualID = «EXPAND xpt::editor::VisualIDRegistry::getVisualIDMethodCall»(elementTypeHint);
+ org.eclipse.emf.ecore.EObject domainElement = getSemanticElement(semanticAdapter);
+ if (domainElement != null && visualID != «EXPAND xpt::editor::VisualIDRegistry::getLinkWithClassVisualIDMethodCall»(domainElement)) {
+ return null; // visual id for link EClass should match visual id from element type
+ }
+ return getEdgeViewClass(visualID);
+}
+
+«EXPAND xpt::Common::generatedMemberComment»
+protected Class getEdgeViewClass(int visualID) {
+ switch (visualID) {
+ «EXPAND caseEntry FOREACH links-»
+ }
+ return null;
+}
+«ENDDEFINE»
+
+«DEFINE getSemanticElementType FOR gmfgen::GenDiagram-»
+
+«EXPAND xpt::Common::generatedMemberComment»
+private org.eclipse.gmf.runtime.emf.type.core.IElementType getSemanticElementType(
+ org.eclipse.core.runtime.IAdaptable semanticAdapter) {
+ if (semanticAdapter == null) {
+ return null;
+ }
+ return (org.eclipse.gmf.runtime.emf.type.core.IElementType) semanticAdapter.getAdapter(
+ org.eclipse.gmf.runtime.emf.type.core.IElementType.class);
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/extensions.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/extensions.xpt
new file mode 100644
index 000000000..04f1a4165
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/extensions.xpt
@@ -0,0 +1,181 @@
+/*
+ * 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 API and implementation
+ */
+
+«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 xpt::diagram::Utils»
+
+«DEFINE extensions FOR gmfgen::GenDiagram-»
+
+ <extension point="org.eclipse.gmf.runtime.diagram.core.viewProviders" id="view-provider">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <viewProvider class="«getNotationViewProviderQualifiedClassName()»">
+ <Priority name="«notationViewProviderPriority»"/>
+ <context viewClass="org.eclipse.gmf.runtime.notation.Diagram" semanticHints="«editorGen.modelID»"/>
+ <context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="«FOREACH getAllNodes()->asSequence() /*XXX can further improve selection using containerViews attribute, however, when top-node is created, provider is activated and this xml is not consulted any longer (same applies to compartments)*/ AS n SEPARATOR ','»«n.visualID»«ENDFOREACH»"/>
+ <context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="«FOREACH links->asSequence() AS l SEPARATOR ','»«l.visualID»«ENDFOREACH»"/>
+ </viewProvider>
+ </extension>
+
+ <extension point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders" id="ep-provider">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <editpartProvider class="«getEditPartProviderQualifiedClassName()»">
+ <Priority name="«editPartProviderPriority»"/>
+ <object class="org.eclipse.gmf.runtime.notation.Node" id="generated-nodes">
+ <method name="getType()" value="«FOREACH getAllNodes()->asSequence() AS n SEPARATOR ','»«n.visualID»«ENDFOREACH»"/>
+ </object>
+ <object class="org.eclipse.gmf.runtime.notation.Edge" id="generated-links">
+ <method name="getType()" value="«FOREACH links->asSequence() AS l SEPARATOR ','»«l.visualID»«ENDFOREACH»"/>
+ </object>
+ <object class="org.eclipse.gmf.runtime.notation.Node" id="generated-labels">
+ <method name="getType()" value="«FOREACH getAllNodes().labels AS lb SEPARATOR ','»«lb.visualID»«ENDFOREACH»"/>
+ </object>
+ <object class="org.eclipse.gmf.runtime.notation.Node" id="generated-compartments">
+ <method name="getType()" value="«FOREACH compartments->asSequence() AS c SEPARATOR ','»«c.visualID»«ENDFOREACH»"/>
+ </object>
+ <context views="generated-nodes,generated-links,generated-labels,generated-compartments"/>
+ </editpartProvider>
+ </extension>
+
+ <extension point="org.eclipse.gmf.runtime.emf.ui.modelingAssistantProviders" id="modelassist-provider">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <modelingAssistantProvider class="«getModelingAssistantProviderQualifiedClassName()»">
+ <Priority name="«modelingAssistantProviderPriority»"/>
+«FOREACH topLevelNodes->asSequence() AS n-»
+ <object class="«n.getEditPartQualifiedClassName()»" id="«n.getUniqueIdentifier()»"/>
+«ENDFOREACH-»
+ <context elements="«FOREACH topLevelNodes->asSequence() AS n SEPARATOR ','»«n.getUniqueIdentifier()»«ENDFOREACH»"/>
+ </modelingAssistantProvider>
+ </extension>
+
+ <extension point="org.eclipse.gmf.runtime.common.ui.services.iconProviders" id="icon-provider">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <IconProvider class="«getIconProviderQualifiedClassName()»">
+ <Priority name="«iconProviderPriority»"/>
+ </IconProvider>
+ </extension>
+«IF editorGen.labelParsers <> null and editorGen.labelParsers.extensibleViaService»
+ <extension point="org.eclipse.gmf.runtime.common.ui.services.parserProviders" id="parser-provider">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <ParserProvider class="«editorGen.labelParsers.getQualifiedClassName()»">
+ <Priority name="«editorGen.labelParsers.providerPriority»"/>
+ </ParserProvider>
+ </extension>
+«ENDIF-»
+«IF generateShortcutIcon()»
+ <extension point="org.eclipse.gmf.runtime.diagram.ui.decoratorProviders" id="decorator-provider">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <decoratorProvider class="«getShortcutsDecoratorProviderQualifiedClassName()»">
+ <Priority name="«shortcutsDecoratorProviderPriority»"/>
+ <object class="org.eclipse.gmf.runtime.notation.Node(org.eclipse.gmf.runtime.notation)" id="generated-top-nodes">
+ <method name="getType()" value="«FOREACH topLevelNodes->asSequence() /*generated code supports shortcuts only to top-level nodes*/ AS n SEPARATOR ','»«n.visualID»«ENDFOREACH»"/>
+ </object>
+ <context decoratorTargets="generated-top-nodes"/>
+ </decoratorProvider>
+ </extension>
+«ENDIF-»
+
+ <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes" id="element-types">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+«FOREACH getElements(self) AS e-»
+«EXPAND elementTypeSafe FOR e.elementType-»
+«ENDFOREACH-»
+ </extension>
+
+ <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings" id="element-types-bindings">
+ «EXPAND xpt::Common::xmlGeneratedTag»
+ <clientContext id="«editorGen.plugin.iD».TypeContext">
+ <enablement>
+ <test
+ property="org.eclipse.gmf.runtime.emf.core.editingDomain"
+ value="«editingDomainID»"/>
+ </enablement>
+ </clientContext>
+ <binding context="«editorGen.plugin.iD».TypeContext">
+«FOREACH getElements(self) AS e-»
+ <elementType ref="«e.elementType.uniqueIdentifier»"/>
+«ENDFOREACH-»
+ <advice ref="org.eclipse.gmf.runtime.diagram.core.advice.notationDepdendents"/>
+ </binding>
+ </extension>
+«ENDDEFINE»
+
+«DEFINE elementTypeSafe FOR gmfgen::ElementType-»
+«IF not definedExternally-»
+«EXPAND elementType-»
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE elementType FOR gmfgen::ElementType»
+«ERROR 'Unknown element type: ' + self.repr()»
+«ENDDEFINE»
+
+«DEFINE elementType FOR gmfgen::MetamodelType-»
+ <metamodel nsURI="«getMetaClass().genPackage.ecorePackage.nsURI»">
+ <metamodelType
+ id="«uniqueIdentifier»"
+«IF null <> displayName-»
+ name="%metatype.name.«diagramElement.getUniqueIdentifier()»"
+«ENDIF-»
+ kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
+ eclass="«getMetaClass().ecoreClass.name»"
+ edithelper="«getEditHelperQualifiedClassName()»">
+ <param name="semanticHint" value="«diagramElement.visualID»"/>
+ </metamodelType>
+ </metamodel>
+«ENDDEFINE»
+
+«DEFINE elementType FOR gmfgen::SpecializationType-»
+«IF null = getMetamodelClass()-»
+«EXPAND specializationType-»
+«ELSE-»
+ <metamodel nsURI="«getMetamodelClass().genPackage.ecorePackage.nsURI»">
+«EXPAND specializationType-»
+ </metamodel>
+«ENDIF-»
+«ENDDEFINE»
+
+«DEFINE specializationType FOR gmfgen::SpecializationType-»
+ <specializationType
+ id="«uniqueIdentifier»"
+«IF null <> displayName-»
+ name="%metatype.name.«diagramElement.getUniqueIdentifier()»"
+«ENDIF-»
+ kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"«IF editHelperAdviceClassName <> null»
+ edithelperadvice="«getEditHelperAdviceQualifiedClassName()»"«ENDIF»>
+ <specializes id="«(if null = metamodelType then 'org.eclipse.gmf.runtime.emf.type.core.null' else metamodelType.uniqueIdentifier endif)»"/>
+ <param name="semanticHint" value="«diagramElement.visualID»"/>
+ </specializationType>
+«ENDDEFINE»
+
+«DEFINE elementType FOR gmfgen::NotationType-»
+ <specializationType
+ id="«uniqueIdentifier»"
+«IF null <> displayName-»
+ name="%metatype.name.«diagramElement.getUniqueIdentifier()»"
+«ENDIF-»
+ kind="org.eclipse.gmf.runtime.diagram.ui.util.INotationType">
+ <specializes id="org.eclipse.gmf.runtime.emf.type.core.null"/>
+ <param name="semanticHint" value="«diagramElement.visualID»"/>
+ </specializationType>
+«ENDDEFINE»
+
+«DEFINE i18n FOR gmfgen::GenDiagram-»
+
+# Providers
+«EXPAND internal_i18n FOREACH getElements(self).elementType»
+«ENDDEFINE»
+
+«DEFINE internal_i18n FOR gmfgen::ElementType-»
+«IF null <> displayName and not definedExternally»metatype.name.«diagramElement.getUniqueIdentifier()»=«displayName»«ENDIF»
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/i18n.qvto b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/i18n.qvto
new file mode 100644
index 000000000..020e3ceb7
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/providers/i18n.qvto
@@ -0,0 +1,15 @@
+modeltype genModel uses "http://www.eclipse.org/gmf/2008/GenModel";
+
+library i18n;
+
+helper i18nKeyForModelingAssistantProvider(diagram : genModel::GenDiagram) : String {
+ return diagram.modelingAssistantProviderClassName
+}
+
+helper titleKey(dialogKey : String) : String {
+ return dialogKey + 'Title'
+}
+
+helper messageKey(dialogKey : String) : String {
+ return dialogKey + 'Message'
+}

Back to the top