diff options
| author | cbrun | 2015-04-29 09:23:46 +0000 |
|---|---|---|
| committer | Cedric Brun | 2015-05-07 08:07:56 +0000 |
| commit | 95512ea160b7a31b2a30ef957acc1518787dba00 (patch) | |
| tree | 7a15b2bca1faaf96e0ed2daca88642743ed80185 | |
| parent | e1da23c440a4b575c677774c3408038ae9281d42 (diff) | |
| download | org.eclipse.sirius-95512ea160b7a31b2a30ef957acc1518787dba00.tar.gz org.eclipse.sirius-95512ea160b7a31b2a30ef957acc1518787dba00.tar.xz org.eclipse.sirius-95512ea160b7a31b2a30ef957acc1518787dba00.zip | |
[465954] : Analyse types of variables for Create/Delete|Line/Column
Tools
Bug: 465954
Change-Id: I6638b984a9b03103b660d9dd037c58008233d12d
Signed-off-by: Cedric Brun <cedric.brun@obeo.fr>
2 files changed, 224 insertions, 3 deletions
diff --git a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java index 36be466aec..b79d632e66 100644 --- a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java +++ b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/description/TableInterpretedExpressionQuery.java @@ -12,6 +12,7 @@ package org.eclipse.sirius.table.business.internal.dialect.description; import java.util.Collection; import java.util.Map; +import java.util.Set; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; @@ -27,12 +28,17 @@ import org.eclipse.sirius.ext.base.Options; import org.eclipse.sirius.table.metamodel.table.TablePackage; import org.eclipse.sirius.table.metamodel.table.description.ColumnMapping; import org.eclipse.sirius.table.metamodel.table.description.CreateCellTool; +import org.eclipse.sirius.table.metamodel.table.description.CreateColumnTool; +import org.eclipse.sirius.table.metamodel.table.description.CreateLineTool; +import org.eclipse.sirius.table.metamodel.table.description.DeleteColumnTool; +import org.eclipse.sirius.table.metamodel.table.description.DeleteLineTool; import org.eclipse.sirius.table.metamodel.table.description.DescriptionPackage; import org.eclipse.sirius.table.metamodel.table.description.ElementColumnMapping; import org.eclipse.sirius.table.metamodel.table.description.FeatureColumnMapping; import org.eclipse.sirius.table.metamodel.table.description.IntersectionMapping; import org.eclipse.sirius.table.metamodel.table.description.LabelEditTool; import org.eclipse.sirius.table.metamodel.table.description.LineMapping; +import org.eclipse.sirius.table.metamodel.table.description.TableDescription; import org.eclipse.sirius.table.tools.api.interpreter.IInterpreterSiriusTableVariables; import org.eclipse.sirius.viewpoint.description.tool.AbstractVariable; import org.eclipse.sirius.viewpoint.description.tool.EditMaskVariables; @@ -114,12 +120,94 @@ public class TableInterpretedExpressionQuery extends AbstractInterpretedExpressi IntersectionMapping interMapping = (IntersectionMapping) tool.eContainer(); declareLineAndColumnSemantic(availableVariables, interMapping); } + } else if (operationContext instanceof CreateLineTool) { + CreateLineTool tool = (CreateLineTool) operationContext; + + Set<String> possibleTypes = collectTypes(tool.eContainer()); + + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.CONTAINER, possibleTypes); + + declareRootTableType(availableVariables, operationContext); + + } else if (operationContext instanceof CreateColumnTool) { + + CreateColumnTool tool = (CreateColumnTool) operationContext; + Set<String> possibleTypes = collectTypes(tool.eContainer()); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.CONTAINER, possibleTypes); + declareRootTableType(availableVariables, operationContext); + + } else if (operationContext instanceof DeleteLineTool) { + DeleteLineTool tool = (DeleteLineTool) operationContext; + LineMapping mapping = tool.getMapping(); + String domainClass = mapping.getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + availableVariables.put(IInterpreterSiriusTableVariables.ELEMENT, VariableType.fromString(domainClass)); + } + declareRootTableType(availableVariables, operationContext); + + } else if (operationContext instanceof DeleteColumnTool) { + DeleteColumnTool tool = (DeleteColumnTool) operationContext; + ColumnMapping mapping = tool.getMapping(); + Set<String> possibleTypes = collectTypes(mapping); + refineVariableType(availableVariables, IInterpreterSiriusTableVariables.ELEMENT, possibleTypes); + declareRootTableType(availableVariables, operationContext); } } return availableVariables; } + private void refineVariableType(Map<String, VariableType> availableVariables, String variableName, Collection<String> foundTypes) { + if (foundTypes.size() > 0) { + availableVariables.put(variableName, VariableType.fromStrings(foundTypes)); + } + } + + private Set<String> collectTypes(EObject container) { + Set<String> possibleTypes = Sets.newLinkedHashSet(); + if (container instanceof TableDescription) { + String domainClass = ((TableDescription) container).getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + possibleTypes.add(domainClass); + } + } else if (container instanceof LineMapping) { + String domainClass = ((LineMapping) container).getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + possibleTypes.add(domainClass); + } + } else if (container instanceof ElementColumnMapping) { + String domainClass = ((ElementColumnMapping) container).getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + possibleTypes.add(domainClass); + } + } else if (container instanceof FeatureColumnMapping) { + Option<EObject> tableDef = new EObjectQuery(container).getFirstAncestorOfType(DescriptionPackage.Literals.TABLE_DESCRIPTION); + if (tableDef.some() && tableDef.get() instanceof TableDescription) { + TableDescription table = (TableDescription) tableDef.get(); + for (LineMapping lMapping : table.getAllLineMappings()) { + String domainClass = lMapping.getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + possibleTypes.add(domainClass); + } + } + } + } + return possibleTypes; + } + + private void declareRootTableType(Map<String, VariableType> availableVariables, EObject operationContext) { + Option<EObject> tableDef = new EObjectQuery(operationContext).getFirstAncestorOfType(DescriptionPackage.Literals.TABLE_DESCRIPTION); + if (tableDef.some() && tableDef.get() instanceof TableDescription) { + TableDescription table = (TableDescription) tableDef.get(); + String domainClass = table.getDomainClass(); + if (!StringUtil.isEmpty(domainClass)) { + availableVariables.put(IInterpreterSiriusTableVariables.ROOT, VariableType.fromString(domainClass)); + } + } + } + private void declareLineAndColumnSemantic(Map<String, VariableType> availableVariables, IntersectionMapping interMapping) { ColumnMapping cMapping = interMapping.getColumnMapping(); Collection<String> possibleLineTypes = Sets.newLinkedHashSet(); diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign index 718dcd1572..c1b4ed03f3 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/vsm/validateVariableTypes.odesign @@ -76,7 +76,7 @@ <edgeMappings name="Dupplicate ParticipantNode to InteractionNode through Message" sourceMapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='SelfTypeInference']/@defaultLayer/@nodeMappings[name='ParticipantNode']" targetMapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='SelfTypeInference']/@defaultLayer/@nodeMappings[name='InteractionNode']" targetFinderExpression="feature:nonExistent" sourceFinderExpression="feature:nonExistent" domainClass="interactions.Message" useDomainElement="true"> <style sizeComputationExpression="2"> <strokeColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='gray']"/> - <centerLabelStyleDescription> + <centerLabelStyleDescription labelExpression="feature:sendingEnd"> <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> </centerLabelStyleDescription> </style> @@ -89,6 +89,14 @@ </centerLabelStyleDescription> </style> </edgeMappings> + <edgeMappings name="RelationBasedEdge Interaction Container to Interaction Node" sourceMapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='SelfTypeInference']/@defaultLayer/@containerMappings[name='InteractionContainer']" targetMapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='SelfTypeInference']/@defaultLayer/@nodeMappings[name='InteractionNode']" targetFinderExpression="var:"> + <style sizeComputationExpression="2"> + <strokeColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='gray']"/> + <centerLabelStyleDescription> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + </centerLabelStyleDescription> + </style> + </edgeMappings> <containerMappings name="ParticipantContainer" deletionDescription="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='SelfTypeInference']/@defaultLayer/@toolSections.0/@ownedTools[name='Delete%20ParticipantContainer']" labelDirectEdit="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='SelfTypeInference']/@defaultLayer/@toolSections.0/@subSections[name='Ignored']/@ownedTools[name='ElementType']" domainClass="interactions.Participant"> <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1"> <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> @@ -435,8 +443,95 @@ </defaultLayer> </ownedRepresentations> <ownedRepresentations xsi:type="description_2:CrossTableDescription" name="XTable" domainClass="interactions.Model"> - <ownedLineMappings name="Message Line" domainClass="interactions.Message"/> - <ownedColumnMappings name="Participant Column" domainClass="interactions.Participant"/> + <metamodel href="http://www.eclipse.org/sirius/sample/interactions#/"/> + <metamodel href="http://www.eclipse.org/emf/2002/Ecore#/"/> + <ownedLineMappings name="Message Line" domainClass="interactions.Message" headerLabelExpression="feature:sendingEnd"> + <foregroundConditionalStyle predicateExpression="feature:sendingEnd"> + <style> + <foreGroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + </style> + </foregroundConditionalStyle> + <foregroundConditionalStyle predicateExpression="feature:nonExistent"> + <style> + <foreGroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + </style> + </foregroundConditionalStyle> + <backgroundConditionalStyle predicateExpression="feature:sendingEnd"> + <style> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + </style> + </backgroundConditionalStyle> + <backgroundConditionalStyle predicateExpression="feature:nonExistent"> + <style> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + </style> + </backgroundConditionalStyle> + <ownedSubLines name="MessageEnd subline" domainClass="interactions.MessageEnd" semanticCandidatesExpression="feature:sendingEnd" headerLabelExpression="feature:context"/> + <create name="Create MessageEnd" mapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='XTable']/@ownedLineMappings[name='Message%20Line']/@ownedSubLines[name='MessageEnd%20subline']"> + <variables name="root" documentation="The semantic element of the table."/> + <variables name="element" documentation="The semantic currently edited element."/> + <variables name="container" documentation="The semantic element corresponding to the view container."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:sendingEnd"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:sendingEnd"/> + </subModelOperations> + </firstModelOperation> + </create> + <delete name="Delete Message"> + <variables name="element" documentation="The currently edited element."/> + <variables name="root" documentation="The semantic element corresponding to the current table."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:sendingEnd"/> + </subModelOperations> + </firstModelOperation> + </delete> + </ownedLineMappings> + <ownedColumnMappings name="Participant Column" headerLabelExpression="feature:type" domainClass="interactions.Participant"> + <defaultForeground> + <foreGroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + </defaultForeground> + <defaultBackground> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + </defaultBackground> + <create name="Create Participant"> + <variables name="root" documentation="The semantic element of the table."/> + <variables name="element" documentation="The semantic currently edited element."/> + <variables name="container" documentation="The semantic element corresponding to the view container."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:type"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:type"/> + </subModelOperations> + </firstModelOperation> + </create> + <delete name="Delete Participant"> + <variables name="element" documentation="The currently edited element."/> + <variables name="root" documentation="The semantic element corresponding to the current table."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:type"/> + </subModelOperations> + </firstModelOperation> + </delete> + </ownedColumnMappings> <intersection name="Intersection Message Participant" lineMapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='XTable']/@ownedLineMappings[name='Message%20Line']" columnMapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='XTable']/@ownedColumnMappings.0" labelExpression="X" columnFinderExpression="aql:self.sendingEnd.context"> <directEdit> <variables name="element" documentation="The currently edited element."/> @@ -469,5 +564,43 @@ </create> </intersection> </ownedRepresentations> + <ownedRepresentations xsi:type="description_2:EditionTableDescription" name="EditionTable" domainClass="interactions.Model"> + <ownedLineMappings name="Participants" domainClass="interactions.Participant"> + <ownedSubLines name="Message Subline" domainClass="interactions.Message"/> + <create name="create message" mapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='EditionTable']/@ownedLineMappings[name='Participants']/@ownedSubLines[name='Message%20Subline']"> + <variables name="root" documentation="The semantic element of the table."/> + <variables name="element" documentation="The semantic currently edited element."/> + <variables name="container" documentation="The semantic element corresponding to the view container."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:type"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:type"/> + </subModelOperations> + </firstModelOperation> + </create> + </ownedLineMappings> + <ownedCreateLine name="Create new Participant" mapping="//@ownedViewpoints[name='VSMTypes']/@ownedRepresentations[name='EditionTable']/@ownedLineMappings[name='Participants']"> + <variables name="root" documentation="The semantic element of the table."/> + <variables name="element" documentation="The semantic currently edited element."/> + <variables name="container" documentation="The semantic element corresponding to the view container."/> + <firstModelOperation xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:root"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:element"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="var:container"> + <subModelOperations xsi:type="tool:ChangeContext" browseExpression="feature:ownedInteractions"/> + </subModelOperations> + </firstModelOperation> + </ownedCreateLine> + <ownedColumnMappings name="name" featureName="name" labelExpression="feature:name"/> + </ownedRepresentations> </ownedViewpoints> </description:Group> |
