Search in sources :

Example 1 with EObjectQuery

use of org.eclipse.sirius.business.api.query.EObjectQuery in project Palladio-Editors-Sirius by PalladioSimulator.

the class SetFailureType method execute.

@Override
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
    InternalFailureOccurrenceDescription element = (InternalFailureOccurrenceDescription) parameters.get("instance");
    EObjectQuery query = new EObjectQuery(element);
    Collection<Resource> resources = query.getSession().getSemanticResources();
    boolean found = false;
    Resource resource = null;
    for (Resource r : resources) {
        if (r.getURI().equals(URI.createURI("pathmap://PCM_MODELS/FailureTypes.repository"))) {
            found = true;
            resource = r;
            break;
        }
    }
    if (found) {
        Repository rep = (Repository) resource.getContents().iterator().next();
        for (EObject o : rep.eContents()) {
            FailureType failureType = (FailureType) o;
            if (failureType.getEntityName().equals("SoftwareInducedFailure")) {
                element.setSoftwareInducedFailureType__InternalFailureOccurrenceDescription(((SoftwareInducedFailureType) failureType));
                break;
            }
        }
    }
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) Repository(org.palladiosimulator.pcm.repository.Repository) SoftwareInducedFailureType(org.palladiosimulator.pcm.reliability.SoftwareInducedFailureType) FailureType(org.palladiosimulator.pcm.reliability.FailureType) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) InternalFailureOccurrenceDescription(org.palladiosimulator.pcm.reliability.InternalFailureOccurrenceDescription) SoftwareInducedFailureType(org.palladiosimulator.pcm.reliability.SoftwareInducedFailureType)

Example 2 with EObjectQuery

use of org.eclipse.sirius.business.api.query.EObjectQuery 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;
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Reference(org.obeonetwork.dsl.environment.Reference) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) StructuredType(org.obeonetwork.dsl.environment.StructuredType) HashSet(java.util.HashSet) Session(org.eclipse.sirius.business.api.session.Session)

Example 3 with EObjectQuery

use of org.eclipse.sirius.business.api.query.EObjectQuery in project InformationSystem by ObeoNetwork.

the class AbstractUserStoryDecorator method getAnalysis.

/**
 * Retrieves the DAnalysis instance from a diagram edit part
 * @param diagramEditPart Diagram edit part corresponding to an element on a viewpoint diagram
 * @return the DAnalysis instance
 */
private static DAnalysis getAnalysis(IDiagramElementEditPart diagramEditPart) {
    EObject viewpointNode = diagramEditPart.resolveSemanticElement();
    // if there is no GMF semantic element, we won't be able to retrieve a DAnalysis
    if (viewpointNode != null) {
        Session session = null;
        // First, try to retrieve the session using the sirius semantic element
        if (viewpointNode instanceof DSemanticDecorator) {
            EObject semanticElement = ((DSemanticDecorator) viewpointNode).getTarget();
            if (semanticElement != null) {
                session = new EObjectQuery(semanticElement).getSession();
            }
        }
        // If it didn't work, let's try using the sirius graphical element
        if (session == null) {
            session = new EObjectQuery(viewpointNode).getSession();
        }
        // If we were able to retrieve a session, let's get the root DAnalysis
        if (session != null) {
            EObject analysisEObject = session.getSessionResource().getContents().get(0);
            if (analysisEObject instanceof DAnalysis) {
                return (DAnalysis) analysisEObject;
            }
        }
        // Nothing worked, let's check if the EMF root element is a DAnalysis
        EObject container = EcoreUtil.getRootContainer(viewpointNode);
        if (container != null && container instanceof DAnalysis) {
            return (DAnalysis) container;
        }
    }
    return null;
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) EObject(org.eclipse.emf.ecore.EObject) DAnalysis(org.eclipse.sirius.viewpoint.DAnalysis) Session(org.eclipse.sirius.business.api.session.Session)

Example 4 with EObjectQuery

use of org.eclipse.sirius.business.api.query.EObjectQuery in project InformationSystem by ObeoNetwork.

the class UnlinkRequirementAction method run.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
    MessageDialog dialog = new MessageDialog(linksView.getSite().getShell(), // $NON-NLS-1$
    RequirementLinkerPlugin.getInstance().getString("DeleteRequirementLinkAction_ConfirmDialog_title"), null, // $NON-NLS-1$
    RequirementLinkerPlugin.getInstance().getString("DeleteRequirementLinkAction_ConfirmDialog_msg"), MessageDialog.CONFIRM, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 1);
    boolean openConfirm = dialog.open() == Window.OK;
    if (openConfirm) {
        Session session = new EObjectQuery(linksView.getInput()).getSession();
        if (session != null) {
            TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
            RecordingCommand cmd = new // $NON-NLS-1$
            RecordingCommand(// $NON-NLS-1$
            editingDomain, // $NON-NLS-1$
            "UnLink Requirements") {

                protected void doExecute() {
                    for (EObjectLink link : linksView.getSelectedEntries()) {
                        if (link instanceof RequirementLink) {
                            RequirementLink reqLink = (RequirementLink) link;
                            reqLink.getRequirement().getReferencedObject().remove(linksView.getInput());
                        }
                    }
                }
            };
            editingDomain.getCommandStack().execute(cmd);
        }
        linksView.refresh();
    }
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) EObjectLink(org.obeonetwork.tools.linker.EObjectLink) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) RequirementLink(org.obeonetwork.tools.requirement.core.RequirementLink) Session(org.eclipse.sirius.business.api.session.Session)

Example 5 with EObjectQuery

use of org.eclipse.sirius.business.api.query.EObjectQuery in project InformationSystem by ObeoNetwork.

the class BindingService method getRelatedBindingInfos.

private Collection<BindingInfo> getRelatedBindingInfos(StructuredType structuredType) {
    EObjectQuery query = new EObjectQuery(structuredType);
    Collection<EObject> targets = new HashSet<EObject>();
    targets.addAll(query.getInverseReferences(EnvironmentPackage.Literals.BINDING_INFO__LEFT));
    targets.addAll(query.getInverseReferences(EnvironmentPackage.Literals.BINDING_INFO__RIGHT));
    Collection<BindingInfo> bindingInfos = new ArrayList<BindingInfo>();
    for (EObject target : targets) {
        if (target instanceof BindingInfo) {
            bindingInfos.add((BindingInfo) target);
        }
    }
    return bindingInfos;
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) EObject(org.eclipse.emf.ecore.EObject) BindingInfo(org.obeonetwork.dsl.environment.BindingInfo) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

EObjectQuery (org.eclipse.sirius.business.api.query.EObjectQuery)7 Session (org.eclipse.sirius.business.api.session.Session)5 EObject (org.eclipse.emf.ecore.EObject)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 DAnalysis (org.eclipse.sirius.viewpoint.DAnalysis)2 DSemanticDecorator (org.eclipse.sirius.viewpoint.DSemanticDecorator)2 LinkedHashSet (java.util.LinkedHashSet)1 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)1 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 View (org.eclipse.gmf.runtime.notation.View)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DAnalysisSessionEObject (org.eclipse.sirius.viewpoint.DAnalysisSessionEObject)1 BindingInfo (org.obeonetwork.dsl.environment.BindingInfo)1 Reference (org.obeonetwork.dsl.environment.Reference)1