Version 1 (modified by 16 years ago) (diff) | ,
---|
Split domain file
Scenario: Root element A
contains element B
and element C
. Element C
is to be saved in a separate domain file.
Solution:
- Create an element
CReference
. CReference
contains an elementC
withcontainment=false
.- Override method
doDefaultElementCreation()
in classCReferenceCreateCommand
. This method contains the creation of the corresponding elementC
, similar to the following:// create CReference-Object EObject cReference = super.doDefaultElementCreation(); // get resource of root element A Resource aResource = getElementToEdit().eResource(); // create C object C c = ExampleFactory.eINSTANCE.createC(); // add c to cReference ((CReference)cReference).setC(c); // create model file for C File cFile = new File(pathToCFile); if (!cFile.exists()) try { cFile.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // create resource for c Resource cResource = aResource.getResourceSet().createResource( URI.createFileURI(cFile.getAbsolutePath())); // add c to new cResource cResource.getContents().add(c); // save resource; this will also be done by the save command of the generated editor unless you reduce the save command try { cResource.save(ExampleDiagramEditorUtil.getSaveOptions()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }