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