use of org.eclipse.sirius.components.diagrams.Diagram in project sirius-components by eclipse-sirius.
the class ViewToolSectionsProvider method createExtraToolSections.
private List<ToolSection> createExtraToolSections(Object diagramElementDescription) {
List<ToolSection> extraToolSections = new ArrayList<>();
List<NodeDescription> targetDescriptions = new ArrayList<>();
boolean unsynchronizedMapping = false;
// @formatter:off
if (diagramElementDescription instanceof NodeDescription) {
targetDescriptions.add((NodeDescription) diagramElementDescription);
unsynchronizedMapping = SynchronizationPolicy.UNSYNCHRONIZED.equals(((NodeDescription) diagramElementDescription).getSynchronizationPolicy());
} else if (diagramElementDescription instanceof EdgeDescription) {
EdgeDescription edgeDescription = (EdgeDescription) diagramElementDescription;
targetDescriptions.addAll(edgeDescription.getSourceNodeDescriptions());
unsynchronizedMapping = SynchronizationPolicy.UNSYNCHRONIZED.equals(((EdgeDescription) diagramElementDescription).getSynchronizationPolicy());
}
Function<VariableManager, IStatus> fakeHandler = variableManager -> new Success();
// Graphical Delete Tool for unsynchronized mapping only (the handler is never called)
if (diagramElementDescription instanceof NodeDescription || diagramElementDescription instanceof EdgeDescription) {
// Edit Tool (the handler is never called)
SingleClickOnDiagramElementTool editTool = // $NON-NLS-1$
SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool("edit").label(// $NON-NLS-1$
"Edit").imageURL(DiagramImageConstants.EDIT_SVG).targetDescriptions(targetDescriptions).handler(fakeHandler).appliesToDiagramRoot(false).build();
var editToolSection = // $NON-NLS-1$
ToolSection.newToolSection("edit-section").label(// $NON-NLS-1$
"").imageURL(// $NON-NLS-1$
"").tools(List.of(editTool)).build();
extraToolSections.add(editToolSection);
if (unsynchronizedMapping) {
SingleClickOnDiagramElementTool graphicalDeleteTool = // $NON-NLS-1$
SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool("graphical-delete").label(// $NON-NLS-1$
"Delete from diagram").imageURL(DiagramImageConstants.GRAPHICAL_DELETE_SVG).targetDescriptions(targetDescriptions).handler(fakeHandler).appliesToDiagramRoot(false).build();
var graphicalDeleteToolSection = // $NON-NLS-1$
ToolSection.newToolSection("graphical-delete-section").label(// $NON-NLS-1$
"").imageURL(// $NON-NLS-1$
"").tools(List.of(graphicalDeleteTool)).build();
extraToolSections.add(graphicalDeleteToolSection);
}
// Semantic Delete Tool (the handler is never called)
SingleClickOnDiagramElementTool semanticDeleteTool = // $NON-NLS-1$
SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool("semantic-delete").label(// $NON-NLS-1$
"Delete from model").imageURL(DiagramImageConstants.SEMANTIC_DELETE_SVG).targetDescriptions(targetDescriptions).handler(fakeHandler).appliesToDiagramRoot(false).build();
var semanticDeleteToolSection = // $NON-NLS-1$
ToolSection.newToolSection("semantic-delete-section").label(// $NON-NLS-1$
"").imageURL(// $NON-NLS-1$
"").tools(List.of(semanticDeleteTool)).build();
extraToolSections.add(semanticDeleteToolSection);
}
return extraToolSections;
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.Diagram in project sirius-components by eclipse-sirius.
the class CreateViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(new ArrayList<>()).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewCreationRequest> getViewCreationRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.createViewOperation = org.eclipse.sirius.diagram.description.tool.ToolFactory.eINSTANCE.createCreateView();
this.createViewOperationHandler = new CreateViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.createViewOperation);
}
use of org.eclipse.sirius.components.diagrams.Diagram in project sirius-components by eclipse-sirius.
the class DeleteViewOperationHandlerTests method initialize.
@BeforeEach
public void initialize() {
this.operationTestContext = new OperationTestContext();
// @formatter:off
DiagramDescription diagramDescription = DiagramDescription.newDiagramDescription(UUID.randomUUID()).label(// $NON-NLS-1$
"DiagramDescriptionTest").targetObjectIdProvider(// $NON-NLS-1$
variableManager -> "diagramTargetObjectId").canCreatePredicate(variableManager -> true).labelProvider(// $NON-NLS-1$
variableManager -> "Diagram").toolSections(List.of()).nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID()))).edgeDescriptions(List.of()).dropHandler(// $NON-NLS-1$
variableManager -> new Failure("")).build();
Node node = Node.newNode(UUID.randomUUID().toString()).descriptionId(UUID.randomUUID()).type(// $NON-NLS-1$
"Node").targetObjectId(UUID.randomUUID().toString()).targetObjectKind(// $NON-NLS-1$
"ecore::EPackage").targetObjectLabel(OperationTestContext.ROOT_PACKAGE_NAME).label(Label.newLabel(UUID.randomUUID().toString()).type(// $NON-NLS-1$
"Label").text(OperationTestContext.ROOT_PACKAGE_NAME).position(Position.at(0, 0)).size(Size.of(10, 10)).alignment(Position.at(0, 0)).style(// $NON-NLS-1$ //$NON-NLS-2$
LabelStyle.newLabelStyle().color("").fontSize(0).iconURL("").build()).build()).style(// $NON-NLS-1$
ImageNodeStyle.newImageNodeStyle().imageURL("").scalingFactor(0).build()).position(Position.at(0, 0)).size(Size.of(10, 10)).borderNodes(List.of()).childNodes(List.of()).build();
Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString()).descriptionId(diagramDescription.getId()).targetObjectId(UUID.randomUUID().toString()).label(// $NON-NLS-1$
"DiagramTest").position(Position.at(0, 0)).size(Size.of(100, 100)).nodes(List.of(node)).edges(List.of()).build();
IDiagramContext diagramContext = new IDiagramContext.NoOp() {
@Override
public List<ViewDeletionRequest> getViewDeletionRequests() {
return new ArrayList<>();
}
};
this.operationTestContext.getVariables().put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
// @formatter:on
AdapterFactoryEditingDomain editingDomain = new EditingDomainFactory().create();
EditingContext editingContext = new EditingContext(UUID.randomUUID().toString(), editingDomain);
this.operationTestContext.getVariables().put(IEditingContext.EDITING_CONTEXT, editingContext);
this.operationTestContext.getVariables().put(CONTAINER_VIEW, diagram);
this.operationTestContext.getVariables().put(VariableManager.SELF, diagram.getNodes().get(0));
this.deleteViewOperation = ToolFactory.eINSTANCE.createDeleteView();
this.deleteViewOperationHandler = new DeleteViewOperationHandler(this.operationTestContext.getObjectService(), this.operationTestContext.getRepresentationMetadataSearchService(), this.operationTestContext.getIdentifierProvider(), this.operationTestContext.getInterpreter(), new ChildModelOperationHandler(List.of()), this.deleteViewOperation);
}
use of org.eclipse.sirius.components.diagrams.Diagram in project sirius-components by eclipse-sirius.
the class DynamicDiagramsTests method testRenderSynchronizedEcoreDiagram.
@Test
void testRenderSynchronizedEcoreDiagram() throws Exception {
DiagramDescription diagramDescription = ViewFactory.eINSTANCE.createDiagramDescription();
// $NON-NLS-1$
diagramDescription.setName("Simple Ecore Diagram");
diagramDescription.setTitleExpression(NAME_EXPRESSION);
diagramDescription.setAutoLayout(false);
// $NON-NLS-1$
diagramDescription.setDomainType("ecore::EPackage");
NodeDescription eClassNode = ViewFactory.eINSTANCE.createNodeDescription();
// $NON-NLS-1$
eClassNode.setName("EClass Node");
// $NON-NLS-1$
eClassNode.setDomainType("ecore::EClass");
eClassNode.setLabelExpression(NAME_EXPRESSION);
// $NON-NLS-1$
eClassNode.setSemanticCandidatesExpression("aql:self.eClassifiers");
eClassNode.setSynchronizationPolicy(SynchronizationPolicy.SYNCHRONIZED);
// $NON-NLS-1$
this.setBasicNodeStyle(eClassNode, "red");
diagramDescription.getNodeDescriptions().add(eClassNode);
Diagram result = this.render(diagramDescription, this.fixture);
assertThat(result).isNotNull();
assertThat(result.getEdges()).isEmpty();
assertThat(result.getNodes()).hasSize(2);
// $NON-NLS-1$ //$NON-NLS-2$
assertThat(result.getNodes()).extracting(node -> node.getLabel().getText()).containsExactlyInAnyOrder("Class1", "Class2");
}
use of org.eclipse.sirius.components.diagrams.Diagram in project sirius-components by eclipse-sirius.
the class DeleteFromDiagramEventHandler method handleDelete.
private void handleDelete(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, DeleteFromDiagramInput diagramInput) {
List<String> errors = new ArrayList<>();
boolean atLeastOneOk = false;
Diagram diagram = diagramContext.getDiagram();
for (String edgeId : diagramInput.getEdgeIds()) {
var optionalElement = this.diagramQueryService.findEdgeById(diagram, edgeId);
if (optionalElement.isPresent()) {
IStatus status = this.invokeDeleteEdgeTool(optionalElement.get(), editingContext, diagramContext, diagramInput.getDeletionPolicy());
if (status instanceof Success) {
atLeastOneOk = true;
} else {
errors.add(((Failure) status).getMessage());
}
} else {
String message = this.messageService.edgeNotFound(edgeId.toString());
errors.add(message);
}
}
for (String nodeId : diagramInput.getNodeIds()) {
var optionalElement = this.diagramQueryService.findNodeById(diagram, nodeId);
if (optionalElement.isPresent()) {
IStatus status = this.invokeDeleteNodeTool(optionalElement.get(), editingContext, diagramContext, diagramInput.getDeletionPolicy());
if (status instanceof Success) {
atLeastOneOk = true;
} else {
errors.add(((Failure) status).getMessage());
}
} else {
String message = this.messageService.nodeNotFound(nodeId.toString());
errors.add(message);
}
}
this.sendResponse(payloadSink, changeDescriptionSink, errors, atLeastOneOk, diagramContext, diagramInput);
}
Aggregations