| author | skovalsky | 2012-02-20 12:46:14 (EST) |
|---|---|---|
| committer | mgolubev | 2012-04-29 13:39:32 (EDT) |
| commit | 56db6b640a4088bdbd5dcba1e7b3229978036bd3 (patch) (side-by-side diff) | |
| tree | 1c0edc692c00f599d9cbc009af57a5947cd28244 | |
| parent | 6ae738ededecb90eedd0bd10c05c76d54382bb36 (diff) | |
| download | org.eclipse.gmf-tooling-56db6b640a4088bdbd5dcba1e7b3229978036bd3.zip org.eclipse.gmf-tooling-56db6b640a4088bdbd5dcba1e7b3229978036bd3.tar.gz org.eclipse.gmf-tooling-56db6b640a4088bdbd5dcba1e7b3229978036bd3.tar.bz2 | |
Allow VisualEffectMappings's for LinkMappings - bridge and templates
3 files changed, 121 insertions, 21 deletions
diff --git a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/DiagramGenModelTransformer.java b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/DiagramGenModelTransformer.java index 385edc2..f9d0498 100644 --- a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/DiagramGenModelTransformer.java +++ b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/DiagramGenModelTransformer.java @@ -598,8 +598,12 @@ public class DiagramGenModelTransformer extends MappingTransformer { genNode.getBehaviour().add(openDiagramPolicy); } + createVisualEffects(mapping, genNode, mapping.getDiagramNode()); + } + + private void createVisualEffects(MappingEntry mapping, GenCommonBase genCommon, DiagramElement diagramElement) { for (VisualEffectMapping visualEffectMapping : mapping.getVisualEffects()) { - createVisualEffect(genNode, visualEffectMapping); + createVisualEffect(genCommon, visualEffectMapping, diagramElement); } } @@ -643,6 +647,8 @@ public class DiagramGenModelTransformer extends MappingTransformer { if (!rcp) { myNavigatorProcessor.process(gl); } + + createVisualEffects(lme, gl, lme.getDiagramLink()); } @Override @@ -674,11 +680,11 @@ public class DiagramGenModelTransformer extends MappingTransformer { return label; } - private void createVisualEffect(GenNode node, VisualEffectMapping mapping) { + private void createVisualEffect(GenCommonBase parent, VisualEffectMapping mapping, DiagramElement parentDiagramElement) { addOclToolingPlugin(); - + GenVisualEffect visualEffect = GMFGenFactory.eINSTANCE.createGenVisualEffect(); - node.getBehaviour().add(visualEffect); + parent.getBehaviour().add(visualEffect); Pin graphPin = mapping.getDiagramPin(); @@ -689,7 +695,7 @@ public class DiagramGenModelTransformer extends MappingTransformer { String operationName = graphPin.getOperationName(); - FigureDescriptor graphFigureDescriptor = mapping.getParentNode().getDiagramNode().getFigure(); + FigureDescriptor graphFigureDescriptor = parentDiagramElement.getFigure(); if (!hasFigurePin(graphFigureDescriptor.getActualFigure(), graphPin)) { for (ChildAccess graphChildAccess : graphFigureDescriptor.getAccessors()) { @@ -704,8 +710,8 @@ public class DiagramGenModelTransformer extends MappingTransformer { visualEffect.setOperationType(graphPin.getOperationType()); visualEffect.setOclExpression(mapping.getOclExpression()); - String editPolicyQualifiedClassName = node.getDiagram().getEditPoliciesPackageName() + '.'// - + CodeGenUtil.capName(CodeGenUtil.validJavaIdentifier(name)) + node.getVisualID() // + String editPolicyQualifiedClassName = parent.getDiagram().getEditPoliciesPackageName() + '.'// + + CodeGenUtil.capName(CodeGenUtil.validJavaIdentifier(name)) + parent.getVisualID() // + "Policy"; visualEffect.setEditPolicyQualifiedClassName(editPolicyQualifiedClassName); @@ -718,9 +724,9 @@ public class DiagramGenModelTransformer extends MappingTransformer { : (RealFigure) figure; return realFigure.getPins().contains(pin); } - + private void addOclToolingPlugin() { - final String pluginId = "org.eclipse.gmf.tooling.runtime.ocl.expressions"; + final String pluginId = "org.eclipse.gmf.tooling.runtime.ocl"; EList<String> reguiredPlugins = getGenEssence().getPlugin().getRequiredPlugins(); if (!reguiredPlugins.contains(pluginId)) { reguiredPlugins.add(pluginId); @@ -1083,7 +1089,7 @@ public class DiagramGenModelTransformer extends MappingTransformer { // XXX perhaps, combining #createValueExpression and #createGenConstraint into a single method makes sense? private ValueExpression createValueExpression(org.eclipse.gmf.mappings.ValueExpression valueExpression) { addOclToolingPlugin(); - + if (valueExpression instanceof Constraint) { return createGenConstraint((Constraint) valueExpression); } diff --git a/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java b/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java index 4dfa4a0..c7263ae 100644 --- a/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java +++ b/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java @@ -124,6 +124,7 @@ public class Generator extends GeneratorBase implements Runnable { for (GenLinkLabel label : next.getLabels()) { generateLinkLabelEditPart(label); } + generateVisualEffectEditPolicies(next); } generateDiagram(); // @@ -280,7 +281,11 @@ public class Generator extends GeneratorBase implements Runnable { generateNodeLabelEditPart(label); } } - for (Behaviour behaviour : node.getBehaviour()) { + generateVisualEffectEditPolicies(node); + } + + private void generateVisualEffectEditPolicies(GenCommonBase commonBase) throws InterruptedException { + for (Behaviour behaviour : commonBase.getBehaviour()) { if (behaviour instanceof GenVisualEffect) { GenVisualEffect visualEffect = (GenVisualEffect) behaviour; generateVisualEffectEditPolicy(visualEffect); diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/VisualEffectEditPolicy.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/VisualEffectEditPolicy.xpt index c3eb115..dad7df8 100644 --- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/VisualEffectEditPolicy.xpt +++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/VisualEffectEditPolicy.xpt @@ -1,8 +1,9 @@ «IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
-«IMPORT 'http://www.eclipse.org/ocl/1.1.0/Ecore'»
«EXTENSION xpt::diagram::Utils»
+«EXTENSION xpt::GenModelUtils»
«DEFINE VisualEffectEditPolicy FOR gmfgen::GenVisualEffect-»
«EXPAND xpt::Common::copyright FOR subject.getDiagram().editorGen-»
@@ -36,6 +37,8 @@ public class «EXPAND xpt::Common::disqualifiedClassName FOR getEditPolicyQualif «EXPAND getHostImpl-»
«EXPAND getExpressionBody-»
+
+ «EXPAND getContext-»
«ENDDEFINE»
«DEFINE setVisualEffectValue FOR gmfgen::GenVisualEffect-»
@@ -65,11 +68,43 @@ public class «EXPAND xpt::Common::disqualifiedClassName FOR getEditPolicyQualif «DEFINE getExpressionBody FOR gmfgen::GenVisualEffect-»
«EXPAND xpt::Common::generatedMemberComment»
@Override
- protected String getExpressionBody() {
- return «getOclExpressionString()»; «EXPAND xpt::Common::nonNLS»
+ protected String getExpressionBody() {
+ return
+ «IF subject.oclIsKindOf(gmfgen::GenLink)-»
+ «EXPAND expressionLinkEnds FOR subject.oclAsType(gmfgen::GenLink).modelFacet-»
+ «ENDIF-»
+ «getOclExpressionString()»; «EXPAND xpt::Common::nonNLS»
}
«ENDDEFINE»
+«DEFINE expressionLinkEnds FOR gmfgen::LinkModelFacet»«ENDDEFINE»
+
+«DEFINE expressionLinkEnds FOR gmfgen::FeatureLinkModelFacet-»
+ «IF metaFeature.ecoreFeature.upperBound = 1-»
+ «EXPAND expressionLinkEnds('', '.'+metaFeature.ecoreFeature.name)-»
+ «ELSE-»
+ «LET getReverse(metaFeature) AS reverseMetaFeature-»
+ «IF reverseMetaFeature <> null-»
+ «EXPAND expressionLinkEnds('.'+reverseMetaFeature.ecoreFeature.name, '')-»
+ «ELSEIF metaFeature.ecoreFeature.oclAsType(ecore::EReference).containment-»
+ «EXPAND expressionLinkEnds('.oclAsType(ecore::EObject).eContainer().oclAsType('+getSourceType().ecoreClass.name+')', '')-»
+ «ELSE-»
+ /* unable to set up both link ends */
+ «ENDIF-»
+ «ENDLET-»
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE expressionLinkEnds FOR gmfgen::TypeLinkModelFacet-»
+ «EXPAND expressionLinkEnds('.'+sourceMetaFeature.ecoreFeature.name, '.'+targetMetaFeature.ecoreFeature.name)-»
+«ENDDEFINE»
+
+«DEFINE expressionLinkEnds(sourcePath : String, targetPath : String) FOR gmfgen::LinkModelFacet-»
+ " let _src : «getSourceType().ecoreClass.name» = self«sourcePath» in " //
+ + " let _dst : «getTargetType().ecoreClass.name» = self«targetPath» in " //
+ +
+«ENDDEFINE»
+
«DEFINE callOperation FOR gmfgen::GenVisualEffect-»
getHostImpl().getPrimaryShape().«operationName-»
«ENDDEFINE»
@@ -82,13 +117,6 @@ getHostImpl().getPrimaryShape().«operationName-» «ENDLET-»
«ENDDEFINE»
-«REM»
-«DEFINE setVisualEffectValueOnVisiblePin FOR gmfgen::GenVisualEffect-»
- «EXPAND setVisualEffectValueOfType(self) FOR getOperationRuntimeType()»
- «EXPAND callOperation»((Boolean)value);
-«ENDDEFINE»
-«ENDREM»
-
«DEFINE setVisualEffectValueOnCustomPin FOR gmfgen::GenVisualEffect-»
«EXPAND setVisualEffectValueOfType(self) FOR getOperationRuntimeType()»
«ENDDEFINE»
@@ -122,3 +150,64 @@ getHostImpl().getPrimaryShape().«operationName-» «ENDFOREACH-»
«ENDDEFINE»
+«DEFINE getContext FOR gmfgen::GenVisualEffect-»
+ «IF subject.oclIsKindOf(gmfgen::GenLink)-»
+ «EXPAND getContext FOR subject.oclAsType(gmfgen::GenLink).modelFacet-»
+ «ENDIF-»
+«ENDDEFINE»
+
+«DEFINE getContext FOR gmfgen::LinkModelFacet»«ENDDEFINE»
+
+«DEFINE getContext FOR gmfgen::FeatureLinkModelFacet-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ @Override
+ protected org.eclipse.emf.ecore.EObject getContext() {
+ «IF metaFeature.ecoreFeature.upperBound = 1-»
+ «EXPAND getContextBody('source', 'target', getSourceType(), getTargetType(), metaFeature)-»
+ «ELSE-»
+ «LET getReverse(metaFeature) AS reverseMetaFeature-»
+ «IF reverseMetaFeature <> null or metaFeature.ecoreFeature.oclAsType(ecore::EReference).containment-»
+ «EXPAND getContextBody('target', 'source', getTargetType(), getSourceType(), reverseMetaFeature)-»
+ «ELSE-»
+ // unable to pass both link ends
+ return null;
+ «ENDIF-»
+ «ENDLET-»
+ «ENDIF-»
+ }
+«ENDDEFINE»
+
+
+«DEFINE getContextBody(selfName : String,
+ oppositeName : String,
+ selfType : genmodel::GenClass,
+ oppositeType : genmodel::GenClass,
+ selfFeature : genmodel::GenFeature) FOR gmfgen::FeatureLinkModelFacet-»
+ org.eclipse.gmf.runtime.notation.Edge hostModel = (org.eclipse.gmf.runtime.notation.Edge) host().getModel();
+ org.eclipse.gmf.runtime.notation.View targetModel = hostModel.getTarget();
+ org.eclipse.gmf.runtime.notation.View sourceModel = hostModel.getSource();
+
+ if (targetModel == null || sourceModel == null) {
+ return null;
+ }
+
+ org.eclipse.emf.ecore.EObject «selfName»SemanticModel = org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.resolveSemanticElement(«selfName»Model);
+ // need to check actual opposite of the semantic element, since diagram opposite could be not up to date
+ «REM»(selfFeature = null) if link is multiplicity containment without opposite«ENDREM-»
+ «IF selfFeature <> null-»
+ «EXPAND MetaModel::QualifiedClassName FOR selfType» «selfName»TypedModel = «EXPAND MetaModel::CastEObject(selfName + 'SemanticModel') FOR selfType»;
+ «ENDIF-»
+ org.eclipse.emf.ecore.EObject «oppositeName»SemanticModel =
+ «IF selfFeature <> null-»
+ «EXPAND MetaModel::getFeatureValue(selfName + 'TypedModel', oppositeType) FOR selfFeature»
+ «ELSE-»
+ «selfName»SemanticModel.eContainer()
+ «ENDIF-»
+ ;
+
+ if («oppositeName»SemanticModel == null) {
+ return null;
+ }
+
+ return «selfName»SemanticModel;
+«ENDDEFINE»
\ No newline at end of file |

