use of org.obeonetwork.dsl.environment.MetaData 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.MetaData in project InformationSystem by ObeoNetwork.
the class MetadataCptPropertiesEditionComponent method updateSemanticModel.
/**
* {@inheritDoc}
* @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
* @generated NOT
*/
public void updateSemanticModel(final IPropertiesEditionEvent event) {
ObeoDSMObject obeoDSMObject = (ObeoDSMObject) semanticObject;
if (EnvironmentViewsRepository.Metadatas.Properties.metadata == event.getAffectedEditor()) {
if (event.getKind() == PropertiesEditionEvent.ADD) {
EReferencePropertiesEditionContext context = new TypedEReferencePropertiesEditingContext(editingContext, this, metadataSettings, EnvironmentPackage.Literals.ANNOTATION, editingContext.getAdapterFactory());
/*
* Generated code below, but it leads to NPE when clicking on the add button
*
EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, metadataSettings, editingContext.getAdapterFactory());
context.addInstanciableTypeFilter(new InstanciableTypeFilter() {
public boolean select(EClass instanciableType) {
return EnvironmentPackage.Literals.ANNOTATION == instanciableType;
}
});
*/
PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy policy = provider.getPolicy(context);
if (policy instanceof CreateEditingPolicy) {
policy.execute();
}
}
} else if (event.getKind() == PropertiesEditionEvent.EDIT) {
EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory());
PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy editionPolicy = provider.getPolicy(context);
if (editionPolicy != null) {
editionPolicy.execute();
}
}
} else if (event.getKind() == PropertiesEditionEvent.REMOVE) {
metadataSettings.removeFromReference((EObject) event.getNewValue());
} else if (event.getKind() == PropertiesEditionEvent.MOVE) {
metadataSettings.move(event.getNewIndex(), (MetaData) event.getNewValue());
}
}
}
use of org.obeonetwork.dsl.environment.MetaData in project InformationSystem by ObeoNetwork.
the class MetadataCptPropertiesEditionComponent method initPart.
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
* org.eclipse.emf.ecore.resource.ResourceSet)
*/
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
setInitializing(true);
if (editingPart != null && key == partKey) {
editingPart.setContext(elt, allResource);
if (editingPart instanceof CompositePropertiesEditionPart) {
((CompositePropertiesEditionPart) editingPart).getSettings().add(metadataSettings);
}
final ObeoDSMObject obeoDSMObject = (ObeoDSMObject) elt;
final MetadatasPropertiesEditionPart metadatasPart = (MetadatasPropertiesEditionPart) editingPart;
// init values
if (isAccessible(EnvironmentViewsRepository.Metadatas.Properties.metadata)) {
metadataSettings = new ReferencesTableSettings(obeoDSMObject, EnvironmentPackage.eINSTANCE.getObeoDSMObject_Metadatas(), EnvironmentPackage.eINSTANCE.getMetaDataContainer_Metadatas());
metadatasPart.initMetadata(metadataSettings);
}
// init filters
if (isAccessible(EnvironmentViewsRepository.Metadatas.Properties.metadata)) {
metadatasPart.addFilterToMetadata(new ViewerFilter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof String)
// $NON-NLS-1$
return element.equals("");
if (element instanceof MetaData)
return true;
return element instanceof Resource;
}
});
// Start of user code for additional businessfilters for metadata
// End of user code
}
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.environment.MetaData in project InformationSystem by ObeoNetwork.
the class AnnotationHelper method getAnnotations.
public static Collection<Annotation> getAnnotations(ObeoDSMObject dsmObject, String name) {
Collection<Annotation> annotations = new ArrayList<Annotation>();
MetaDataContainer metaDataContainer = dsmObject.getMetadatas();
if (metaDataContainer != null) {
for (MetaData metaData : metaDataContainer.getMetadatas()) {
if (metaData instanceof Annotation) {
Annotation annotation = (Annotation) metaData;
if (name.equals(annotation.getTitle())) {
annotations.add(annotation);
}
}
}
}
return annotations;
}
use of org.obeonetwork.dsl.environment.MetaData in project InformationSystem by ObeoNetwork.
the class DocumentationLinkType method loadLinks.
/**
* {@inheritDoc}
* @see org.obeonetwork.tools.linker.LinkType#loadLinks(org.eclipse.emf.ecore.EObject)
*/
public List<EObjectLink> loadLinks(EObject source) {
if (source instanceof ObeoDSMObject) {
ObeoDSMObject element = (ObeoDSMObject) source;
MetaDataContainer metadatas = element.getMetadatas();
if (metadatas != null) {
List<EObjectLink> result = new ArrayList<EObjectLink>();
for (MetaData metadata : metadatas.getMetadatas()) {
if (metadata instanceof Annotation) {
Annotation annotation = (Annotation) metadata;
if (annotation.getTitle() != null && annotation.getTitle().startsWith(DocumentationLink.DOCUMENTATION_ANNOTATION_TITLE)) {
DocumentationLink link = new DocumentationLinkImpl(annotation);
result.add(link);
}
}
}
return result;
}
}
return Collections.emptyList();
}
Aggregations