Search in sources :

Example 1 with DiagramDescription

use of org.eclipse.sirius.components.view.DiagramDescription 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 2 with DiagramDescription

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

the class DiagramDescriptionValidator method hasProperDomainType.

private boolean hasProperDomainType(DiagramDescription diagramDescription, DiagnosticChain diagnostics) {
    boolean isValid = false;
    ResourceSet resourceSet = diagramDescription.eResource().getResourceSet();
    List<Entity> entities = this.getDomainEntitiesFromResourceSet(resourceSet);
    List<EPackage> ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry());
    // $NON-NLS-1$
    String domainType = Optional.ofNullable(diagramDescription.getDomainType()).orElse("");
    isValid = entities.stream().anyMatch(entity -> this.describesEntity(domainType, entity));
    if (!isValid && !domainType.isBlank()) {
        // @formatter:off
        isValid = ePackages.stream().map(EPackage::getEClassifiers).flatMap(Collection::stream).filter(EClass.class::isInstance).map(EClass.class::cast).anyMatch(classifier -> new DomainClassPredicate(domainType).test(classifier));
    // @formatter:off
    }
    if (!isValid && diagnostics != null) {
        // @formatter:off
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, String.format(DIAGRAM_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), new Object[] { diagramDescription, ViewPackage.Literals.REPRESENTATION_DESCRIPTION__DOMAIN_TYPE });
        // @formatter:on
        diagnostics.add(basicDiagnostic);
    }
    return isValid;
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EDataType(org.eclipse.emf.ecore.EDataType) DiagnosticChain(org.eclipse.emf.common.util.DiagnosticChain) CreateInstance(org.eclipse.sirius.components.view.CreateInstance) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Entity(org.eclipse.sirius.components.domain.Entity) ArrayList(java.util.ArrayList) EValidator(org.eclipse.emf.ecore.EValidator) DomainPackage(org.eclipse.sirius.components.domain.DomainPackage) EClass(org.eclipse.emf.ecore.EClass) Map(java.util.Map) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate) Conditional(org.eclipse.sirius.components.view.Conditional) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription) Collection(java.util.Collection) Diagnostic(org.eclipse.emf.common.util.Diagnostic) DiagramElementDescription(org.eclipse.sirius.components.view.DiagramElementDescription) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) EPackage(org.eclipse.emf.ecore.EPackage) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) Objects(java.util.Objects) List(java.util.List) Domain(org.eclipse.sirius.components.domain.Domain) Entry(java.util.Map.Entry) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) Entity(org.eclipse.sirius.components.domain.Entity) EClass(org.eclipse.emf.ecore.EClass) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Collection(java.util.Collection) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with DiagramDescription

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

the class ViewItemProvider 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);
    DiagramDescription newDiagramDescription = ViewFactory.eINSTANCE.createDiagramDescription();
    // $NON-NLS-1$
    newDiagramDescription.setName("New Diagram Description");
    newChildDescriptors.add(this.createChildParameter(ViewPackage.Literals.VIEW__DESCRIPTIONS, newDiagramDescription));
}
Also used : DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription)

Example 4 with DiagramDescription

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

the class StereotypeDescriptionRegistryConfigurer method getEmptyViewContent.

private String getEmptyViewContent() {
    View newView = ViewFactory.eINSTANCE.createView();
    DiagramDescription diagramDescription = ViewFactory.eINSTANCE.createDiagramDescription();
    // $NON-NLS-1$
    diagramDescription.setName("New Diagram Description");
    newView.getDescriptions().add(diagramDescription);
    return this.stereotypeBuilder.getStereotypeBody(newView);
}
Also used : View(org.eclipse.sirius.components.view.View) DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription)

Example 5 with DiagramDescription

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

the class DynamicDiagramsTests method testRenderUnsynchronizedEcoreDiagram.

@Test
void testRenderUnsynchronizedEcoreDiagram() 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.UNSYNCHRONIZED);
    // $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()).isEmpty();
}
Also used : 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)

Aggregations

DiagramDescription (org.eclipse.sirius.components.view.DiagramDescription)7 NodeStyle (org.eclipse.sirius.components.view.NodeStyle)3 View (org.eclipse.sirius.components.view.View)3 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 List (java.util.List)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 EClass (org.eclipse.emf.ecore.EClass)2 EPackage (org.eclipse.emf.ecore.EPackage)2 IRepresentationPersistenceService (org.eclipse.sirius.components.collaborative.api.IRepresentationPersistenceService)2 DiagramCreationService (org.eclipse.sirius.components.collaborative.diagrams.DiagramCreationService)2 IEditService (org.eclipse.sirius.components.core.api.IEditService)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)2 IRepresentationDescriptionSearchService (org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService)2 Diagram (org.eclipse.sirius.components.diagrams.Diagram)2 ILayoutService (org.eclipse.sirius.components.diagrams.layout.api.ILayoutService)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1