Skip to content

Commit

Permalink
Ensure editor parts are active when calling "Save As"
Browse files Browse the repository at this point in the history
- If more than one editor part for a model is open but not activated, when Save As is called the inactive editor parts will reference the model's previous file name (stored in a persistence memento) and when re-opened will show the "This View is no longer available" error message on the editor part.

- The workaround is to activate all editor parts for that model before calling "Save As".
  • Loading branch information
Phillipus committed Jan 1, 2025
1 parent 1fd45b6 commit f640665
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ public boolean saveModelAs(IArchimateModel model) throws IOException {
return false;
}

// Activate inactive editor parts now otherwise they will reference the previous file name stored in the part's persistence memento
// and when re-activated show a blank editor part and a "This View is no longer available" message.
EditorManager.activateDiagramEditors(model);

// Set new file
model.setFile(file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ public static void closeDiagramEditors(IArchimateModel model) {
}
}

/**
* Activate all Diagram Editor Parts for a model in order to update their memento save state
* Called by "Save As" so that inactive editor parts are not left with old file references when re-opening them.
*/
public static void activateDiagramEditors(IArchimateModel model) {
if(model == null || !PlatformUI.isWorkbenchRunning()) {
return;
}

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for(IEditorReference ref : page.getEditorReferences()) {
try {
if(ref.getEditorInput() instanceof DiagramEditorInput input && input.getDiagramModel().getArchimateModel() == model) {
ref.getEditor(true);
}
}
catch(PartInitException ex) {
ex.printStackTrace();
}
}
}

/**
* @param diagramModel
* @return All editor references that have diagramModel in their editor input
Expand Down

0 comments on commit f640665

Please sign in to comment.