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