use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferencesService method getReferences.
public List<Reference> getReferences(DSemanticDiagram diagram) {
Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
List<Reference> references = new ArrayList<Reference>();
for (StructuredType type : types) {
references.addAll(type.getOwnedReferences());
}
return references;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class ReferencesService method reconnectBidiReferenceSource.
public Reference reconnectBidiReferenceSource(Reference reference, StructuredType source, StructuredType target) {
Reference oppositeOf = reference.getOppositeOf();
// Change container of reference
reference.setContainingType(target);
// Change referencedType for opposite reference
oppositeOf.setReferencedType(target);
reference.setOppositeOf(oppositeOf);
return reference;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class TypesServices method getAllReferencingStructuredTypes.
private Collection<StructuredType> getAllReferencingStructuredTypes(StructuredType referencedType) {
Collection<StructuredType> referencingTypes = new HashSet<StructuredType>();
Session session = new EObjectQuery(referencedType).getSession();
Collection<Setting> inverseReferences = null;
ECrossReferenceAdapter xReferencer = null;
if (session != null) {
xReferencer = session.getSemanticCrossReferencer();
}
if (xReferencer != null) {
inverseReferences = xReferencer.getInverseReferences(referencedType);
} else {
if (referencedType.eResource() != null && referencedType.eResource().getResourceSet() != null) {
inverseReferences = UsageCrossReferencer.find(referencedType, referencedType.eResource().getResourceSet());
}
}
if (inverseReferences != null) {
for (Setting setting : inverseReferences) {
if (setting.getEObject() instanceof StructuredType && setting.getEStructuralFeature() == EnvironmentPackage.Literals.STRUCTURED_TYPE__SUPERTYPE) {
referencingTypes.add((StructuredType) setting.getEObject());
} else if (setting.getEObject() instanceof Reference && setting.getEStructuralFeature() == EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE) {
referencingTypes.add(((Reference) setting.getEObject()).getContainingType());
}
}
}
return referencingTypes;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class TypesServices method createTypesFromOtherTypes.
public Collection<StructuredType> createTypesFromOtherTypes(Namespace namespace, Collection<StructuredType> types, Collection<Reference> references, String sourceTypeName, String targetTypeName) {
String uri = PACKAGES_URI.get(targetTypeName);
EFactory factory = getEFactory(uri);
EPackage ePackage = factory.getEPackage();
EClass eClass = (EClass) ePackage.getEClassifier(targetTypeName);
Map<StructuredType, StructuredType> mappingsTypes = new HashMap<StructuredType, StructuredType>();
Map<Reference, Reference> mappingsReferences = new HashMap<Reference, Reference>();
Collection<StructuredType> result = new ArrayList<StructuredType>();
// Create types
for (StructuredType type : types) {
EObject eObject = factory.create(eClass);
if (eObject instanceof StructuredType) {
StructuredType type2 = (StructuredType) eObject;
type2.setName(type.getName());
type2.getAssociatedTypes().add(type);
type2.setDescription(type.getDescription());
namespace.getTypes().add(type2);
mappingsTypes.put(type, type2);
result.add(type2);
}
}
// Create references
for (Reference reference : references) {
StructuredType sourceType = mappingsTypes.get(reference.getContainingType());
StructuredType targetType = mappingsTypes.get(reference.getReferencedType());
Reference newReference = EnvironmentFactory.eINSTANCE.createReference();
sourceType.getOwnedReferences().add(newReference);
newReference.setReferencedType(targetType);
newReference.setDescription(reference.getDescription());
newReference.setIsComposite(reference.isIsComposite());
newReference.setIsIdentifier(reference.isIsIdentifier());
newReference.setMultiplicity(reference.getMultiplicity());
newReference.setName(reference.getName());
newReference.setNavigable(reference.isNavigable());
mappingsReferences.put(reference, newReference);
}
// Set opposite references
for (Reference reference : references) {
if (reference.getOppositeOf() != null) {
Reference newReference = mappingsReferences.get(reference);
if (newReference.getOppositeOf() == null) {
Reference newOppositeReference = mappingsReferences.get(reference.getOppositeOf());
newReference.setOppositeOf(newOppositeReference);
}
}
}
return result;
}
use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.
the class DBoundElementContentProvider method getDelegatedChildren.
private EObject[] getDelegatedChildren(EObject object) {
if (object instanceof StructuredType) {
StructuredType structuredType = (StructuredType) object;
List<Property> properties = new ArrayList<Property>();
properties.addAll(structuredType.getAttributes());
for (StructuredType associatedType : structuredType.getAssociatedTypes()) {
properties.addAll(associatedType.getAttributes());
}
properties.addAll(structuredType.getReferences());
return (EObject[]) properties.toArray(new EObject[] {});
} else if (object instanceof Reference) {
Reference entityReference = (Reference) object;
if (entityReference.getReferencedType() != null) {
return getDelegatedChildren(entityReference.getReferencedType());
} else {
return new EObject[] {};
}
}
return new EObject[] {};
}
Aggregations