use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.
the class NavigationOperationHandlerTests method testMultipleChildModelOperationWithSelection.
@Test
public void testMultipleChildModelOperationWithSelection() {
DiagramDescription firstDiagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
firstDiagramDescription.setLabel(FIRST_DIAGRAM_DESCRIPTION_ID.toString());
Navigation firstNavigation = ToolFactory.eINSTANCE.createNavigation();
firstNavigation.setCreateIfNotExistent(false);
firstNavigation.setDiagramDescription(firstDiagramDescription);
DiagramDescription secondDiagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
secondDiagramDescription.setLabel(SECOND_DIAGRAM_DESCRIPTION_ID.toString());
Navigation secondNavigation = ToolFactory.eINSTANCE.createNavigation();
secondNavigation.setCreateIfNotExistent(false);
secondNavigation.setDiagramDescription(secondDiagramDescription);
IStatus status = new ChildModelOperationHandler(List.of()).handle(new IObjectService.NoOp(), this.representationMetadataSearchService, this.diagramDescriptionIdentifierProvider, new AQLInterpreter(List.of(), List.of()), Map.of(IEditingContext.EDITING_CONTEXT, new IEditingContext.NoOp()), List.of(firstNavigation, secondNavigation));
assertThat(status).isInstanceOf(Success.class);
Success success = (Success) status;
Object selectionParameter = success.getParameters().get(Success.NEW_SELECTION);
assertThat(selectionParameter).isInstanceOf(WorkbenchSelection.class);
WorkbenchSelection selection = (WorkbenchSelection) selectionParameter;
// @formatter:off
assertThat(selection).isEqualTo(new WorkbenchSelection(List.of(new WorkbenchSelectionEntry(FIRST_DIAGRAM_ID, FIRST_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(SECOND_DIAGRAM_ID, SECOND_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(THIRD_DIAGRAM_ID, THIRD_DIAGRAM_LABEL, Diagram.KIND))));
// @formatter:on
}
use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.
the class ToolProvider method getToolSections.
@Override
public List<ToolSection> getToolSections(Map<UUID, NodeDescription> id2NodeDescriptions, List<EdgeDescription> edgeDescriptions, DiagramDescription siriusDiagramDescription, List<Layer> layers) {
List<ToolSection> result = new ArrayList<>();
// @formatter:off
var siriusToolSections = layers.stream().flatMap(layer -> layer.getToolSections().stream()).filter(org.eclipse.sirius.diagram.description.tool.ToolSection.class::isInstance).map(org.eclipse.sirius.diagram.description.tool.ToolSection.class::cast).collect(Collectors.toList());
// @formatter:on
AQLInterpreter interpreter = this.interpreterFactory.create(siriusDiagramDescription);
for (var siriusToolSection : siriusToolSections) {
// @formatter:off
List<ITool> tools = this.getToolDescriptions(siriusToolSection).stream().filter(this::isSupported).map(toolDescription -> this.convertTool(id2NodeDescriptions, siriusDiagramDescription, toolDescription, interpreter)).flatMap(Optional::stream).collect(Collectors.toList());
// @formatter:on
if (!tools.isEmpty()) {
ToolSection toolSection = this.convertToolSection(siriusToolSection, tools);
result.add(toolSection);
}
}
return result;
}
use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.
the class NavigationOperationHandler method handle.
@Override
public IStatus handle(Map<String, Object> variables) {
Success success = new Success();
Object editingContextVariable = variables.get(IEditingContext.EDITING_CONTEXT);
boolean createIfNotExistent = this.navigation.isCreateIfNotExistent();
if (!createIfNotExistent && editingContextVariable instanceof IEditingContext) {
IEditingContext editingContext = (IEditingContext) editingContextVariable;
DiagramDescription diagramDescription = this.navigation.getDiagramDescription();
String diagramDescriptionIdString = this.identifierProvider.getIdentifier(diagramDescription);
UUID diagramDescriptionId = UUID.fromString(diagramDescriptionIdString);
Object self = variables.get(VariableManager.SELF);
String selfId = this.objectService.getId(self);
// @formatter:off
List<WorkbenchSelectionEntry> entries = this.representationMetadataSearchService.findAllByTargetObjectId(editingContext, selfId).stream().filter(representationMetadata -> representationMetadata.getDescriptionId().equals(diagramDescriptionId)).map(representationMetadata -> {
String id = representationMetadata.getId();
String label = representationMetadata.getLabel();
String kind = representationMetadata.getKind();
return new WorkbenchSelectionEntry(id, label, kind);
}).collect(Collectors.toList());
// @formatter:on
if (!entries.isEmpty()) {
WorkbenchSelection newSelection = new WorkbenchSelection(entries);
success.getParameters().put(Success.NEW_SELECTION, newSelection);
}
}
return success;
}
use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.
the class DiagramDescriptionNodeAndEdgeDescriptionsPopulator method getDropHandler.
private Function<VariableManager, IStatus> getDropHandler(DiagramDescription siriusDiagramDescription, AQLInterpreter interpreter) {
// @formatter:off
List<ContainerDropDescription> diagramDropTools = siriusDiagramDescription.getAllTools().stream().filter(ContainerDropDescription.class::isInstance).map(ContainerDropDescription.class::cast).collect(Collectors.toList());
// @formatter:on
ToolConverter toolConverter = new ToolConverter(interpreter, this.editService, this.modelOperationHandlerSwitchProvider);
return variableManager -> {
Optional<EObject> optionalSelf = variableManager.get(VariableManager.SELF, EObject.class);
Optional<IEditingContext> optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
Optional<Diagram> optionalDiagram = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class).map(IDiagramContext::getDiagram);
Optional<Node> optionalSelectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
if (optionalSelf.isPresent() && optionalEditingContext.isPresent()) {
EObject self = optionalSelf.get();
IEditingContext editingContext = optionalEditingContext.get();
VariableManager childVariableManager = variableManager.createChild();
Optional<Object> newViewContainer = optionalSelectedNode.map(Object.class::cast).or(() -> optionalDiagram);
// @formatter:off
Optional<Object> newContainer = optionalSelectedNode.map(Node::getTargetObjectId).or(() -> optionalDiagram.map(Diagram::getTargetObjectId)).flatMap(targetObjectId -> this.objectService.getObject(editingContext, targetObjectId));
if (newContainer.isPresent() && newViewContainer.isPresent()) {
childVariableManager.put(NEW_CONTAINER, newContainer.get());
childVariableManager.put(NEW_VIEW_CONTAINER, newViewContainer.get());
childVariableManager.put(ToolProvider.ELEMENT, self);
Collection<ContainerDropDescription> candidates = new ArrayList<>();
for (ContainerDropDescription dropTool : diagramDropTools) {
String precondition = dropTool.getPrecondition();
if (precondition != null && !precondition.trim().isBlank()) {
boolean result = interpreter.evaluateExpression(childVariableManager.getVariables(), precondition).asBoolean().orElse(false);
if (result) {
candidates.add(dropTool);
}
} else {
candidates.add(dropTool);
}
}
if (!candidates.isEmpty()) {
ContainerDropDescription dropToolDescription = candidates.iterator().next();
return toolConverter.createDropToolHandler(dropToolDescription).apply(childVariableManager);
}
}
}
// $NON-NLS-1$
return new Failure("");
};
}
use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.
the class NavigationOperationHandlerTests method testChildModelOperationWithSelection.
@Test
public void testChildModelOperationWithSelection() {
DiagramDescription diagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
diagramDescription.setLabel(FIRST_DIAGRAM_DESCRIPTION_ID.toString());
Navigation navigation = ToolFactory.eINSTANCE.createNavigation();
navigation.setCreateIfNotExistent(false);
navigation.setDiagramDescription(diagramDescription);
IStatus status = new ChildModelOperationHandler(List.of()).handle(new IObjectService.NoOp(), this.representationMetadataSearchService, this.diagramDescriptionIdentifierProvider, new AQLInterpreter(List.of(), List.of()), Map.of(IEditingContext.EDITING_CONTEXT, new IEditingContext.NoOp()), List.of(navigation));
assertThat(status).isInstanceOf(Success.class);
Success success = (Success) status;
Object selectionParameter = success.getParameters().get(Success.NEW_SELECTION);
assertThat(selectionParameter).isInstanceOf(WorkbenchSelection.class);
WorkbenchSelection selection = (WorkbenchSelection) selectionParameter;
// @formatter:off
assertThat(selection).isEqualTo(new WorkbenchSelection(List.of(new WorkbenchSelectionEntry(FIRST_DIAGRAM_ID, FIRST_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(SECOND_DIAGRAM_ID, SECOND_DIAGRAM_LABEL, Diagram.KIND))));
// @formatter:on
}
Aggregations