Search in sources :

Example 1 with CreateInstance

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

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

the class DiagramDescriptionValidator method validate.

@Override
public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
    boolean isValid = true;
    if (eObject instanceof DiagramDescription) {
        DiagramDescription diagramDescription = (DiagramDescription) eObject;
        isValid = this.hasProperDomainType(diagramDescription, diagnostics) && isValid;
    }
    if (eObject instanceof DiagramElementDescription) {
        DiagramElementDescription diagramElementDescription = (DiagramElementDescription) eObject;
        isValid = this.hasProperDomainType(diagramElementDescription, diagnostics) && isValid;
    }
    if (eObject instanceof NodeStyle) {
        NodeStyle nodeStyle = (NodeStyle) eObject;
        isValid = this.hasProperColor(nodeStyle, diagnostics) && isValid;
    }
    if (eObject instanceof Conditional) {
        Conditional conditional = (Conditional) eObject;
        isValid = this.conditionIsPresent(conditional, diagnostics) && isValid;
    }
    if (eObject instanceof CreateInstance) {
        CreateInstance createInstance = (CreateInstance) eObject;
        isValid = this.hasProperDomainType(createInstance, diagnostics) && isValid;
    }
    return isValid;
}
Also used : NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Conditional(org.eclipse.sirius.components.view.Conditional) CreateInstance(org.eclipse.sirius.components.view.CreateInstance) DiagramDescription(org.eclipse.sirius.components.view.DiagramDescription) DiagramElementDescription(org.eclipse.sirius.components.view.DiagramElementDescription)

Aggregations

Conditional (org.eclipse.sirius.components.view.Conditional)2 CreateInstance (org.eclipse.sirius.components.view.CreateInstance)2 DiagramDescription (org.eclipse.sirius.components.view.DiagramDescription)2 DiagramElementDescription (org.eclipse.sirius.components.view.DiagramElementDescription)2 NodeStyle (org.eclipse.sirius.components.view.NodeStyle)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 DiagnosticChain (org.eclipse.emf.common.util.DiagnosticChain)1 EList (org.eclipse.emf.common.util.EList)1 EClass (org.eclipse.emf.ecore.EClass)1 EDataType (org.eclipse.emf.ecore.EDataType)1 EObject (org.eclipse.emf.ecore.EObject)1