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;
}
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;
}
Aggregations