Search in sources :

Example 1 with NodeDescription

use of org.eclipse.sirius.components.view.NodeDescription in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testNodeStyleDescriptionValidQualifiedDomainInResourceSet.

@Test
public void testNodeStyleDescriptionValidQualifiedDomainInResourceSet() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    NodeDescription nodeDescription = ViewFactory.eINSTANCE.createNodeDescription();
    // $NON-NLS-1$
    nodeDescription.setDomainType(SAMPLE_DOMAIN_NAME + "::" + SAMPLE_ENTITY_NAME);
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    XMIResourceImpl viewResource = new XMIResourceImpl();
    viewResource.getContents().add(nodeDescription);
    XMIResourceImpl domainResource = new XMIResourceImpl();
    Domain domain = DomainFactory.eINSTANCE.createDomain();
    domain.setName(SAMPLE_DOMAIN_NAME);
    domainResource.getContents().add(domain);
    Entity entity = DomainFactory.eINSTANCE.createEntity();
    entity.setName(SAMPLE_ENTITY_NAME);
    domain.getTypes().add(entity);
    resourceSet.getResources().add(viewResource);
    resourceSet.getResources().add(domainResource);
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(nodeDescription.eClass(), nodeDescription, diagnosticChain, defaultContext);
    assertThat(validationResult).isTrue();
    assertThat(diagnosticChain).isEqualTo(new BasicDiagnostic(Diagnostic.OK, null, 0, null, null));
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) NodeDescription(org.eclipse.sirius.components.view.NodeDescription) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Domain(org.eclipse.sirius.components.domain.Domain) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Example 2 with NodeDescription

use of org.eclipse.sirius.components.view.NodeDescription 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");
}
Also used : EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IRepresentationPersistenceService(org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SynchronizationPolicy(org.eclipse.sirius.components.view.SynchronizationPolicy) Diagram(org.eclipse.sirius.components.diagrams.Diagram) EClass(org.eclipse.emf.ecore.EClass) ViewFactory(org.eclipse.sirius.components.view.ViewFactory) NodeDescription(org.eclipse.sirius.components.view.NodeDescription) IEditService(org.eclipse.sirius.components.core.api.IEditService) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription) DiagramCreationService(org.eclipse.sirius.components.collaborative.diagrams.DiagramCreationService) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) UUID(java.util.UUID) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.jupiter.api.Test) List(java.util.List) ILayoutService(org.eclipse.sirius.components.diagrams.layout.api.ILayoutService) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) View(org.eclipse.sirius.components.view.View) Optional(java.util.Optional) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) NodeDescription(org.eclipse.sirius.components.view.NodeDescription) DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Example 3 with NodeDescription

use of org.eclipse.sirius.components.view.NodeDescription in project sirius-components by eclipse-sirius.

the class DiagramDescriptionItemProvider method collectNewChildDescriptors.

