Changes between Initial Version and Version 1 of SplitDomainFile


Ignore:
Timestamp:
Oct 7, 2008, 3:53:45 PM (17 years ago)
Author:
jdamerow
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SplitDomainFile

    v1 v1  
     1= Split domain file =
     2
     3[wiki:gmf:gmf <back]
     4
     5Scenario: Root element {{{A}}} contains element {{{B}}} and element {{{C}}}.  Element {{{C}}} is to be saved in a separate domain file.
     6
     7Solution:
     8  - Create an element {{{CReference}}}.
     9  - {{{CReference}}} contains an element {{{C}}} with {{{containment=false}}}.
     10  - Override method {{{doDefaultElementCreation()}}} in class {{{CReferenceCreateCommand}}}. This method contains the creation of the corresponding element {{{C}}}, similar to the following:
     11{{{
     12// create CReference-Object
     13EObject cReference = super.doDefaultElementCreation();
     14
     15// get resource of root element A
     16Resource aResource = getElementToEdit().eResource();
     17
     18// create C object
     19C c = ExampleFactory.eINSTANCE.createC();
     20
     21// add c to cReference
     22((CReference)cReference).setC(c);
     23
     24// create model file for C
     25File cFile = new File(pathToCFile);
     26if (!cFile.exists())
     27   try {
     28        cFile.createNewFile();
     29   } catch (IOException e) {
     30        // TODO Auto-generated catch block
     31        e.printStackTrace();
     32   }
     33
     34// create resource for c
     35Resource cResource = aResource.getResourceSet().createResource(
     36        URI.createFileURI(cFile.getAbsolutePath()));
     37
     38// add c to new cResource
     39cResource.getContents().add(c);
     40
     41// save resource; this will also be done by the save command of the generated editor unless you reduce the save command
     42try {
     43   cResource.save(ExampleDiagramEditorUtil.getSaveOptions());
     44} catch (IOException e) {
     45   // TODO Auto-generated catch block
     46   e.printStackTrace();
     47}
     48}}}