Search in sources :

Example 1 with DomainClassPredicate

use of org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate in project sirius-components by eclipse-sirius.

the class DiagramDescriptionValidator method hasProperDomainType.

private boolean hasProperDomainType(DiagramElementDescription diagramElementDescription, DiagnosticChain diagnostics) {
    boolean isValid = false;
    ResourceSet resourceSet = diagramElementDescription.eResource().getResourceSet();
    List<Entity> entities = this.getDomainEntitiesFromResourceSet(resourceSet);
    List<EPackage> ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry());
    // $NON-NLS-1$
    String domainType = Optional.ofNullable(diagramElementDescription.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_ELEMENT_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), new Object[] { diagramElementDescription, ViewPackage.Literals.DIAGRAM_ELEMENT_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 2 with DomainClassPredicate

use of org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate in project sirius-components by eclipse-sirius.

the class DiagramDescriptionConverter method canCreateDiagram.

private boolean canCreateDiagram(org.eclipse.sirius.components.view.DiagramDescription viewDiagramDescription, VariableManager variableManager, AQLInterpreter interpreter) {
    boolean result = false;
    // @formatter:off
    Optional<EClass> optionalEClass = variableManager.get(IRepresentationDescription.CLASS, EClass.class).filter(new DomainClassPredicate(viewDiagramDescription.getDomainType()));
    // @formatter:on
    if (optionalEClass.isPresent()) {
        String preconditionExpression = viewDiagramDescription.getPreconditionExpression();
        if (preconditionExpression != null && !preconditionExpression.isBlank()) {
            result = interpreter.evaluateExpression(variableManager.getVariables(), preconditionExpression).asBoolean().orElse(false);
        } else {
            result = true;
        }
    }
    return result;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate)

Example 3 with DomainClassPredicate

use of org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate in project sirius-components by eclipse-sirius.

the class DiagramDescriptionValidator method hasProperDomainType.

private boolean hasProperDomainType(CreateInstance createInstance, DiagnosticChain diagnostics) {
    boolean isValid = false;
    ResourceSet resourceSet = createInstance.eResource().getResourceSet();
    List<Entity> entities = this.getDomainEntitiesFromResourceSet(resourceSet);
    List<EPackage> ePackages = this.getEPackagesFromRegistry(resourceSet.getPackageRegistry());
    // $NON-NLS-1$
    String domainType = Optional.ofNullable(createInstance.getTypeName()).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(CREATE_INSTANCE_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, domainType), new Object[] { createInstance, ViewPackage.Literals.CREATE_INSTANCE__TYPE_NAME });
        // @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 4 with DomainClassPredicate

use of org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate 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 5 with DomainClassPredicate

use of org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate in project sirius-components by eclipse-sirius.

the class CanCreateDiagramPredicate method test.

@Override
public boolean test(VariableManager variableManager) {
    boolean result = false;
    String domainClass = this.diagramDescription.getDomainClass();
    // @formatter:off
    Optional<EClass> optionalEObject = variableManager.get(IRepresentationDescription.CLASS, EClass.class).filter(new DomainClassPredicate(domainClass));
    if (optionalEObject.isPresent()) {
        String preconditionExpression = this.diagramDescription.getPreconditionExpression();
        if (preconditionExpression != null && !preconditionExpression.isBlank()) {
            Result preconditionResult = this.interpreter.evaluateExpression(variableManager.getVariables(), preconditionExpression);
            result = preconditionResult.asBoolean().orElse(false);
        } else {
            result = true;
        }
    }
    return result;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate) Result(org.eclipse.sirius.components.interpreter.Result)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)5 DomainClassPredicate (org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate)5 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)3 Diagnostic (org.eclipse.emf.common.util.Diagnostic)3 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)3 EList (org.eclipse.emf.common.util.EList)3 EDataType (org.eclipse.emf.ecore.EDataType)3 EObject (org.eclipse.emf.ecore.EObject)3 EPackage (org.eclipse.emf.ecore.EPackage)3 EValidator (org.eclipse.emf.ecore.EValidator)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3