/**
 * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children that can be created
 * under this object. <!-- begin-user-doc --> <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
    super.collectNewChildDescriptors(newChildDescriptors, object);
    NodeDescription nodeChild = ViewFactory.eINSTANCE.createNodeDescription();
    // $NON-NLS-1$
    nodeChild.setName("Node");
    nodeChild.setStyle(ViewFactory.eINSTANCE.createNodeStyle());
    newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.DIAGRAM_DESCRIPTION__NODE_DESCRIPTIONS, nodeChild));
    EdgeDescription edgeChild = ViewFactory.eINSTANCE.createEdgeDescription();
    // $NON-NLS-1$
    edgeChild.setName("Edge");
    EdgeStyle newEdgeStyle = ViewFactory.eINSTANCE.createEdgeStyle();
    // $NON-NLS-1$
    newEdgeStyle.setColor("#002639");
    edgeChild.setStyle(newEdgeStyle);
    newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.DIAGRAM_DESCRIPTION__EDGE_DESCRIPTIONS, edgeChild));
    DropTool dropTool = ViewFactory.eINSTANCE.createDropTool();
    // $NON-NLS-1$
    dropTool.setName("On Drop");
    newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.DIAGRAM_DESCRIPTION__ON_DROP, dropTool));
}
Also used : NodeDescription(org.eclipse.sirius.components.view.NodeDescription) DropTool(org.eclipse.sirius.components.view.DropTool) EdgeDescription(org.eclipse.sirius.components.view.EdgeDescription) EdgeStyle(org.eclipse.sirius.components.view.EdgeStyle)

Example 4 with NodeDescription

use of org.eclipse.sirius.components.view.NodeDescription in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testNodeDescriptionInvalidDomain.

@Test
public void testNodeDescriptionInvalidDomain() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    NodeDescription nodeDescription = ViewFactory.eINSTANCE.createNodeDescription();
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    XMIResourceImpl xmiResource = new XMIResourceImpl();
    xmiResource.getContents().add(nodeDescription);
    resourceSet.getResources().add(xmiResource);
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, null, 0, null, null);
    // @formatter:off
    expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, // $NON-NLS-1$
    String.format(DiagramDescriptionValidator.DIAGRAM_ELEMENT_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, Optional.ofNullable(nodeDescription.getDomainType()).orElse("")), new Object[] { nodeDescription, ViewPackage.Literals.DIAGRAM_ELEMENT_DESCRIPTION__DOMAIN_TYPE }));
    // @formatter:on
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(nodeDescription.eClass(), nodeDescription, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    assertThat(diagnosticChain).isEqualTo(expected);
}
Also used : NodeDescription(org.eclipse.sirius.components.view.NodeDescription) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Example 5 with NodeDescription

use of org.eclipse.sirius.components.view.NodeDescription in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testNodeStyleDescriptionValidDomainInResourceSet.

@Test
public void testNodeStyleDescriptionValidDomainInResourceSet() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    NodeDescription nodeDescription = ViewFactory.eINSTANCE.createNodeDescription();
    nodeDescription.setDomainType(SAMPLE_ENTITY_NAME);
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    XMIResourceImpl viewResource = new XMIResourceImpl();
    viewResource.getContents().add(nodeDescription);
    XMIResourceImpl domainResource = new XMIResourceImpl();
    Domain domain = DomainFactory.eINSTANCE.createDomain();
    domain.setName(SAMPLE_DOMAIN_NAME);
    domainResource.getContents().add(domain);
    Entity entity = DomainFactory.eINSTANCE.createEntity();
    entity.setName(SAMPLE_ENTITY_NAME);
    domain.getTypes().add(entity);
    resourceSet.getResources().add(viewResource);
    resourceSet.getResources().add(domainResource);
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(nodeDescription.eClass(), nodeDescription, diagnosticChain, defaultContext);
    assertThat(validationResult).isTrue();
    assertThat(diagnosticChain).isEqualTo(new BasicDiagnostic(Diagnostic.OK, null, 0, null, null));
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) NodeDescription(org.eclipse.sirius.components.view.NodeDescription) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Domain(org.eclipse.sirius.components.domain.Domain) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Aggregations

NodeDescription (org.eclipse.sirius.components.view.NodeDescription)9 Test (org.junit.jupiter.api.Test)7 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)5 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)5 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)5 DiagramDescriptionValidator (org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator)5 EClass (org.eclipse.emf.ecore.EClass)3 EPackage (org.eclipse.emf.ecore.EPackage)3 EPackageRegistryImpl (org.eclipse.emf.ecore.impl.EPackageRegistryImpl)2 Diagram (org.eclipse.sirius.components.diagrams.Diagram)2 Domain (org.eclipse.sirius.components.domain.Domain)2 Entity (org.eclipse.sirius.components.domain.Entity)2 DiagramDescription (org.eclipse.sirius.components.view.DiagramDescription)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)1