Search in sources :

Example 26 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project ow by vtst.

the class LessLabelProvider method text.

StyledString text(StyleSheet obj) {
    // We are careful about null, because we don't know all possible cases.
    Resource resource = obj.eResource();
    String label = messages.getString("stylesheet");
    if (resource != null) {
        URI uri = resource.getURI();
        if (uri != null)
            label = (label + " [" + uri.lastSegment() + "]");
    }
    return new StyledString(label, rootStyler);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) URI(org.eclipse.emf.common.util.URI)

Example 27 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project benchmarx by eMoflon.

the class EMoflonFamiliesToPersons method saveModels.

public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 28 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersons method initiateSynchronisationDialogue.

/**
	 * Initiates a synchronization between a source and a target model. The medini QVT engine is initialized,
	 * the required metamodels are registered and empty source and target models are created.
	 * Finally a FamilyRegister is added to the source model and an initial forward transformation is issued
	 * to create a corresponding PersonRegister.
	 */
@Override
public void initiateSynchronisationDialogue() {
    // delete content of traces folder
    File tracesFolder = new File("./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/traces");
    final File[] files = tracesFolder.listFiles();
    if (files != null) {
        for (File f : files) {
            if (f != null)
                f.delete();
        }
    }
    // Initialise resource set of models
    this.resourceSet = new ResourceSetImpl();
    this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Collect all necessary packages from the metamodel(s)
    Collection<EPackage> metaPackages = new ArrayList<EPackage>();
    this.collectMetaModels(metaPackages);
    // Make these packages known to the QVT engine
    init(metaPackages);
    // Create resources for models
    source = resourceSet.createResource(URI.createURI("source.xmi"));
    target = resourceSet.createResource(URI.createURI("target.xmi"));
    // Collect the models, which should participate in the transformation.
    // You can provide a list of models for each direction.
    // The models must be added in the same order as defined in your transformation!
    Collection<Collection<Resource>> modelResources = new ArrayList<Collection<Resource>>();
    Collection<Resource> firstSetOfModels = new ArrayList<Resource>();
    Collection<Resource> secondSetOfModels = new ArrayList<Resource>();
    Collection<Resource> thirdSetOfModels = new ArrayList<Resource>();
    modelResources.add(firstSetOfModels);
    modelResources.add(secondSetOfModels);
    modelResources.add(thirdSetOfModels);
    firstSetOfModels.add(source);
    secondSetOfModels.add(target);
    URI directory = URI.createFileURI(basePath + "traces");
    this.preExecution(modelResources, directory);
    source.getContents().add(FamiliesFactory.eINSTANCE.createFamilyRegister());
    launchFWD();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) File(java.io.File) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage)

Example 29 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersons method saveModels.

/**
	 * Allows to save the current state of the source and target models
	 * 
	 * @param name : Filename 
	 */
public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 30 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project benchmarx by eMoflon.

the class EMFUtil method loadExpectedResource.

public static Resource loadExpectedResource(String path, ResourceSet resourceSet) {
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    Resource resource = resourceSet.createResource(URI.createFileURI("resources/" + path + ".xmi"));
    try {
        resource.load(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return resource;
}
Also used : XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)58 URI (org.eclipse.emf.common.util.URI)23 IOException (java.io.IOException)18 IResource (org.eclipse.core.resources.IResource)11 EObject (org.eclipse.emf.ecore.EObject)10 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)10 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)9 PersistenceException (org.talend.commons.exception.PersistenceException)8 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)8 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)7 List (java.util.List)6 IProject (org.eclipse.core.resources.IProject)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IFile (org.eclipse.core.resources.IFile)5 TalendXMIResource (org.talend.commons.runtime.model.emf.TalendXMIResource)5 ByteArrayResource (org.talend.core.model.properties.helper.ByteArrayResource)5 CwmResource (org.talend.model.emf.CwmResource)5