use of org.eclipse.sirius.components.view.DiagramElementDescription 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.view.DiagramElementDescription in project sirius-components by eclipse-sirius.
the class DiagramDescriptionConverter method createLabelEditHandler.
private BiFunction<VariableManager, String, IStatus> createLabelEditHandler(DiagramElementDescription diagramElementDescription, AQLInterpreter interpreter) {
var capturedConvertedNodes = Map.copyOf(this.convertedNodes);
LabelEditTool tool = diagramElementDescription.getLabelEditTool();
if (tool != null) {
return (variableManager, newLabel) -> {
VariableManager childVariableManager = variableManager.createChild();
// $NON-NLS-1$
childVariableManager.put("arg0", newLabel);
return new ToolInterpreter(interpreter, this.objectService, this.editService, this.getDiagramContext(variableManager), capturedConvertedNodes).executeTool(tool, childVariableManager);
};
} else {
return this.canonicalBehaviors::editLabel;
}
}
use of org.eclipse.sirius.components.view.DiagramElementDescription in project sirius-components by eclipse-sirius.
the class DiagramDescriptionConverter method createDeleteHandler.
private Function<VariableManager, IStatus> createDeleteHandler(DiagramElementDescription diagramElementDescription, AQLInterpreter interpreter) {
var capturedConvertedNodes = Map.copyOf(this.convertedNodes);
DeleteTool tool = diagramElementDescription.getDeleteTool();
if (tool != null) {
return variableManager -> {
return new ToolInterpreter(interpreter, this.objectService, this.editService, this.getDiagramContext(variableManager), capturedConvertedNodes).executeTool(tool, variableManager);
};
} else {
return this.canonicalBehaviors::deleteElement;
}
}
use of org.eclipse.sirius.components.view.DiagramElementDescription 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;
}
use of org.eclipse.sirius.components.view.DiagramElementDescription in project sirius-components by eclipse-sirius.
the class CreateViewImpl method setElementDescription.
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
@Override
public void setElementDescription(DiagramElementDescription newElementDescription) {
DiagramElementDescription oldElementDescription = this.elementDescription;
this.elementDescription = newElementDescription;
if (this.eNotificationRequired())
this.eNotify(new ENotificationImpl(this, Notification.SET, ViewPackage.CREATE_VIEW__ELEMENT_DESCRIPTION, oldElementDescription, this.elementDescription));
}
Aggregations