Edition services

Modelio v3.6

The edition service provide simple text editors that can be opened to display the contents of a file:

Open a text editor

A text editor can be opened on a (model element, file) association pair by using the openEditor() method service of IEditionService. Being coupled to a model element, the editor will automatically close if the element is deleted.

Here is an example how to invoke a text editor:

 1import org.modelio.api.editor.EditorType;
 2import org.modelio.api.editor.IEditionService;
 3import org.modelio.api.editor.IMDATextEditor;
 4import org.modelio.api.modelio.Modelio;
 5import org.modelio.metamodel.uml.infrastructure.ModelElement;
 7IModuleContext ctx = MyModule.getInstance().getModuleContext();
 8IEditionService editionService = ctx.getModelioServices().getEditionService();
 9Element toEdit = ...;
10File fileToEdit = ...;
11EditorType editorType = EditorType.TXTEditor;
13IMDATextEditor editor = editionService.openEditor(toEdit, fileToEdit, editorType, false);

React to save and close of an editor

A listener can be put on the editor to be notified when the editor is saved or closed. Then the file content can be retrieved, parsed or reversed.

 1IMDATextEditor editor = ... ;
 3editor.setListener( new IMDAEditorListener() {
 4  public void documentSaved(IMDATextEditor anEditor) {
 5    // retrieve file content in the model here
 6    File savedFile = editor.getFile();
 7    ...
 8  }
10  public void editorClosed(IMDATextEditor anEditor) {
11  }