From e0ad81d793be142ee88c209cea809372b5111977 Mon Sep 17 00:00:00 2001 From: Glenn Plouhinec Date: Wed, 23 Oct 2024 19:07:09 +0200 Subject: [PATCH] #2894 Avoid potential deadlocks in refresh Signed-off-by: Maxime Porhel Signed-off-by: Glenn Plouhinec --- .../core/sirius/analysis/DiagramServices.java | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 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 04feb3e6a1..c3001fc22f 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 + * Glenn Plouhinec, Maxime Porhel (Obeo) - Avoid potential deadlocks in refresh *******************************************************************************/ package org.polarsys.capella.core.sirius.analysis; @@ -44,7 +45,6 @@ import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; import org.eclipse.sirius.common.tools.api.util.RefreshIdsHolder; -import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil; import org.eclipse.sirius.diagram.AbstractDNode; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DDiagramElement; @@ -93,6 +93,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; @@ -1956,21 +1958,29 @@ 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(); - View gmfView = SiriusGMFHelper.getGmfView(diagramElement, session); - - if (gmfView != null && editor instanceof DiagramEditor) { - final Map editPartRegistry = ((DiagramEditor) editor).getDiagramGraphicalViewer().getEditPartRegistry(); - final Object editPart = editPartRegistry.get(gmfView); - if (editPart instanceof EditPart) { - return (EditPart) editPart; + 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 diagramEditor = (DiagramEditor) editor; + View gmfView = SiriusGMFHelper.getGmfView(diagramElement, session); + + 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; + } } } + return null; } - return null; - } /** * Refresh the begin EditPart and end EditPart of a DEdge