From 2a6be8bf70a810215e377cb3498465884f9f3c49 Mon Sep 17 00:00:00 2001 From: Maxime Porhel Date: Mon, 9 Sep 2024 16:21:44 +0200 Subject: [PATCH] #2894 Avoid potential deadlocks in refresh Change-Id: I653a0e579d58abf71f44ceb8eb85179cc07d5eb5 Signed-off-by: Maxime Porhel --- .../core/sirius/analysis/DiagramServices.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/DiagramServices.java b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/DiagramServices.java index 4d5a4adcb5..e056ab0ec1 100644 --- a/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/DiagramServices.java +++ b/core/plugins/org.polarsys.capella.core.sirius.analysis/src/org/polarsys/capella/core/sirius/analysis/DiagramServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2023 THALES GLOBAL SERVICES. + * Copyright (c) 2006, 2024 THALES GLOBAL SERVICES and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -9,6 +9,7 @@ * * Contributors: * Thales - initial API and implementation + * Maxime Porhel (Obeo) - Avoid potential deadlocks in refresh *******************************************************************************/ package org.polarsys.capella.core.sirius.analysis; @@ -93,6 +94,8 @@ import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; import org.eclipse.sirius.tools.api.SiriusPlugin; import org.eclipse.sirius.ui.business.api.dialect.DialectEditor; +import org.eclipse.sirius.ui.business.api.session.IEditingSession; +import org.eclipse.sirius.ui.business.api.session.SessionUIManager; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.ViewpointPackage; @@ -2100,13 +2103,20 @@ public void refreshRepresentationOfEditor(IEditorPart editor) { * @return */ public EditPart getEditPart(DDiagramElement diagramElement) { - IEditorPart editor = EclipseUIUtil.getActiveEditor(); - if (editor instanceof DiagramEditor) { - Session session = new EObjectQuery(diagramElement).getSession(); + DDiagram parentDiagram = diagramElement == null ? null : diagramElement.getParentDiagram(); + Session session = parentDiagram == null ? null : new EObjectQuery(parentDiagram).getSession(); + IEditingSession uiSession = SessionUIManager.INSTANCE.getUISession(session); + + DialectEditor editor = null; + if (uiSession != null && parentDiagram != null) { + editor = uiSession.getEditor(parentDiagram); + } + + if (editor instanceof DiagramEditor diagramEditor) { View gmfView = SiriusGMFHelper.getGmfView(diagramElement, session); - if (gmfView != null && editor instanceof DiagramEditor) { - final Map editPartRegistry = ((DiagramEditor) editor).getDiagramGraphicalViewer().getEditPartRegistry(); + if (gmfView != null && diagramEditor.getDiagramGraphicalViewer() != null) { + final Map editPartRegistry = diagramEditor.getDiagramGraphicalViewer().getEditPartRegistry(); final Object editPart = editPartRegistry.get(gmfView); if (editPart instanceof EditPart) { return (EditPart) editPart;