Search in sources :

Example 1 with Size

use of org.eclipse.sirius.components.diagrams.Size 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);
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) BeforeEach(org.junit.jupiter.api.BeforeEach) Size(org.eclipse.sirius.components.diagrams.Size) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ToolFactory(org.eclipse.sirius.viewpoint.description.tool.ToolFactory) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) Position(org.eclipse.sirius.components.diagrams.Position) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) CreateViewOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.CreateViewOperationHandler) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) EditingDomainFactory(org.eclipse.sirius.components.emf.services.EditingDomainFactory) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) Diagram(org.eclipse.sirius.components.diagrams.Diagram) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) ENamedElement(org.eclipse.emf.ecore.ENamedElement) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) DescriptionFactory(org.eclipse.sirius.diagram.description.DescriptionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CreateView(org.eclipse.sirius.diagram.description.tool.CreateView) VariableManager(org.eclipse.sirius.components.representations.VariableManager) ViewCreationRequest(org.eclipse.sirius.components.diagrams.ViewCreationRequest) ChangeContext(org.eclipse.sirius.viewpoint.description.tool.ChangeContext) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) ViewCreationRequest(org.eclipse.sirius.components.diagrams.ViewCreationRequest) ArrayList(java.util.ArrayList) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) CreateViewOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.CreateViewOperationHandler) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) EditingDomainFactory(org.eclipse.sirius.components.emf.services.EditingDomainFactory) Failure(org.eclipse.sirius.components.representations.Failure) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Size

use of org.eclipse.sirius.components.diagrams.Size 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);
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) BeforeEach(org.junit.jupiter.api.BeforeEach) Node(org.eclipse.sirius.components.diagrams.Node) Size(org.eclipse.sirius.components.diagrams.Size) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) ToolFactory(org.eclipse.sirius.viewpoint.description.tool.ToolFactory) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) Position(org.eclipse.sirius.components.diagrams.Position) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) EditingDomainFactory(org.eclipse.sirius.components.emf.services.EditingDomainFactory) DeleteView(org.eclipse.sirius.viewpoint.description.tool.DeleteView) Diagram(org.eclipse.sirius.components.diagrams.Diagram) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Label(org.eclipse.sirius.components.diagrams.Label) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Success(org.eclipse.sirius.components.representations.Success) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) List(java.util.List) DeleteViewOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.DeleteViewOperationHandler) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) VariableManager(org.eclipse.sirius.components.representations.VariableManager) ChangeContext(org.eclipse.sirius.viewpoint.description.tool.ChangeContext) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) Node(org.eclipse.sirius.components.diagrams.Node) DeleteViewOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.DeleteViewOperationHandler) ArrayList(java.util.ArrayList) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) ViewDeletionRequest(org.eclipse.sirius.components.diagrams.ViewDeletionRequest) EditingDomainFactory(org.eclipse.sirius.components.emf.services.EditingDomainFactory) Failure(org.eclipse.sirius.components.representations.Failure) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Size

use of org.eclipse.sirius.components.diagrams.Size in project sirius-components by eclipse-sirius.

the class UpdateNodeBoundsEventHandler method handleUpdateNodeBounds.

private void handleUpdateNodeBounds(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IDiagramContext diagramContext, UpdateNodeBoundsInput diagramInput) {
    // @formatter:off
    Position newPosition = Position.newPosition().x(diagramInput.getNewPositionX()).y(diagramInput.getNewPositionY()).build();
    Size newSize = Size.newSize().width(diagramInput.getNewWidth()).height(diagramInput.getNewHeight()).build();
    // @formatter:on
    Optional<Node> optionalNode = this.diagramQueryService.findNodeById(diagramContext.getDiagram(), diagramInput.getDiagramElementId());
    if (optionalNode.isPresent()) {
        Position oldPosition = optionalNode.get().getPosition();
        // @formatter:off
        Position delta = Position.newPosition().x(oldPosition.getX() - newPosition.getX()).y(oldPosition.getY() - newPosition.getY()).build();
        // @formatter:on
        diagramContext.setDiagramEvent(new ResizeEvent(diagramInput.getDiagramElementId(), delta, newSize));
        payloadSink.tryEmitValue(new UpdateNodeBoundsSuccessPayload(diagramInput.getId(), diagramContext.getDiagram()));
        changeDescriptionSink.tryEmitNext(new ChangeDescription(DiagramChangeKind.DIAGRAM_LAYOUT_CHANGE, diagramInput.getRepresentationId(), diagramInput));
    } else {
        String message = this.messageService.nodeNotFound(String.valueOf(diagramInput.getDiagramElementId()));
        payloadSink.tryEmitValue(new ErrorPayload(diagramInput.getId(), message));
        changeDescriptionSink.tryEmitNext(new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput));
    }
}
Also used : ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Node(org.eclipse.sirius.components.diagrams.Node) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) UpdateNodeBoundsSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.UpdateNodeBoundsSuccessPayload) ResizeEvent(org.eclipse.sirius.components.diagrams.events.ResizeEvent)

