use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter 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.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.
the class DeleteMappingCommand method doExecute.
@Override
protected void doExecute() {
if (bindingEdge.getTarget() != null && bindingEdge.getTarget() instanceof BindingReference) {
BindingReference bindingReference = (BindingReference) bindingEdge.getTarget();
Session session = SessionManager.INSTANCE.getSession(bindingReference);
ECrossReferenceAdapter crossReferencer = session.getSemanticCrossReferencer();
BindingElement left = bindingReference.getLeft();
BindingElement right = bindingReference.getRight();
if (hasNoOtherReference(left)) {
// Delete the useless element
accessor.eDelete(left, crossReferencer);
}
if (hasNoOtherReference(right)) {
// Delete the useless element
accessor.eDelete(right, crossReferencer);
} else {
}
accessor.eDelete(bindingReference, crossReferencer);
accessor.eDelete(bindingEdge, crossReferencer);
bindingEdge.setLeft(null);
bindingEdge.setRight(null);
} else {
EcoreUtil.delete(bindingEdge);
bindingEdge.setLeft(null);
bindingEdge.setRight(null);
}
}
use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.
the class DBindingEditorCreationDescriptionImpl method getMappings.
/**
* {@inheritDoc}
*
* @see org.eclipse.sirius.viewpoint.description.tool.impl.RepresentationCreationDescriptionImpl#getMappings()
* @generated NOT
*/
@Override
public EList<RepresentationElementMapping> getMappings() {
if (this.eResource() == null) {
throw new UnsupportedOperationException();
}
ECrossReferenceAdapter crossReferencer = ECrossReferenceAdapter.getCrossReferenceAdapter(this.eResource().getResourceSet());
if (crossReferencer == null) {
throw new UnsupportedOperationException();
}
final List<RepresentationElementMapping> mappings = new LinkedList<RepresentationElementMapping>();
final Collection<Setting> settings = crossReferencer.getInverseReferences(this, true);
for (final Setting setting : settings) {
final EObject eReferencer = setting.getEObject();
final EStructuralFeature eFeature = setting.getEStructuralFeature();
if (eReferencer instanceof RepresentationElementMapping && eFeature.equals(org.eclipse.sirius.viewpoint.description.DescriptionPackage.eINSTANCE.getRepresentationElementMapping_DetailDescriptions())) {
mappings.add((RepresentationElementMapping) eReferencer);
}
}
return new BasicEList<RepresentationElementMapping>(mappings);
}
use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.
the class DeleteInteractionHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
final Interaction interaction = extractInteraction(event);
if (interaction == null) {
return null;
}
boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete interaction", "Delete the selected interaction ?");
if (confirm) {
final Session session = SessionManager.INSTANCE.getSession(interaction);
final ModelAccessor modelAccessor = session.getModelAccessor();
final ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer();
TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
transactionalEditingDomain.getCommandStack().execute(new RecordingCommand(transactionalEditingDomain) {
@Override
protected void doExecute() {
// Retrieve associated representations
Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(interaction, session);
// Delete representations
for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
closeEditor(session, representationDescriptor.getRepresentation());
DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
}
// Delete interaction
modelAccessor.eDelete(interaction, semanticCrossReferencer);
}
});
}
return null;
}
use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.
the class RequirementService method getLinkedRequirements.
private static Set<Requirement> getLinkedRequirements(Session session, EObject eObject) {
ECrossReferenceAdapter crossReferenceAdapter = session.getSemanticCrossReferencer();
HashSet<Requirement> linkedRequirements = new HashSet<Requirement>();
for (Setting setting : crossReferenceAdapter.getInverseReferences(eObject)) {
if (setting.getEObject() instanceof Requirement) {
Requirement requirement = (Requirement) setting.getEObject();
// duplicates
if (requirement.getReferencedObject().contains(eObject)) {
linkedRequirements.add(requirement);
}
}
}
return linkedRequirements;
}
Aggregations