diff options
author | Laurent Redor | 2020-08-21 17:59:27 +0000 |
---|---|---|
committer | Laurent Redor | 2020-09-21 07:29:04 +0000 |
commit | b1f430b5c982c5b6ddbb33afe8f57483599bb744 (patch) | |
tree | 79a97099939eb7670a8a04283dfbda375e7f7ffe /plugins | |
parent | 2ba0bac52739173c96fa9cca078607c0fb21ea33 (diff) | |
download | org.eclipse.sirius-b1f430b5c982c5b6ddbb33afe8f57483599bb744.tar.gz org.eclipse.sirius-b1f430b5c982c5b6ddbb33afe8f57483599bb744.tar.xz org.eclipse.sirius-b1f430b5c982c5b6ddbb33afe8f57483599bb744.zip |
[566349] Add a preClose method for DialectEditor
This commit also implements specific cleaning for DiagramEditor.
Bug: 566349
Change-Id: I3eb313f8bd660458d1339c62b2fcc39494812bcc
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
Diffstat (limited to 'plugins')
6 files changed, 91 insertions, 4 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java index fe6db87d01..4c88f611c1 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java @@ -295,6 +295,22 @@ public class DiagramDialectUIServices implements DialectUIServices { } try { + // Call a preClose in sync mode before calling the real close that is done in async + if (editorPart instanceof DialectEditor) { + Display display = Display.getCurrent(); + if (display == null) { + display = PlatformUI.getWorkbench().getDisplay(); + } + if (!display.isDisposed()) { + display.syncExec(new Runnable() { + public void run() { + if (!PlatformUI.getWorkbench().isClosing()) { + ((DialectEditor) editorPart).preClose(); + } + } + }); + } + } ((DiagramDocumentEditor) editorPart).close(save); } catch (final NullPointerException e) { // we might have an exception closing an editor which is diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusDiagramActionBarContributor.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusDiagramActionBarContributor.java index cff1039785..a469a0a5df 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusDiagramActionBarContributor.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/part/SiriusDiagramActionBarContributor.java @@ -65,6 +65,8 @@ import org.osgi.framework.Version; */ public class SiriusDiagramActionBarContributor extends DiagramActionBarContributor { + boolean disposed; + /** * @was-generated */ @@ -464,4 +466,16 @@ public class SiriusDiagramActionBarContributor extends DiagramActionBarContribut private boolean isOldUIEnabled() { return Platform.getPreferencesService().getBoolean(DiagramUIPlugin.ID, SiriusDiagramUiPreferencesKeys.PREF_OLD_UI.name(), false, null); } + + @Override + public void dispose() { + // In Sirius, we called the dispose in method + // org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl.preClose() to be sure that the + // actions are not "refreshed" after the async close of an editor. But when the editor is really closed, the + // dispose would be called a second time (not necessary). + if (!disposed) { + disposed = true; + super.dispose(); + } + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java index c4679a3731..c4e84c4849 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java @@ -53,6 +53,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.impl.TransactionImpl; import org.eclipse.emf.workspace.IWorkspaceCommandStack; import org.eclipse.gef.DefaultEditDomain; +import org.eclipse.gef.Disposable; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.GraphicalViewer; @@ -225,6 +226,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorReference; @@ -241,7 +243,9 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.Saveable; +import org.eclipse.ui.SubActionBars; import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.internal.PartSite; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.part.IPage; import org.eclipse.ui.views.contentoutline.ContentOutline; @@ -2029,4 +2033,37 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE public void rebuildStatusLine() { super.rebuildStatusLine(); } + + /** + * This method dispose all the actions that can be potentially be notified between the asking of closing of an + * editor and the real closing of it. Indeed the close of an editor is done in async and in case of a server lost, + * with Sirius used in a collaborative context, these actions can be notified/refreshed with a wrong context causing + * a lot of exceptions. + */ + @Override + public void preClose() { + // Dispose the tabbar (and all associated actions) + if (getTabbar() != null) { + getTabbar().dispose(); + setTabbar(null); + } + // Dispose the actions of "standard Eclipse" + if (getSite() instanceof PartSite) { + IActionBars actionBars = ((PartSite) getSite()).getActionBars(); + if (actionBars instanceof SubActionBars) { + ((SubActionBars) actionBars).dispose(); + } else { + ((PartSite) getSite()).deactivateActionBars(false); + } + } + // Dispose all the action registered as dependent on changes in the workbench's {@link ISelectionService} + for (Object actionID : getSelectionActions()) { + if (actionID instanceof String) { + IAction action = getActionRegistry().getAction(actionID); + if (action instanceof Disposable) { + ((Disposable) action).dispose(); + } + } + } + } } diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 7cb99a57e2..056bc85d13 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -164,6 +164,15 @@ } </code></pre> + <h4 id="Changesinorg.eclipse.sirius.ui">Changes in + <code>org.eclipse.sirius.ui</code> + </h4> + <ul> + <li><span class="label label-success">Added</span> A new method, + <code>preClose()</code> has been added in + <code>org.eclipse.sirius.ui.business.api.dialect.DialectEditor</code>. This method is called in sync when the editor is asking to be closed (the real close is done in async). This allows to dispose actions, for example, as soos as the close is requested. There is a default implementation, that does nothing, for all dialect editors. + </li> + </ul> <h4 id="Changesinorg.eclipse.sirius.tests.junit.support">Changes in <code>org.eclipse.sirius.tests.junit.support</code> </h4> @@ -1119,7 +1128,7 @@ <code>org.eclipse.sirius.business.internal.metamodel.description.validation.operations.ValidationRuleOperations</code> class. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -1559,7 +1568,7 @@ <code>DDiagram</code>. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui3">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 8214d779d4..2f3e815582 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -24,6 +24,10 @@ try { } } +h4. Changes in @org.eclipse.sirius.ui@ + +* <span class="label label-success">Added</span> A new method, @preClose()@ has been added in @org.eclipse.sirius.ui.business.api.dialect.DialectEditor@. This method is called in sync when the editor is asking to be closed (the real close is done in async). This allows to dispose actions, for example, as soos as the close is requested. There is a default implementation, that does nothing, for all dialect editors. + h4. Changes in @org.eclipse.sirius.tests.junit.support@ * <span class="label label-success">Added</span> New methods have been added to @org.eclipse.sirius.tests.support.api.TestsUtil@ to check the current Java runtime version. The parameter is the expected version of Java, i.e: ...7, 8, 9, ..., 13, 14, ... diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectEditor.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectEditor.java index b254528e19..3a61b2dc56 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectEditor.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/DialectEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2020 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -65,5 +65,12 @@ public interface DialectEditor extends ISiriusEditor { * @since 0.9.0 */ DialectEditorDialogFactory getDialogFactory(); - + + /** + * Method that is called in sync when the editor is asking to be closed (the real close is done in async). This + * allows to dispose actions, for example, as soos as the close is requested. + */ + default void preClose() { + // Do nothing by default; + } } |