Search in sources :

Example 1 with DiagramElementDescription

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

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;
    }
}
Also used : IObjectService(org.eclipse.sirius.components.core.api.IObjectService) BiFunction(java.util.function.BiFunction) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection) IStatus(org.eclipse.sirius.components.representations.IStatus) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) Map(java.util.Map) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Predicate(java.util.function.Predicate) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) Result(org.eclipse.sirius.components.interpreter.Result) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Element(org.eclipse.sirius.components.representations.Element) Objects(java.util.Objects) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) SingleClickOnTwoDiagramElementsCandidate(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsCandidate) Optional(java.util.Optional) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Size(org.eclipse.sirius.components.diagrams.Size) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Status(org.eclipse.sirius.components.interpreter.Status) EClass(org.eclipse.emf.ecore.EClass) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) CanonicalBehaviors(org.eclipse.sirius.components.emf.view.CanonicalBehaviors) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) IEditService(org.eclipse.sirius.components.core.api.IEditService) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) ToolInterpreter(org.eclipse.sirius.components.emf.view.ToolInterpreter) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) DiagramElementDescription(org.eclipse.sirius.components.view.DiagramElementDescription) EdgeTool(org.eclipse.sirius.components.view.EdgeTool) LabelEditTool(org.eclipse.sirius.components.view.LabelEditTool) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) NodeElementProps(org.eclipse.sirius.components.diagrams.elements.NodeElementProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) DeleteTool(org.eclipse.sirius.components.view.DeleteTool) NodeTool(org.eclipse.sirius.components.view.NodeTool) VariableManager(org.eclipse.sirius.components.representations.VariableManager) LabelEditTool(org.eclipse.sirius.components.view.LabelEditTool) ToolInterpreter(org.eclipse.sirius.components.emf.view.ToolInterpreter)

Example 3 with DiagramElementDescription

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;
    }
}
Also used : IObjectService(org.eclipse.sirius.components.core.api.IObjectService) BiFunction(java.util.function.BiFunction) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection) IStatus(org.eclipse.sirius.components.representations.IStatus) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) Map(java.util.Map) DomainClassPredicate(org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate) NodeStyle(org.eclipse.sirius.components.view.NodeStyle) Predicate(java.util.function.Predicate) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) Result(org.eclipse.sirius.components.interpreter.Result) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Element(org.eclipse.sirius.components.representations.Element) Objects(java.util.Objects) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) SingleClickOnTwoDiagramElementsCandidate(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsCandidate) Optional(java.util.Optional) IRepresentationDescription(org.eclipse.sirius.components.representations.IRepresentationDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Size(org.eclipse.sirius.components.diagrams.Size) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Status(org.eclipse.sirius.components.interpreter.Status) EClass(org.eclipse.emf.ecore.EClass) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) CanonicalBehaviors(org.eclipse.sirius.components.emf.view.CanonicalBehaviors) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) IEditService(org.eclipse.sirius.components.core.api.IEditService) EdgeStyle(org.eclipse.sirius.components.diagrams.EdgeStyle) DiagramRenderingCache(org.eclipse.sirius.components.diagrams.renderer.DiagramRenderingCache) ToolInterpreter(org.eclipse.sirius.components.emf.view.ToolInterpreter) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) DiagramElementDescription(org.eclipse.sirius.components.view.DiagramElementDescription) EdgeTool(org.eclipse.sirius.components.view.EdgeTool) LabelEditTool(org.eclipse.sirius.components.view.LabelEditTool) ViewPackage(org.eclipse.sirius.components.view.ViewPackage) NodeElementProps(org.eclipse.sirius.components.diagrams.elements.NodeElementProps) VariableManager(org.eclipse.sirius.components.representations.VariableManager) DeleteTool(org.eclipse.sirius.components.view.DeleteTool) NodeTool(org.eclipse.sirius.components.view.NodeTool) ToolInterpreter(org.eclipse.sirius.components.emf.view.ToolInterpreter) DeleteTool(org.eclipse.sirius.components.view.DeleteTool)

Example 4 with DiagramElementDescription

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

Example 5 with DiagramElementDescription

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));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) DiagramElementDescription(org.eclipse.sirius.components.view.DiagramElementDescription)

Aggregations

DiagramElementDescription (org.eclipse.sirius.components.view.DiagramElementDescription)5 NodeStyle (org.eclipse.sirius.components.view.NodeStyle)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 EClass (org.eclipse.emf.ecore.EClass)3 EObject (org.eclipse.emf.ecore.EObject)3 DomainClassPredicate (org.eclipse.sirius.components.emf.compatibility.DomainClassPredicate)3 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)2 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)2 IEditService (org.eclipse.sirius.components.core.api.IEditService)2 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)2