Search in sources :

Example 81 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project Palladio-Editors-Sirius by PalladioSimulator.

the class AddLinkingResourceAction method execute.

@Override
public void execute(final Collection<? extends EObject> selections, final Map<String, Object> parameters) {
    final Object parameter = parameters.get(NEW_COMMUNICATION_LINK_RESOURCE_SPECIFICATION);
    if (parameter == null || !(parameter instanceof CommunicationLinkResourceSpecification)) {
        return;
    }
    final CommunicationLinkResourceSpecification communicationLinkResourceSpecification = (CommunicationLinkResourceSpecification) parameter;
    // latency
    final PCMRandomVariable latency = getRandomVariableFromStoExDialog(LATENCY_DISPLAY_TITLE);
    if (latency == null) {
        return;
    }
    communicationLinkResourceSpecification.setLatency_CommunicationLinkResourceSpecification(latency);
    // throughput
    final PCMRandomVariable throughput = getRandomVariableFromStoExDialog(THROUGHPUT_DISPLAY_TITLE);
    if (throughput == null) {
        return;
    }
    communicationLinkResourceSpecification.setThroughput_CommunicationLinkResourceSpecification(throughput);
    // Communication Link
    Session session = SessionManager.INSTANCE.getSession(communicationLinkResourceSpecification);
    URI uri = URI.createURI("pathmap://PCM_MODELS/Palladio.resourcetype");
    Resource palladioResources = SiriusCustomUtil.getResourceByURI(uri, session);
    if (palladioResources != null) {
        ResourceRepository rep = (ResourceRepository) palladioResources.getContents().iterator().next();
        for (EObject o : rep.eContents()) {
            if ((o instanceof CommunicationLinkResourceType) && ((CommunicationLinkResourceType) o).getEntityName().equals("LAN")) {
                communicationLinkResourceSpecification.setCommunicationLinkResourceType_CommunicationLinkResourceSpecification((CommunicationLinkResourceType) o);
                break;
            }
        }
    }
}
Also used : CommunicationLinkResourceSpecification(org.palladiosimulator.pcm.resourceenvironment.CommunicationLinkResourceSpecification) EObject(org.eclipse.emf.ecore.EObject) CommunicationLinkResourceType(org.palladiosimulator.pcm.resourcetype.CommunicationLinkResourceType) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) ResourceRepository(org.palladiosimulator.pcm.resourcetype.ResourceRepository) URI(org.eclipse.emf.common.util.URI) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) Session(org.eclipse.sirius.business.api.session.Session)

Example 82 with Resource

use of org.eclipse.emf.ecore.resource.Resource 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 83 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project Palladio-Editors-Sirius by PalladioSimulator.

the class CreateModelCommand method doExecute.

@Override
protected void doExecute() {
    final Resource resource = resourceSet.createResource(modelURI);
    resource.getContents().add(modelObject);
    try {
        resource.save(Collections.EMPTY_MAP);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException)

Example 84 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project Palladio-Editors-Sirius by PalladioSimulator.

the class ResourceSelectorPage method getResult.

protected EObject getResult(Session session) {
    EObject result = null;
    URI uri = URI.createURI(path, true);
    TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
    ResourceSet resourceSet = domain.getResourceSet();
    try {
        Resource resource = resourceSet.getResource(uri, true);
        result = (EObject) resource.getContents().get(0);
    } catch (WrappedException ex) {
    // do nothing
    }
    return result;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 85 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.

the class ConvertJavaCode method doConvert.

private void doConvert(final Set<ICompilationUnit> compilationUnits, IProgressMonitor monitor, Map<ICompilationUnit, ConversionResult> conversionResults) throws ExecutionException, InterruptedException {
    for (ICompilationUnit iCompilationUnit : compilationUnits) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        JavaConverter converter = converterProvider.get();
        ConversionResult conversionResult = converter.toXtend(iCompilationUnit);
        monitor.subTask("Working with " + iCompilationUnit.getElementName());
        if (!conversionResult.getProblems().iterator().hasNext()) {
            IFile file = xtendFileToCreate(iCompilationUnit);
            Resource resource = createResource(file, conversionResult.getXtendCode());
            if (!validateResource(resource)) {
                monitor.subTask("Conversion was not successfull. Re-trying with another strategy.");
                conversionResult = converter.useRobustSyntax().toXtend(iCompilationUnit);
            }
        }
        conversionResults.put(iCompilationUnit, conversionResult);
        monitor.worked(1);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ConversionResult(org.eclipse.xtend.core.javaconverter.JavaConverter.ConversionResult) IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) JavaConverter(org.eclipse.xtend.core.javaconverter.JavaConverter)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)448 Test (org.junit.Test)210 XtextResource (org.eclipse.xtext.resource.XtextResource)157 EObject (org.eclipse.emf.ecore.EObject)109 URI (org.eclipse.emf.common.util.URI)85 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)76 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)71 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)66 StringInputStream (org.eclipse.xtext.util.StringInputStream)50 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)45 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)36 IOException (java.io.IOException)26 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)24 List (java.util.List)23 EClass (org.eclipse.emf.ecore.EClass)23 EPackage (org.eclipse.emf.ecore.EPackage)23 InternalEObject (org.eclipse.emf.ecore.InternalEObject)23 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)21 ArrayList (java.util.ArrayList)19 IFile (org.eclipse.core.resources.IFile)18