Search in sources :

Example 1 with Annotation

use of org.obeonetwork.dsl.environment.Annotation 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 Annotation

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

the class MetadatasPropertiesEditionPartForm method createMetadataTableComposition.

/**
 * @param container
 */
protected Composite createMetadataTableComposition(FormToolkit widgetFactory, Composite container) {
    Composite tableContainer = widgetFactory.createComposite(container, SWT.NONE);
    GridLayout tableContainerLayout = new GridLayout();
    GridData tableContainerData = new GridData(GridData.FILL_BOTH);
    tableContainerData.horizontalSpan = 3;
    tableContainer.setLayoutData(tableContainerData);
    tableContainerLayout.numColumns = 2;
    tableContainer.setLayout(tableContainerLayout);
    org.eclipse.swt.widgets.Table tableMetadata = widgetFactory.createTable(tableContainer, SWT.FULL_SELECTION | SWT.BORDER);
    tableMetadata.setHeaderVisible(true);
    GridData gdMetadata = new GridData();
    gdMetadata.grabExcessHorizontalSpace = true;
    gdMetadata.horizontalAlignment = GridData.FILL;
    gdMetadata.grabExcessVerticalSpace = true;
    gdMetadata.verticalAlignment = GridData.FILL;
    tableMetadata.setLayoutData(gdMetadata);
    tableMetadata.setLinesVisible(true);
    // Start of user code for columns definition for Metadata
    TableColumn title = new TableColumn(tableMetadata, SWT.NONE);
    title.setWidth(120);
    // $NON-NLS-1$
    title.setText("title");
    TableColumn body = new TableColumn(tableMetadata, SWT.NONE);
    body.setWidth(300);
    // $NON-NLS-1$
    body.setText("body");
    // End of user code
    metadata = new TableViewer(tableMetadata);
    metadata.setContentProvider(new ArrayContentProvider());
    metadata.setLabelProvider(new ITableLabelProvider() {

        // Start of user code for label provider definition for Metadata
        public String getColumnText(Object object, int columnIndex) {
            if (object instanceof Annotation) {
                Annotation annot = (Annotation) object;
                switch(columnIndex) {
                    case 0:
                        return annot.getTitle();
                    case 1:
                        return annot.getBody();
                }
            }
            // $NON-NLS-1$
            return "";
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }

        // End of user code
        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }
    });
    metadata.getTable().addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            if (metadata.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) metadata.getSelection();
                if (selection.getFirstElement() instanceof EObject) {
                    propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MetadatasPropertiesEditionPartForm.this, EnvironmentViewsRepository.Metadatas.Properties.metadata, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
                    metadata.refresh();
                }
            }
        }
    });
    GridData metadataData = new GridData(GridData.FILL_HORIZONTAL);
    metadataData.minimumHeight = 120;
    metadataData.heightHint = 120;
    metadata.getTable().setLayoutData(metadataData);
    for (ViewerFilter filter : this.metadataFilters) {
        metadata.addFilter(filter);
    }
    EditingUtils.setID(metadata.getTable(), EnvironmentViewsRepository.Metadatas.Properties.metadata);
    // $NON-NLS-1$
    EditingUtils.setEEFtype(metadata.getTable(), "eef::TableComposition::field");
    createMetadataPanel(widgetFactory, tableContainer);
    // End of user code
    return container;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IPropertiesEditionEvent(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) PropertiesEditionEvent(org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) Annotation(org.obeonetwork.dsl.environment.Annotation) GridLayout(org.eclipse.swt.layout.GridLayout) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) IPropertiesEditionEvent(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) PropertiesEditionEvent(org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with Annotation

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

the class MetadatasPropertiesEditionPartImpl method createMetadataTableComposition.

/**
 * @param container
 */
protected Composite createMetadataTableComposition(Composite container) {
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridLayout tableContainerLayout = new GridLayout();
    GridData tableContainerData = new GridData(GridData.FILL_BOTH);
    tableContainerData.horizontalSpan = 3;
    tableContainer.setLayoutData(tableContainerData);
    tableContainerLayout.numColumns = 2;
    tableContainer.setLayout(tableContainerLayout);
    org.eclipse.swt.widgets.Table tableMetadata = new org.eclipse.swt.widgets.Table(tableContainer, SWT.FULL_SELECTION);
    tableMetadata.setHeaderVisible(true);
    GridData gdMetadata = new GridData();
    gdMetadata.grabExcessHorizontalSpace = true;
    gdMetadata.horizontalAlignment = GridData.FILL;
    gdMetadata.grabExcessVerticalSpace = true;
    gdMetadata.verticalAlignment = GridData.FILL;
    tableMetadata.setLayoutData(gdMetadata);
    tableMetadata.setLinesVisible(true);
    // Start of user code for columns definition for Metadata
    TableColumn title = new TableColumn(tableMetadata, SWT.NONE);
    title.setWidth(120);
    // $NON-NLS-1$
    title.setText("title");
    TableColumn body = new TableColumn(tableMetadata, SWT.NONE);
    body.setWidth(300);
    // $NON-NLS-1$
    body.setText("body");
    // End of user code
    metadata = new TableViewer(tableMetadata);
    metadata.setContentProvider(new ArrayContentProvider());
    metadata.setLabelProvider(new ITableLabelProvider() {

        // Start of user code for label provider definition for Metadata
        public String getColumnText(Object object, int columnIndex) {
            if (object instanceof Annotation) {
                Annotation annot = (Annotation) object;
                switch(columnIndex) {
                    case 0:
                        return annot.getTitle();
                    case 1:
                        return annot.getBody();
                }
            }
            // $NON-NLS-1$
            return "";
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }

        // End of user code
        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener listener) {
        }
    });
    metadata.getTable().addListener(SWT.MouseDoubleClick, new Listener() {

        public void handleEvent(Event event) {
            if (metadata.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) metadata.getSelection();
                if (selection.getFirstElement() instanceof EObject) {
                    propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(MetadatasPropertiesEditionPartImpl.this, EnvironmentViewsRepository.Metadatas.Properties.metadata, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
                    metadata.refresh();
                }
            }
        }
    });
    GridData metadataData = new GridData(GridData.FILL_HORIZONTAL);
    metadataData.minimumHeight = 120;
    metadataData.heightHint = 120;
    metadata.getTable().setLayoutData(metadataData);
    for (ViewerFilter filter : this.metadataFilters) {
        metadata.addFilter(filter);
    }
    EditingUtils.setID(metadata.getTable(), EnvironmentViewsRepository.Metadatas.Properties.metadata);
    // $NON-NLS-1$
    EditingUtils.setEEFtype(metadata.getTable(), "eef::TableComposition::field");
    createMetadataPanel(tableContainer);
    // End of user code
    return container;
}
Also used : Listener(org.eclipse.swt.widgets.Listener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) EObject(org.eclipse.emf.ecore.EObject) Composite(org.eclipse.swt.widgets.Composite) IPropertiesEditionEvent(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) PropertiesEditionEvent(org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) Annotation(org.obeonetwork.dsl.environment.Annotation) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) IPropertiesEditionEvent(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent) PropertiesEditionEvent(org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with Annotation

use of org.obeonetwork.dsl.environment.Annotation 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 Annotation

use of org.obeonetwork.dsl.environment.Annotation 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

Annotation (org.obeonetwork.dsl.environment.Annotation)9 MetaDataContainer (org.obeonetwork.dsl.environment.MetaDataContainer)5 ArrayList (java.util.ArrayList)3 MetaData (org.obeonetwork.dsl.environment.MetaData)3 EObject (org.eclipse.emf.ecore.EObject)2 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)2 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Image (org.eclipse.swt.graphics.Image)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2