Menu

ResourceConverterExample

Tom Swain
Attachments

The following describes how to have EMF resources automatically converted to different resources when using the "save as" command in the EMF generated editor. Attached is the source for creating a resource conversion class. It is suggested that a class similar to the one attached be used.

To intercept the resource during the "save as" process, insert the following code in generated editor code doSaveAs(URI uri, IEditorInput editorInput) method:

protected void doSaveAs(URI uri, IEditorInput editorInput) {
  //  add the following five lines line
  List<Resource> resources = editingDomain.getResourceSet().getResources();
  RealResourceConverter rrc = new RealResourceConverter(resources.get(0));
  Resource newResource = rrc.convert(uri);
  resources.set(0, newResource);
  contentOutlineViewer.setInput(newResource);

  (editingDomain.getResourceSet().getResources().get(0)).setURI(uri);
  setInputWithNotify(editorInput);
  ...
}

Note: Make sure the correct "doSaveAs" method (the one with parameters) is overridden, and that the "@generated" annotation is set to "NOT".


Related

Wiki: Home

MongoDB Logo MongoDB