use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferenceOppositePropertiesEditionComponent 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(oppositeNameSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeReferencedTypeSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeMultiplicitySettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIsCompositeSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeNavigableSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIdentifierSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeDescriptionSettings);
}
final Reference reference = (Reference) elt;
final OppositePropertiesEditionPart oppositePart = (OppositePropertiesEditionPart) editingPart;
// init values
if (oppositeNameSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.name))
oppositePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeNameSettings.getValue()));
// FIXME NO VALID CASE INTO template public updater(editionElement : PropertiesEditionElement, view : View, pec : PropertiesEditionComponent) in widgetControl.mtl module, with the values : oppositeReferencedType, Opposite, reference.
if (oppositeMultiplicitySettings.getSignificantObject() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.multiplicity)) {
oppositePart.initMultiplicity(EEFUtils.choiceOfValues(oppositeMultiplicitySettings.getSignificantObject(), EnvironmentPackage.eINSTANCE.getProperty_Multiplicity()), (Enumerator) oppositeMultiplicitySettings.getValue());
}
if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.isComposite)) {
oppositePart.setIsComposite((Boolean) oppositeIsCompositeSettings.getValue());
}
if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.navigable)) {
oppositePart.setNavigable((Boolean) oppositeNavigableSettings.getValue());
}
if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.identifier)) {
oppositePart.setIdentifier((Boolean) oppositeIdentifierSettings.getValue());
}
if (oppositeDescriptionSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.description))
oppositePart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeDescriptionSettings.getValue()));
// init filters
// FIXME NO VALID CASE INTO template public filterUpdater(editionElement : PropertiesEditionElement, view : View, pec : PropertiesEditionComponent) in widgetControl.mtl module, with the values : oppositeReferencedType, Opposite, reference.
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferenceOppositePropertiesEditionComponentSpec method initPart.
@Override
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(oppositeNameSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeReferencedTypeSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeMultiplicitySettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIsCompositeSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeNavigableSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIdentifierSettings);
((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeDescriptionSettings);
}
final OppositePropertiesEditionPart oppositePart = (OppositePropertiesEditionPart) editingPart;
if (elt != null && elt instanceof Reference) {
// init values
if (oppositeNameSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.name))
oppositePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeNameSettings.getValue()));
if (oppositeMultiplicitySettings.getSignificantObject() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.multiplicity)) {
oppositePart.initMultiplicity(EEFUtils.choiceOfValues(oppositeMultiplicitySettings.getSignificantObject(), EnvironmentPackage.eINSTANCE.getProperty_Multiplicity()), (Enumerator) oppositeMultiplicitySettings.getValue());
}
if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.isComposite)) {
oppositePart.setIsComposite((Boolean) oppositeIsCompositeSettings.getValue());
}
if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.navigable)) {
oppositePart.setNavigable((Boolean) oppositeNavigableSettings.getValue());
}
if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.identifier)) {
oppositePart.setIdentifier((Boolean) oppositeIdentifierSettings.getValue());
}
if (oppositeDescriptionSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.description))
oppositePart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeDescriptionSettings.getValue()));
if (this.oppositeReferencedTypeSettings.getSignificantObject() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.referencedType)) {
oppositePart.setReferencedType((EObject) this.oppositeReferencedTypeSettings.getValue());
}
} else {
// no value
}
}
setInitializing(false);
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createIndices.
private void createIndices(Entity entity) {
Table table = getFromOutputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
// We collect unique and non unique indices, all indices will be kept unchanged
Collection<Index> existingUniqueIndices = new ArrayList<Index>();
Collection<Index> existingNonUniqueIndices = new ArrayList<Index>();
for (Index index : table.getIndexes()) {
if (index.isUnique()) {
existingUniqueIndices.add(index);
} else {
existingNonUniqueIndices.add(index);
}
}
// Handle indexes on attributes
for (Attribute attribute : entity.getOwnedAttributes()) {
String unicity = AnnotationHelper.getPhysicalUnique(attribute);
if (unicity != null) {
List<Column> columns = new ArrayList<Column>();
Column column = getFromOutputTraceabilityMap(attribute, DatabasePackage.Literals.COLUMN);
columns.add(column);
Index index = findIndex(existingUniqueIndices, columns);
if (index != null) {
// We reuse the existing index
index.getElements().get(0).setAsc(isIndexAsc(unicity));
} else {
// We have to create a new index
index = DatabaseFactory.eINSTANCE.createIndex();
table.getIndexes().add(index);
existingUniqueIndices.add(index);
index.setUnique(true);
IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
index.getElements().add(indexElement);
indexElement.setAsc(isIndexAsc(unicity));
indexElement.setColumn(column);
}
index.setName(getUniqueIndexName(index));
index.setComments(getUniqueIndexComments(index));
addToObjectsToBeKept(index);
}
}
// Handle indexes on entity
String tableUnicity = AnnotationHelper.getPhysicalUnique(entity);
if (tableUnicity != null) {
List<Map<String, Boolean>> listOfIndexInfos = getInfosFromTableUnicity(tableUnicity);
for (Map<String, Boolean> indexInfos : listOfIndexInfos) {
List<Column> columns = new ArrayList<Column>();
for (String columnName : indexInfos.keySet()) {
for (Column column : table.getColumns()) {
if (column.getName().equalsIgnoreCase(columnName)) {
columns.add(column);
break;
}
}
}
// Check if all columns were found
if (columns.size() != indexInfos.size()) {
String msg = "Could not understand PHYSICAL_UNIQUE annotation for Entity: " + entity.getName() + " - annotation: \"" + tableUnicity + "\"";
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, msg));
}
// Try to retrieve an existing index on these columns
Index index = findIndex(existingUniqueIndices, columns);
if (index != null) {
// Update sort orders
for (IndexElement element : index.getElements()) {
element.setAsc(indexInfos.get(element.getColumn().getName().toUpperCase()));
}
} else {
// We have to create a new index
index = DatabaseFactory.eINSTANCE.createIndex();
table.getIndexes().add(index);
existingUniqueIndices.add(index);
index.setUnique(true);
for (Column targetColumn : columns) {
IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
index.getElements().add(indexElement);
String s = targetColumn.getName();
indexElement.setAsc(indexInfos.get(targetColumn.getName().toUpperCase()));
indexElement.setColumn(targetColumn);
}
}
index.setName(getUniqueIndexName(index));
index.setComments(getUniqueIndexComments(index));
addToObjectsToBeKept(index);
}
}
// Handle indexes on references
for (Reference reference : getReferencesForIndexCreation(entity)) {
boolean indexShouldBeUnique = false;
// if (isMultiplicitySimple(reference)) {
// indexShouldBeUnique = true;
// } else if (isMultiplicityMany(reference)) {
// indexShouldBeUnique = false;
// }
String unicity = AnnotationHelper.getPhysicalUnique(reference);
if (unicity == null) {
unicity = "ASC";
} else {
indexShouldBeUnique = true;
}
List<Column> columns = new ArrayList<Column>();
ForeignKey fk = getFromOutputTraceabilityMap(reference, DatabasePackage.Literals.FOREIGN_KEY);
// Get columns for FK
if (fk != null) {
for (ForeignKeyElement fkElt : fk.getElements()) {
columns.add(fkElt.getFkColumn());
}
Index index = null;
if (indexShouldBeUnique) {
index = findIndex(existingUniqueIndices, columns);
} else {
index = findIndex(existingNonUniqueIndices, columns);
}
if (index != null) {
// Ensure the index is of the right kind
index.setUnique(indexShouldBeUnique);
// We reuse the existing index
for (IndexElement indexElt : index.getElements()) {
indexElt.setAsc(isIndexAsc(unicity));
}
} else {
// We have to create a new index
index = DatabaseFactory.eINSTANCE.createIndex();
table.getIndexes().add(index);
if (indexShouldBeUnique) {
existingUniqueIndices.add(index);
} else {
existingNonUniqueIndices.add(index);
}
index.setUnique(indexShouldBeUnique);
for (ForeignKeyElement fkElt : fk.getElements()) {
IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
index.getElements().add(indexElement);
indexElement.setAsc(isIndexAsc(unicity));
indexElement.setColumn(fkElt.getFkColumn());
}
}
index.setName(fk.getName());
index.setComments(getFKIndexComments(index));
addToObjectsToBeKept(index);
}
}
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class MLDToEntity method addPhysicalUnique.
private void addPhysicalUnique(Index index) {
if (index.isUnique()) {
if (index.getElements().size() == 1) {
// Add annotation on Attribute
IndexElement indexElement = index.getElements().get(0);
String annotationValue = indexElement.isAsc() ? "ASC" : "DESC";
Attribute uniqueAttribute = getFromOutputTraceabilityMap(indexElement.getColumn(), EnvironmentPackage.Literals.ATTRIBUTE);
if (uniqueAttribute != null) {
AnnotationHelper.setPhysicalUniqueAnnotation(uniqueAttribute, annotationValue);
} else {
// We can only handle the FK situation
if (indexElement.getColumn().isInForeignKey()) {
// Search the reference corresponding to a FK
for (ForeignKey fk : indexElement.getColumn().getForeignKeys()) {
Reference reference = getFromOutputTraceabilityMap(fk, EnvironmentPackage.Literals.REFERENCE);
if (reference != null) {
AnnotationHelper.setPhysicalUniqueAnnotation(reference, annotationValue);
}
}
}
}
} else {
// Add annotation on Table
Entity entity = getFromOutputTraceabilityMap(index.getOwner(), EntityPackage.Literals.ENTITY);
// Retrieve the current value of the annotation.
String annotationValue = AnnotationHelper.getPhysicalUnique(entity);
// Construct the term corresponding to the index being considered.
String annotationTerm = "";
int i = 0;
for (IndexElement indexElement : index.getElements()) {
if (i > 0) {
annotationTerm += ",";
}
annotationTerm += indexElement.getColumn().getName() + ":";
if (indexElement.isAsc()) {
annotationTerm += "ASC";
} else {
annotationTerm += "DESC";
}
i++;
}
if (annotationValue != null && !annotationValue.isEmpty()) {
annotationValue += " | ";
} else if (annotationValue == null) {
annotationValue = "";
}
annotationValue += annotationTerm;
AnnotationHelper.setPhysicalUniqueAnnotation(entity, annotationValue);
}
}
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class DesignServices method isExistingDependency.
/**
* Checks whether a dependency should be displayed between 2 namespaces
* @param source
* @param target
* @return
*/
public static boolean isExistingDependency(Namespace source, Namespace target) {
for (Type type : source.getTypes()) {
if (type instanceof StructuredType) {
StructuredType structuredType = (StructuredType) type;
// Check inheritance
StructuredType supertype = structuredType.getSupertype();
if (supertype != null && target.equals(supertype.eContainer())) {
return true;
}
// Check references
for (Reference reference : structuredType.getOwnedReferences()) {
StructuredType referencedType = reference.getReferencedType();
if (referencedType != null && target.equals(referencedType.eContainer())) {
return true;
}
}
// Check attributes
for (Attribute attribute : structuredType.getOwnedAttributes()) {
DataType datatype = attribute.getType();
if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
return true;
}
}
}
}
return false;
}
Aggregations