carbidecpp22devenv/plugins/org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/codegen.templates/xpt/diagram/updater/Utils.ext
changeset 422 033392511bf7
equal deleted inserted replaced
421:631a44165bcf 422:033392511bf7
       
     1 /*
       
     2  * Copyright (c) 2007 Borland Software Corporation
       
     3  * 
       
     4  * All rights reserved. This program and the accompanying materials
       
     5  * are made available under the terms of the Eclipse Public License v1.0
       
     6  * which accompanies this distribution, and is available at
       
     7  * http://www.eclipse.org/legal/epl-v10.html
       
     8  *
       
     9  * Contributors:
       
    10  *    Alexander Shatalin (Borland) - initial API and implementation
       
    11  */
       
    12 
       
    13 import "http://www.eclipse.org/gmf/2008/GenModel";
       
    14 import "http://www.eclipse.org/emf/2002/GenModel";
       
    15 import "http://www.eclipse.org/emf/2002/Ecore";
       
    16 extension xpt::diagram::editpolicies::LinkUtils;
       
    17 
       
    18 String getContainedLinksMethodNameSuffix() :
       
    19 	"Contained"
       
    20 ;
       
    21 
       
    22 String getIncomingLinksMethodNameSuffix() :
       
    23 	"Incoming"
       
    24 ;
       
    25 
       
    26 String getOutgoingLinksMethodNameSuffix() :
       
    27 	"Outgoing"
       
    28 ;
       
    29 
       
    30 cached List[gmfgen::GenLink] getContainedLinks(genmodel::GenClass metaClass, gmfgen::GenDiagram diagram) :
       
    31 	diagram.links.select(link | canBeContainer(link, metaClass))
       
    32 ;
       
    33 
       
    34 cached List[gmfgen::GenLink] getOutgoingLinks(genmodel::GenClass metaClass, gmfgen::GenDiagram diagram) :
       
    35 	diagram.links.select(link | canBeSource(link, metaClass))
       
    36 ;
       
    37 
       
    38 cached List[gmfgen::GenLink] getIncomingLinks(genmodel::GenClass metaClass, gmfgen::GenDiagram diagram) :
       
    39 	diagram.links.select(link | canBeTarget(link, metaClass))
       
    40 ;
       
    41 
       
    42 List[gmfgen::GenLink] getAllContainedLinks(gmfgen::GenDiagram diagram) :
       
    43 	diagram.links.select(link | !getAllSemanticElements(diagram).select(commonBase | canBeContainer(link, getMetaClass(commonBase))).isEmpty())
       
    44 ;
       
    45 
       
    46 List[gmfgen::GenLink] getAllIncomingLinks(gmfgen::GenDiagram diagram) :
       
    47 	diagram.links.select(link | !getAllSemanticDiagramElements(diagram).select(commonBase | canBeTarget(link, getMetaClass(commonBase))).isEmpty())
       
    48 ;
       
    49 
       
    50 List[gmfgen::GenLink] getAllOutgoingLinks(gmfgen::GenDiagram diagram) :
       
    51 	diagram.links.select(link | isOutgoingLink(link)).select(link | !getAllSemanticDiagramElements(diagram).select(commonBase | canBeSource(link, getMetaClass(commonBase))).isEmpty())
       
    52 ;
       
    53 
       
    54 private boolean isOutgoingLink(gmfgen::GenLink link) :
       
    55 	null != link.modelFacet && isOutgoingLink(link.modelFacet)
       
    56 ;
       
    57 
       
    58 private boolean isOutgoingLink(gmfgen::LinkModelFacet modelFacet) :
       
    59 	true
       
    60 ;
       
    61 
       
    62 private boolean isOutgoingLink(gmfgen::TypeLinkModelFacet modelFacet) :
       
    63 	null != modelFacet.sourceMetaFeature
       
    64 ;
       
    65 
       
    66 cached List[gmfgen::GenCommonBase] getAllSemanticDiagramElements(gmfgen::GenDiagram diagram) :
       
    67 	diagram.getAllNodes().toList().addAll(diagram.links).typeSelect(gmfgen::GenCommonBase).select(commonBase | null != getMetaClass(commonBase))
       
    68 ;
       
    69 
       
    70 cached List[gmfgen::GenCommonBase] getAllSemanticElements(gmfgen::GenDiagram diagram) :
       
    71 	null != diagram.domainDiagramElement 
       
    72 		? {diagram}.addAll(getAllSemanticDiagramElements(diagram)) 
       
    73 		: getAllSemanticDiagramElements(diagram)
       
    74 ;
       
    75 
       
    76 cached genmodel::GenClass getMetaClass(gmfgen::GenCommonBase commonBase) :
       
    77 	null
       
    78 ;
       
    79 
       
    80 cached genmodel::GenClass getMetaClass(gmfgen::GenDiagram diagram) :
       
    81 	diagram.domainDiagramElement
       
    82 ;
       
    83 
       
    84 cached genmodel::GenClass getMetaClass(gmfgen::GenNode node) :
       
    85 	node.modelFacet.metaClass
       
    86 ;
       
    87 
       
    88 cached genmodel::GenClass getMetaClass(gmfgen::GenLink link) :
       
    89 	null != link.modelFacet ? getMetaClass(link.modelFacet) : null
       
    90 ;
       
    91 
       
    92 private genmodel::GenClass getMetaClass(gmfgen::LinkModelFacet modelFacet) :
       
    93 	null
       
    94 ;
       
    95 
       
    96 private genmodel::GenClass getMetaClass(gmfgen::TypeLinkModelFacet modelFacet) :
       
    97 	modelFacet.metaClass
       
    98 ;
       
    99 
       
   100 boolean hasSemanticChildren(gmfgen::GenContainerBase container) :
       
   101 	!container.sansDomain && !container.containedNodes.isEmpty()
       
   102 ;
       
   103 
       
   104 genmodel::GenClass getModelElementType(gmfgen::GenContainerBase containerBase) :
       
   105 // Never should be here!
       
   106 	null
       
   107 ;
       
   108 
       
   109 genmodel::GenClass getModelElementType(gmfgen::GenDiagram diagram) :
       
   110 	diagram.domainDiagramElement
       
   111 ;
       
   112 
       
   113 genmodel::GenClass getModelElementType(gmfgen::GenCompartment compartment) :
       
   114 	getModelElementType(compartment.node)
       
   115 ;
       
   116 
       
   117 genmodel::GenClass getModelElementType(gmfgen::GenNode node) :
       
   118 	node.modelFacet.metaClass
       
   119 ;
       
   120 
       
   121 cached Set[genmodel::GenFeature] getSemanticChildrenChildFeatures(gmfgen::GenContainerBase containerBase) :
       
   122 	getNonPhantomSemanticChildren(containerBase).collect(node | node.modelFacet.childMetaFeature).toSet()
       
   123 ;
       
   124 
       
   125 cached Set[genmodel::GenFeature] getSemanticChildrenContainmentFeatures(gmfgen::GenContainerBase containerBase) :
       
   126 	getNonPhantomSemanticChildren(containerBase).collect(node | node.modelFacet.containmentMetaFeature).toSet()
       
   127 ;
       
   128 
       
   129 cached List[gmfgen::GenNode] getSemanticChildren(gmfgen::GenContainerBase containerBase, genmodel::GenFeature childMetaFeature) :
       
   130 	getNonPhantomSemanticChildren(containerBase).select(node | node.modelFacet.childMetaFeature == childMetaFeature)
       
   131 ;
       
   132 
       
   133 private cached List[gmfgen::GenNode] getNonPhantomSemanticChildren(gmfgen::GenContainerBase containerBase) :
       
   134 	getSemanticChildren(containerBase).select(node | !node.modelFacet.isPhantomElement())
       
   135 ;
       
   136 
       
   137 cached List[gmfgen::GenNode] getPhantomNodes(gmfgen::GenContainerBase containerBase) :
       
   138 	{}
       
   139 ;
       
   140 
       
   141 cached List[gmfgen::GenNode] getPhantomNodes(gmfgen::GenDiagram diagram) :
       
   142 	getSemanticChildren(diagram).select(node | node.modelFacet.isPhantomElement())
       
   143 ;
       
   144 
       
   145 cached List[gmfgen::GenNode] getSemanticChildren(gmfgen::GenContainerBase containerBase) :
       
   146 	containerBase.containedNodes.select(node | null != node.modelFacet)
       
   147 ;
       
   148 
       
   149 cached boolean hasConformableSemanticChildren(gmfgen::GenContainerBase containerBase) :
       
   150 	let childMetaClasses = getSemanticChildren(containerBase).collect(node | node.modelFacet.metaClass) :
       
   151 		!childMetaClasses.forAll(mc | childMetaClasses.select(mc2 | mc == mc2).size() == 1)
       
   152 ;
       
   153 
       
   154 GenClass getLinkEndType(gmfgen::LinkModelFacet f, String methodNameSuffix) :
       
   155 	null
       
   156 ;
       
   157 
       
   158 //	For FeatureModelFacet-based links we are calling 
       
   159 //	getOutgoing???Links instead of getContained???Links
       
   160 GenClass getLinkEndType(gmfgen::FeatureLinkModelFacet f, String methodNameSuffix) :
       
   161 	getIncomingLinksMethodNameSuffix() == methodNameSuffix
       
   162 		? f.getTargetType()
       
   163 		: f.getSourceType()
       
   164 ;
       
   165 
       
   166 // 	For TypeModelFacet-based links we are calling 
       
   167 //	getContained???Links instead of getOutgoinf???Links 
       
   168 //	if sourceMetaFeature was not specified
       
   169 GenClass getLinkEndType(gmfgen::TypeLinkModelFacet f, String methodNameSuffix) :
       
   170 	getIncomingLinksMethodNameSuffix() == methodNameSuffix
       
   171 		? f.getTargetType()
       
   172 		: (getOutgoingLinksMethodNameSuffix() == methodNameSuffix && null != f.sourceMetaFeature
       
   173 			? f.getSourceType()
       
   174 			: f.containmentMetaFeature.genClass
       
   175 		)
       
   176 ;