Search in sources :

Example 1 with MetaData

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);
}
Also used : MetaData(org.obeonetwork.dsl.environment.MetaData) MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer) Annotation(org.obeonetwork.dsl.environment.Annotation)

Example 2 with MetaData

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());
        }
    }
}
Also used : EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) MetaData(org.obeonetwork.dsl.environment.MetaData) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) TypedEReferencePropertiesEditingContext(org.eclipse.emf.eef.runtime.context.impl.TypedEReferencePropertiesEditingContext) EObject(org.eclipse.emf.ecore.EObject) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)

Example 3 with MetaData

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);
}
Also used : ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) MetadatasPropertiesEditionPart(org.obeonetwork.dsl.environment.parts.MetadatasPropertiesEditionPart) CompositePropertiesEditionPart(org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart) MetaData(org.obeonetwork.dsl.environment.MetaData) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) Resource(org.eclipse.emf.ecore.resource.Resource) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject)

Example 4 with MetaData

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;
}
Also used : MetaData(org.obeonetwork.dsl.environment.MetaData) ArrayList(java.util.ArrayList) MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer) Annotation(org.obeonetwork.dsl.environment.Annotation)

Example 5 with MetaData

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();
}
Also used : MetaData(org.obeonetwork.dsl.environment.MetaData) DocumentationLink(org.obeonetwork.tools.doc.core.DocumentationLink) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) EObjectLink(org.obeonetwork.tools.linker.EObjectLink) ArrayList(java.util.ArrayList) MetaDataContainer(org.obeonetwork.dsl.environment.MetaDataContainer) Annotation(org.obeonetwork.dsl.environment.Annotation)

Aggregations

MetaData (org.obeonetwork.dsl.environment.MetaData)5 Annotation (org.obeonetwork.dsl.environment.Annotation)3 MetaDataContainer (org.obeonetwork.dsl.environment.MetaDataContainer)3 ObeoDSMObject (org.obeonetwork.dsl.environment.ObeoDSMObject)3 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 TypedEReferencePropertiesEditingContext (org.eclipse.emf.eef.runtime.context.impl.TypedEReferencePropertiesEditingContext)1 CompositePropertiesEditionPart (org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)1 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)1 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 MetadatasPropertiesEditionPart (org.obeonetwork.dsl.environment.parts.MetadatasPropertiesEditionPart)1 DocumentationLink (org.obeonetwork.tools.doc.core.DocumentationLink)1 EObjectLink (org.obeonetwork.tools.linker.EObjectLink)1