use of org.obeonetwork.dsl.environment.StructuredType 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.StructuredType in project InformationSystem by ObeoNetwork.
the class TypesServices method getAllSelectableExternalStructuredTypes.
public Collection<StructuredType> getAllSelectableExternalStructuredTypes(Namespace namespace, DSemanticDiagram diagram, String typeName) {
Collection<StructuredType> notReferencedTypes = getAllNotReferencedStructuredTypes(namespace, diagram);
// Remove already displayed types
Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
notReferencedTypes.removeAll(types);
Collection<StructuredType> selectableTypes = new ArrayList<StructuredType>();
// Keep only types of the specified typeName
for (StructuredType structuredType : notReferencedTypes) {
if (typeName == null || typeName.isEmpty() || typeName.equals(structuredType.eClass().getName())) {
selectableTypes.add(structuredType);
}
}
return selectableTypes;
}
use of org.obeonetwork.dsl.environment.StructuredType 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.StructuredType 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.StructuredType in project InformationSystem by ObeoNetwork.
the class TypesServices method internalGetAllChildrenStructuredTypes.
private Collection<StructuredType> internalGetAllChildrenStructuredTypes(ObeoDSMObject parent, String typeName) {
Collection<StructuredType> types = new ArrayList<StructuredType>();
TreeIterator<EObject> eAllContents = parent.eAllContents();
while (eAllContents.hasNext()) {
EObject eObject = (EObject) eAllContents.next();
if (eObject instanceof StructuredType) {
// If the type is not specified we do not check on the type
if (typeName == null || typeName.isEmpty() || typeName.equals(eObject.eClass().getName())) {
types.add((StructuredType) eObject);
}
}
}
return types;
}
Aggregations