Example 4 with Size

use of org.eclipse.sirius.components.diagrams.Size in project sirius-components by eclipse-sirius.

the class DiagramExportService method addAbsoluteLabelPosition.

private void addAbsoluteLabelPosition(Label label, Position parentPosition) {
    double xOffest = parentPosition.getX();
    double yOffest = parentPosition.getY();
    Position labelPosition = label.getPosition();
    Position labelAlignment = label.getAlignment();
    Size labelSize = label.getSize();
    double xLabel = xOffest + labelPosition.getX() + labelAlignment.getX();
    double yLabel = yOffest + labelPosition.getY() + labelAlignment.getY();
    this.xBeginPositions.add(xLabel);
    this.yBeginPositions.add(yLabel);
    this.xEndPositions.add(xLabel + labelSize.getWidth());
    this.yEndPositions.add(yLabel + labelSize.getHeight());
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size)

Example 5 with Size

use of org.eclipse.sirius.components.diagrams.Size in project sirius-components by eclipse-sirius.

the class NodeExportService method exportImage.

private StringBuilder exportImage(Node node, ImageNodeStyle style) {
    StringBuilder imageExport = new StringBuilder();
    Size size = node.getSize();
    Label label = node.getLabel();
    imageExport.append(this.elementExport.exportGNodeElement(node));
    // adapt the size and position to show the full width of the border
    Size imageSize = Size.of(node.getSize().getWidth() + style.getBorderSize(), node.getSize().getHeight() + style.getBorderSize());
    Position position = Position.at(-style.getBorderSize() / 2., -style.getBorderSize() / 2.);
    imageExport.append(this.elementExport.exportRectangleElement(imageSize, position, Optional.of(style.getBorderRadius()), Optional.empty(), Optional.of(style.getBorderColor()), Optional.of(style.getBorderSize()), Optional.of(style.getBorderStyle())));
    imageExport.append(this.elementExport.exportImageElement(style.getImageURL(), 0, 0, Optional.of(size)));
    imageExport.append(this.elementExport.exportLabel(label));
    imageExport.append(this.exportChildren(node));
    // $NON-NLS-1$
    return imageExport.append("</g>");
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Label(org.eclipse.sirius.components.diagrams.Label)

Aggregations

Size (org.eclipse.sirius.components.diagrams.Size)76 Position (org.eclipse.sirius.components.diagrams.Position)46 Test (org.junit.jupiter.api.Test)35 ArrayList (java.util.ArrayList)19 Node (org.eclipse.sirius.components.diagrams.Node)16 VariableManager (org.eclipse.sirius.components.representations.VariableManager)16 List (java.util.List)15 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)15 UUID (java.util.UUID)14 Label (org.eclipse.sirius.components.diagrams.Label)13 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)12 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)12 Optional (java.util.Optional)11 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)11 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)11 NodeLayoutData (org.eclipse.sirius.components.diagrams.layout.incremental.data.NodeLayoutData)11 Element (org.eclipse.sirius.components.representations.Element)11 LabelStyleDescription (org.eclipse.sirius.components.diagrams.description.LabelStyleDescription)10 Function (java.util.function.Function)9 CustomizableProperties (org.eclipse.sirius.components.diagrams.CustomizableProperties)9