Yesterday we looked at how to force an update of a given editor programmatically. I mentioned that this may be necessary if the editor renders content that does not originate from a model and does not detect an update.

In this case, however, you usually want to update all open editors, not just the current one. But how do you retrieve a list of all open editors?

Here is the code to do that:

FileEditorManager.getInstance(ProjectHelper.toIdeaProject(mpsProject))
    .getAllEditors()
    .asSequence
    .ofType<MPSFileNodeEditor>
    .select({~it => it.getNodeEditor().getCurrentEditorComponent(); })

A lot is happening in this expression so let’s examine it part by part:

  • FileEditorManager.getInstance(...) retrieves the instance of the IDEA component that is responsible for managing a list of open editors.
  • ProjectHelper.toIdeaProject(mpsProject) retrieves the IDEA project associated with an MPS project, in case you don’t have the IDEA project in your context.
  • getAllEditors() retrieves all editors known to the FileEditorManager component. This returns an array of FileEditor objects. FileEditor is an abstraction that includes text-based and MPS projectional editors.
  • asSequence converts an array to a sequence from the collections language so that the collection operations can be used on it later on.
  • ofType<MPSFileNodeEditor> filters the sequence to include only projectional editors.
  • MPSFileNodeEditor#getNodeEditor() retrieves the NodeEditor which is an abstraction over simple and tabbed MPS editors (such as used for language concepts with aspect tabs).
  • getCurrentEditorComponent() finally retrieves the EditorComponent that the given editor is showing.

The result of the expression is a sequence of EditorComponent objects that are currently open in the main editor area. This does not include the editor component of the MPS Console or the Inspector.