Skip to content

Commit

Permalink
eclipse-capella#2894 Avoid potential deadlocks in refresh
Browse files Browse the repository at this point in the history
Change-Id: I653a0e579d58abf71f44ceb8eb85179cc07d5eb5
Signed-off-by: Maxime Porhel <[email protected]>
  • Loading branch information
mPorhel committed Sep 25, 2024
1 parent fb402a8 commit 36d775d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 THALES GLOBAL SERVICES.
* Copyright (c) 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
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* Thales - initial API and implementation
* Maxime Porhel (Obeo) - Avoid potential deadlocks in refresh
*******************************************************************************/
package org.polarsys.capella.test.diagram.misc.ju.testcases;

Expand Down Expand Up @@ -155,8 +156,7 @@ public void testPieIconsOnPhysicalLinks(Session session, String diagramUID){
}

private boolean hasPieIconOnFunctionalExchange(DDiagram diagram) {
for (DDiagramElement element : diagram.getDiagramElements()) {
DEdge edge = (DEdge) element;
for (DEdge edge : diagram.getEdges()) {
EObject target = edge.getTarget();
if (target instanceof FunctionalExchange) {
FunctionalExchange fe = (FunctionalExchange) target;
Expand All @@ -182,8 +182,7 @@ private boolean hasPieIconOnFunctionalExchange(DDiagram diagram) {
}

private boolean hasPieIconOnPhysicalLink(DDiagram diagram) {
for (DDiagramElement element : diagram.getDiagramElements()) {
DEdge edge = (DEdge) element;
for (DEdge edge : diagram.getEdges()) {
EObject target = edge.getTarget();
if (target instanceof PhysicalLink) {
PhysicalLink fe = (PhysicalLink) target;
Expand Down

0 comments on commit 36d775d

Please sign in to comment.