Search code examples
javasaveeclipse-emfemf

How to save an EMF model to a hierarchy of folders and files


I am implementing a commercial RCP application where the user can create projects for example of this format:

  • Project1
    • SubElement1
    • SubElement2
      • SubSubElement1
  • Project2
  • ....

etc.

I am using EMF to model the data domain and I want to save the data.I want to have a hierarchy of folders and files for each project e.g. Folder 1 should be Project1 containing a Folder SubElement1 which contains some xml files. etc.

I found examples to save EMF models but I didn't figure out how to save this folder-files hierarchy under one EMF resource...


Solution

  • There is no way spreading a single resource across multiple files. In spite of that, EMF provides you a mechanism for working with parts/multiple instance of a model through ResourceSet. What's more, you can even have a cross-references between multiple models in multiple files.

    Another advice for you, is using Eclipse Resource API for managing creation of folder and files in workspace, and let EMF deal with all the model stuff. That's how we are doing it in our project.