Skip to content

Commit

Permalink
[719] Add support for the 'container' and 'element' compatibility var…
Browse files Browse the repository at this point in the history
…iables

'container' is the (default) name for the variable used by Sirius
Desktop to refer to the semantic element on which a node or container
creation tool is invoked. See {Node,Container}CreationCommandBuilder
and ToolFactoryImpl.create{Node,Container}CreationDescription() in
Sirius Desktop.

'element' plays the same role for the generic tools. See
GenericToolCommandBuilder and ToolFactoryImpl.createToolDescription().

Bug: #719
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid committed Aug 31, 2021
1 parent b28b354 commit 98bb2a4
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public class ToolProvider implements IToolProvider {
*/
public static final String EDGE_TARGET = "target"; //$NON-NLS-1$

/**
* The name of the compatibility variable used to store and retrieve the semantic element on which a node or
* container creation tool has been invoked.
*/
public static final String CONTAINER = "container"; //$NON-NLS-1$

/**
* The name of the compatibility variable used to store and retrieve the semantic element on which a generic tool
* has been invoked.
*/
public static final String ELEMENT = "element"; //$NON-NLS-1$

private final IAQLInterpreterFactory interpreterFactory;

private final IIdentifierProvider identifierProvider;
Expand Down Expand Up @@ -321,7 +333,7 @@ private CreateEdgeTool convertEdgeCreationDescription(Map<UUID, NodeDescription>
return CreateEdgeTool.newCreateEdgeTool(id)
.label(label)
.imageURL(imagePath)
.handler(this.createEdgeCreationDescription(interpreter, edgeCreationDescription))
.handler(this.createEdgeCreationHandler(interpreter, edgeCreationDescription))
.edgeCandidates(edgeCandidates)
.build();
// @formatter:on
Expand All @@ -332,6 +344,8 @@ private Function<VariableManager, Status> createContainerCreationHandler(AQLInte
InitialNodeCreationOperation initialOperation = toolDescription.getInitialOperation();
return variableManager -> {
Map<String, Object> variables = variableManager.getVariables();
// Provide compatibility aliases for this variable
variables.put(CONTAINER, variables.get(VariableManager.SELF));
var selectModelelementVariableOpt = new SelectModelElementVariableProvider().getSelectModelElementVariable(toolDescription.getVariable());
if (selectModelelementVariableOpt.isPresent()) {
variables.put(selectModelelementVariableOpt.get().getName(), variables.get(CreateNodeTool.SELECTED_OBJECT));
Expand All @@ -351,6 +365,8 @@ private Function<VariableManager, Status> createNodeCreationHandler(AQLInterpret
InitialNodeCreationOperation initialOperation = toolDescription.getInitialOperation();
return variableManager -> {
Map<String, Object> variables = variableManager.getVariables();
// Provide compatibility aliases for this variable
variables.put(CONTAINER, variables.get(VariableManager.SELF));
var selectModelelementVariableOpt = new SelectModelElementVariableProvider().getSelectModelElementVariable(toolDescription.getVariable());
if (selectModelelementVariableOpt.isPresent()) {
variables.put(selectModelelementVariableOpt.get().getName(), variables.get(CreateNodeTool.SELECTED_OBJECT));
Expand All @@ -370,6 +386,8 @@ private Function<VariableManager, Status> createGenericToolHandler(AQLInterprete
InitialOperation initialOperation = toolDescription.getInitialOperation();
return variableManager -> {
Map<String, Object> variables = variableManager.getVariables();
// Provide compatibility aliases for this variable
variables.put(ELEMENT, variables.get(VariableManager.SELF));
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(interpreter);
return modelOperationHandlerSwitch.apply(initialOperation.getFirstModelOperations()).map(handler -> {
return handler.handle(variables);
Expand All @@ -380,7 +398,7 @@ private Function<VariableManager, Status> createGenericToolHandler(AQLInterprete
}
}

private Function<VariableManager, Status> createEdgeCreationDescription(AQLInterpreter interpreter, EdgeCreationDescription edgeCreationDescription) {
private Function<VariableManager, Status> createEdgeCreationHandler(AQLInterpreter interpreter, EdgeCreationDescription edgeCreationDescription) {
if (edgeCreationDescription != null) {
InitEdgeCreationOperation initialOperation = edgeCreationDescription.getInitialOperation();
return variableManager -> {
Expand Down

0 comments on commit 98bb2a4

Please sign in to comment.