From f64066583bc74c86e4523aeb343bcca23373be41 Mon Sep 17 00:00:00 2001 From: Phillipus Date: Tue, 31 Dec 2024 11:14:57 +0000 Subject: [PATCH] Ensure editor parts are active when calling "Save As" - 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". --- .../editor/model/impl/EditorModelManager.java | 4 ++++ .../editor/ui/services/EditorManager.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/model/impl/EditorModelManager.java b/com.archimatetool.editor/src/com/archimatetool/editor/model/impl/EditorModelManager.java index 764fc93f9..7aa3a5233 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/model/impl/EditorModelManager.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/model/impl/EditorModelManager.java @@ -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); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/services/EditorManager.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/services/EditorManager.java index 60b239b0c..6de62e3c2 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/services/EditorManager.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/services/EditorManager.java @@ -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