Search in sources :

Example 1 with MetaDataContainer

use of org.obeonetwork.dsl.environment.MetaDataContainer in project InformationSystem by ObeoNetwork.

the class AnnotationServices method setAnnotation.

/**
 * Creates or sets an annotation with the specified name and value
 * @param context Object carrying the annotation
 * @param annotationName Name of the annotation
 * @param annotationValue Value of the annotation
 */
public void setAnnotation(ObeoDSMObject context, String annotationName, String annotationValue) {
    if (annotationName == null) {
        return;
    }
    Annotation annotation = null;
    // Get the existing MetaDataContainer or create a new one
    MetaDataContainer container = context.getMetadatas();
    if (container == null) {
        // Create a new container
        container = EnvironmentFactory.eINSTANCE.createMetaDataContainer();
        context.setMetadatas(container);
        // Create a new annotation
        annotation = EnvironmentFactory.eINSTANCE.createAnnotation();
        annotation.setTitle(annotationName);
        annotation.setBody(annotationValue);
        container.getMetadatas().add(annotation);
        return;
    }
    // Look for an existing annotation
    for (MetaData metadata : container.getMetadatas()) {
        if (metadata instanceof Annotation) {
            Annotation existingAnnotation = (Annotation) metadata;
            if (annotationName.equals(existingAnnotation.getTitle())) {
                existingAnnotation.setBody(annotationValue);
                return;
            }
        }
    }
    // If we get there it means there is no existing annotation with the specified name
    annotation = EnvironmentFactory.eINSTANCE.createAnnotation();
    annotation.setTitle(annotationName);
    annotation.setBody(annotationValue);
    container.getMetadatas().add(annotation);
}
Also used : MetaData(org.obeonetwork.dsl.environment.MetaData) MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer) Annotation(org.obeonetwork.dsl.environment.Annotation)

Example 2 with MetaDataContainer

use of org.obeonetwork.dsl.environment.MetaDataContainer in project InformationSystem by ObeoNetwork.

the class CustomRiskPropertiesEditionComponent method createRiskObject.

private Risk createRiskObject(EObject element) {
    if (element instanceof ObeoDSMObject) {
        ObeoDSMObject obeoDSMObject = (ObeoDSMObject) element;
        MetaDataContainer container = obeoDSMObject.getMetadatas();
        if (container == null) {
            container = EnvironmentFactory.eINSTANCE.createMetaDataContainer();
            obeoDSMObject.setMetadatas(container);
        }
        Risk newRisk = GraalExtensionsFactory.eINSTANCE.createRisk();
        container.getMetadatas().add(newRisk);
        return newRisk;
    }
    return null;
}
Also used : ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) Risk(fr.gouv.mindef.safran.graalextensions.Risk) MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer)

Example 3 with MetaDataContainer

use of org.obeonetwork.dsl.environment.MetaDataContainer in project InformationSystem by ObeoNetwork.

the class CustomEEFEditorSettings method getOrCreateSignificantObject.

public EObject getOrCreateSignificantObject() {
    EObject object = getSignificantObject();
    if (object == null) {
        if (getSource() instanceof ObeoDSMObject) {
            ObeoDSMObject source = (ObeoDSMObject) getSource();
            EditingDomain domain = context.getEditingDomain();
            if (source.getMetadatas() == null) {
                // Create MetaDataContainer
                MetaDataContainer mdContainer = EnvironmentFactory.eINSTANCE.createMetaDataContainer();
                domain.getCommandStack().execute(SetCommand.create(domain, source, EnvironmentPackage.eINSTANCE.getObeoDSMObject_Metadatas(), mdContainer));
            }
            // Create Risk
            Risk risk = GraalExtensionsFactory.eINSTANCE.createRisk();
            domain.getCommandStack().execute(AddCommand.create(domain, source.getMetadatas(), EnvironmentPackage.eINSTANCE.getMetaDataContainer_Metadatas(), risk));
            significantObject = getSignificantObject();
            return significantObject;
        }
    }
    return object;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) Risk(fr.gouv.mindef.safran.graalextensions.Risk) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer)

Example 4 with MetaDataContainer

use of org.obeonetwork.dsl.environment.MetaDataContainer in project InformationSystem by ObeoNetwork.

the class AnnotationHelper method setAnnotation.

public static void setAnnotation(ObeoDSMObject dsmObject, String key, String value) {
    Annotation annotation = getAnnotation(dsmObject, key);
    if (value == null) {
        if (annotation != null) {
            // then we have to remove the annotation
            EcoreUtil.delete(annotation);
        }
        return;
    }
    if (annotation == null) {
        MetaDataContainer metaDataContainer = getOrCreateMetaDataContainer(dsmObject);
        annotation = EnvironmentFactory.eINSTANCE.createAnnotation();
        metaDataContainer.getMetadatas().add(annotation);
        annotation.setTitle(key);
    }
    annotation.setBody(value);
}
Also used : MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer) Annotation(org.obeonetwork.dsl.environment.Annotation)

Example 5 with MetaDataContainer

use of org.obeonetwork.dsl.environment.MetaDataContainer in project InformationSystem by ObeoNetwork.

the class AnnotationHelper method addAnnotation.

public static void addAnnotation(ObeoDSMObject dsmObject, String key, String value) {
    MetaDataContainer metaDataContainer = getOrCreateMetaDataContainer(dsmObject);
    Annotation annotation = EnvironmentFactory.eINSTANCE.createAnnotation();
    metaDataContainer.getMetadatas().add(annotation);
    annotation.setTitle(key);
    annotation.setBody(value);
}
Also used : MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer) Annotation(org.obeonetwork.dsl.environment.Annotation)

Aggregations

MetaDataContainer (org.obeonetwork.dsl.environment.MetaDataContainer)8 Annotation (org.obeonetwork.dsl.environment.Annotation)5 MetaData (org.obeonetwork.dsl.environment.MetaData)3 ObeoDSMObject (org.obeonetwork.dsl.environment.ObeoDSMObject)3 Risk (fr.gouv.mindef.safran.graalextensions.Risk)2 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)1 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)1 DocumentationLink (org.obeonetwork.tools.doc.core.DocumentationLink)1 EObjectLink (org.obeonetwork.tools.linker.EObjectLink)1