- 
                Notifications
    You must be signed in to change notification settings 
- Fork 147
Edition_services
        Antonin Abhervé edited this page Sep 3, 2020 
        ·
        1 revision
      
    Modelio v4.0
The edition service provide simple text editors that can be opened to display the contents of a file:
- 
the edition service interface is IEditionService.
- 
the IEditionServiceinstance can be obtained from theIModelioServicesvia the moduleIModuleContext.
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; 6 7IModuleContext ctx = MyModule.getInstance().getModuleContext(); 8IEditionService editionService = ctx.getModelioServices().getEditionService(); 9Element toEdit = ...; 10File fileToEdit = ...; 11EditorType editorType = EditorType.TXTEditor; 12 13IMDATextEditor editor = editionService.openEditor(toEdit, fileToEdit, editorType, false); 14
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 = ... ;
 2
 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  }
 9
10  public void editorClosed(IMDATextEditor anEditor) {
11  }
12});
13