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