Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Monnier2019-09-18 04:59:52 -0400
committerLaurent Fasani2019-09-20 05:40:31 -0400
commit4b5dcf59ebba9c0e254289138599ba916d9b203c (patch)
tree11fba892cefb482d5804879fea98bd821a15c47f
parent9ce8d730dcfad7c788579a56eebb4504fe9ddf90 (diff)
downloadorg.eclipse.sirius-master.tar.gz
org.eclipse.sirius-master.tar.xz
org.eclipse.sirius-master.zip
[551184] Clean Diagram editor from selection service listenersHEADmaster
Diagram editor dispose now removes itself from listeners if the diagram was in a newly created distant resource that has been removed (Discard) Bug: 551184 Change-Id: Ib3b9d769f0b0d77cbc076be197825e01c6ae4490 Signed-off-by: Steve Monnier <steve.monnier@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java16
1 files changed, 16 insertions, 0 deletions
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 69b810da5f..b8d17ade9e 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
@@ -31,6 +31,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
@@ -110,6 +111,7 @@ import org.eclipse.sirius.business.api.session.SessionListener;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.business.api.session.SessionManagerListener;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
+import org.eclipse.sirius.common.tools.api.util.ReflectionHelper;
import org.eclipse.sirius.common.tools.api.util.StringUtil;
import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil;
import org.eclipse.sirius.common.ui.tools.api.util.IObjectActionDelegateWrapper;
@@ -230,6 +232,7 @@ import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.ISaveablePart2;
import org.eclipse.ui.ISaveablesSource;
import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
@@ -921,6 +924,19 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE
// If possible, remove the diagram event broker for the listening of the
// transactional editing domain
stopDiagramEventBrokerListener(getEditingDomain());
+ removeSelfFromListeners();
+ }
+
+ /**
+ * This editor has been noticed to not being properly removed from the list of listener if the diagram is in a newly
+ * created distant resource that has been removed (discarded).
+ */
+ private void removeSelfFromListeners() {
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ Optional<Object> fieldValueWithoutException = ReflectionHelper.getFieldValueWithoutException(selectionService, "listeners"); //$NON-NLS-1$
+ if (selectionService != null && fieldValueWithoutException.isPresent() && fieldValueWithoutException.filter(ListenerList.class::isInstance).isPresent()) {
+ selectionService.removeSelectionListener(this);
+ }
}
@Override

Back to the top