Skip to content

Commit

Permalink
#2894 Avoid potential deadlocks in refresh
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Porhel <[email protected]>
Signed-off-by: Glenn Plouhinec <[email protected]>
  • Loading branch information
GlennPlou authored and tguiu committed Nov 20, 2024
1 parent d968e2e commit 98e77d9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 75 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
* Glenn Plouhinec, Maxime Porhel (Obeo) - Avoid potential deadlocks in refresh
*******************************************************************************/
package org.polarsys.capella.core.sirius.analysis;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2100,16 +2102,22 @@ 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);

if (uiSession != null && parentDiagram != null) {
DialectEditor editor = uiSession.getEditor(parentDiagram);

if (editor instanceof DiagramEditor diagramEditor) {
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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2020 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
* Glenn Plouhinec, Maxime Porhel (Obeo) - Avoid potential deadlocks in refresh
*******************************************************************************/
package org.polarsys.capella.test.diagram.common.ju.wrapper.utils;

Expand Down Expand Up @@ -671,11 +672,12 @@ public static void pasteLayout(DDiagram diagram) {
}

/**
* Close a 'diagram'
* Close a diagram editor from the ui session.
*
* @param session
* the Sirius session
* @param diagram
* @return
* the representation associated to the editor to close
*/
public static void closeEditor(Session session, DDiagram diagram) {
IEditorPart editor = getDiagramEditor(session, diagram);
Expand All @@ -684,6 +686,16 @@ public static void closeEditor(Session session, DDiagram diagram) {
}
}

/**
* Close a diagram editor.
*
* @param editor
* the editor to close
*/
public static void closeEditor(IEditorPart editor) {
DialectUIManager.INSTANCE.closeEditor(editor, true);
}

/**
* Open a 'diagram' e.g. a {@link DRepresentation}.
*
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
* Glenn Plouhinec, Maxime Porhel (Obeo) - Avoid potential deadlocks in refresh
*******************************************************************************/
package org.polarsys.capella.test.diagram.misc.ju.testcases;

Expand All @@ -20,12 +21,12 @@
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.DEdge;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeBeginNameEditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeEndNameEditPart;
import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.StyleConfiguration;
import org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.styles.StyleConfigurationRegistry;
import org.eclipse.ui.IEditorPart;
import org.polarsys.capella.core.data.cs.PhysicalLink;
import org.polarsys.capella.core.data.fa.FunctionalExchange;
import org.polarsys.capella.core.sirius.analysis.CapellaServices;
Expand All @@ -44,15 +45,23 @@ public class PieIconTest extends BasicTestCase {
private static final String PROJECT_NAME = "testPie"; //$NON-NLS-1$

protected Session session;

protected SessionContext context;

public static String OAIB = "_uMIigLCvEe6Fv9U2y24pjw";

public static String OAB = "_97h-ILCwEe6Fv9U2y24pjw";

public static String SAB = "_CZ_7QLC2Ee6Fv9U2y24pjw";

public static String SDFB = "_MWE0wLC0Ee6Fv9U2y24pjw";

public static String LAB = "_1jTKwK-mEe6L-OKa_6GDIw";

public static String LDFB = "_c61CELEYEe6Fv9U2y24pjw";

public static String PAB = "_S542sLEaEe6Fv9U2y24pjw";

public static String PDFB = "_0DlQ4LEZEe6Fv9U2y24pjw";

@Override
Expand All @@ -65,7 +74,6 @@ protected void setUp() throws Exception {
super.setUp();
this.session = getSession(PROJECT_NAME);
this.context = new SessionContext(session);

}

@Override
Expand All @@ -80,30 +88,30 @@ public void testOA() {
testPieIconsOnFunctionalExchanges(session, OAB, false);
testPieIconsOnFunctionalExchanges(session, OAIB, false);
}

public void testSA() {
testPieIconsOnFunctionalExchanges(session, SAB, true);
testPieIconsOnFunctionalExchanges(session, SDFB, false);
}
}

public void testLA() {
testPieIconsOnFunctionalExchanges(session, LAB, true);
testPieIconsOnFunctionalExchanges(session, LDFB, false);
}
}

public void testPA() {
testPieIconsOnFunctionalExchanges(session, PAB, true);
testPieIconsOnFunctionalExchanges(session, PDFB, false);
}
}

public void testPieIconsOnFunctionalExchanges(Session session, String diagramUID, boolean testPL) {
DEdgeIconCache.getInstance().reset();

DiagramHelper.setPrefereneRefreshOnOpening(false);
DiagramHelper.setPreferenceAutoRefresh(false);

DDiagram diagram = (DDiagram) DiagramHelper.getDRepresentationByUID(session, diagramUID);
DiagramHelper.opendiagramEditor(session, diagram);
IEditorPart editor = DiagramHelper.opendiagramEditor(session, diagram);
assertFalse(hasPieIconOnFunctionalExchange(diagram));
if (testPL)
assertFalse(hasPieIconOnPhysicalLink(diagram));
Expand All @@ -114,97 +122,85 @@ public void testPieIconsOnFunctionalExchanges(Session session, String diagramUID
assertTrue(hasPieIconOnFunctionalExchange(diagram));
if (testPL)
assertTrue(hasPieIconOnPhysicalLink(diagram));
DiagramHelper.closeEditor(session, diagram);
DiagramHelper.closeEditor(editor);

DiagramHelper.setPrefereneRefreshOnOpening(true);
DiagramHelper.setPreferenceAutoRefresh(true);

// Icon shall not be true on opening with refresh
diagram = (DDiagram) DiagramHelper.getDRepresentationByUID(session, diagramUID);
DiagramHelper.opendiagramEditor(session, diagram);
editor = DiagramHelper.opendiagramEditor(session, diagram);
assertTrue(hasPieIconOnFunctionalExchange(diagram));
if (testPL)
assertTrue(hasPieIconOnPhysicalLink(diagram));
DiagramHelper.closeEditor(session, diagram);
DiagramHelper.closeEditor(editor);
}
public void testPieIconsOnPhysicalLinks(Session session, String diagramUID){

public void testPieIconsOnPhysicalLinks(Session session, String diagramUID) {
DEdgeIconCache.getInstance().reset();

DiagramHelper.setPrefereneRefreshOnOpening(false);
DiagramHelper.setPreferenceAutoRefresh(false);

DDiagram diagram = (DDiagram) DiagramHelper.getDRepresentationByUID(session, diagramUID);
DiagramHelper.opendiagramEditor(session, diagram);
IEditorPart editor = DiagramHelper.opendiagramEditor(session, diagram);
assertFalse(hasPieIconOnPhysicalLink(diagram));
// Icon shall be null as semanticElements are still FunctionalExchange, and not FunctionalChain
DiagramHelper.refreshDiagram(diagram);

// Icon shall not be null after refresh
assertTrue(hasPieIconOnPhysicalLink(diagram));
DiagramHelper.closeEditor(session, diagram);
DiagramHelper.closeEditor(editor);

DiagramHelper.setPrefereneRefreshOnOpening(true);
DiagramHelper.setPreferenceAutoRefresh(true);

// Icon shall not be true on opening with refresh
diagram = (DDiagram) DiagramHelper.getDRepresentationByUID(session, diagramUID);
DiagramHelper.opendiagramEditor(session, diagram);
editor = DiagramHelper.opendiagramEditor(session, diagram);
assertTrue(hasPieIconOnPhysicalLink(diagram));
DiagramHelper.closeEditor(session, diagram);
DiagramHelper.closeEditor(editor);
}

private boolean hasPieIconOnFunctionalExchange(DDiagram diagram) {
for (DDiagramElement element : diagram.getDiagramElements()) {
DEdge edge = (DEdge) element;
EObject target = edge.getTarget();
if (target instanceof FunctionalExchange) {
FunctionalExchange fe = (FunctionalExchange) target;
EditPart edgeEditPart = DiagramServices.getDiagramServices().getEditPart(edge);
if (CapellaServices.getService().getDisplayedInvolvingFunctionalChains(edge).size() > 1) {
if (edgeEditPart != null) {
EditPart nameEditPart = edgeEditPart.getChildren().stream()
.filter(child -> child instanceof DEdgeBeginNameEditPart || child instanceof DEdgeEndNameEditPart)
.findAny().get();
if (nameEditPart != null) {
StyleConfiguration c = StyleConfigurationRegistry.getInstance()
.getStyleConfiguration(edge.getDiagramElementMapping(), edge.getStyle());

return c.getLabelIcon(element, (IGraphicalEditPart) nameEditPart) != null;
}

return nameEditPart != null;
for (DEdge edge : diagram.getEdges()) {
EObject target = edge.getTarget();
if (target instanceof FunctionalExchange) {
FunctionalExchange fe = (FunctionalExchange) target;
EditPart edgeEditPart = DiagramServices.getDiagramServices().getEditPart(edge);
if (CapellaServices.getService().getDisplayedInvolvingFunctionalChains(edge).size() > 1) {
if (edgeEditPart != null) {
EditPart nameEditPart = edgeEditPart.getChildren().stream().filter(child -> child instanceof DEdgeBeginNameEditPart || child instanceof DEdgeEndNameEditPart).findAny().get();
if (nameEditPart != null) {
StyleConfiguration c = StyleConfigurationRegistry.getInstance().getStyleConfiguration(edge.getDiagramElementMapping(), edge.getStyle());
return c.getLabelIcon(edge, (IGraphicalEditPart) nameEditPart) != null;
}
return nameEditPart != null;
}
}
}
}
return false;
}

private boolean hasPieIconOnPhysicalLink(DDiagram diagram) {
for (DDiagramElement element : diagram.getDiagramElements()) {
DEdge edge = (DEdge) element;
EObject target = edge.getTarget();
if (target instanceof PhysicalLink) {
PhysicalLink fe = (PhysicalLink) target;
EditPart edgeEditPart = DiagramServices.getDiagramServices().getEditPart(edge);
if (CapellaServices.getService().getDisplayedInvolvingPhysicalPaths(edge).size() > 1) {
if (edgeEditPart != null) {
EditPart nameEditPart = edgeEditPart.getChildren().stream()
.filter(child -> child instanceof DEdgeBeginNameEditPart || child instanceof DEdgeEndNameEditPart)
.findAny().get();
if (nameEditPart != null) {
StyleConfiguration c = StyleConfigurationRegistry.getInstance()
.getStyleConfiguration(edge.getDiagramElementMapping(), edge.getStyle());

return c.getLabelIcon(element, (IGraphicalEditPart) nameEditPart) != null;
}

return nameEditPart != null;
for (DEdge edge : diagram.getEdges()) {
EObject target = edge.getTarget();
if (target instanceof PhysicalLink) {
PhysicalLink fe = (PhysicalLink) target;
EditPart edgeEditPart = DiagramServices.getDiagramServices().getEditPart(edge);
if (CapellaServices.getService().getDisplayedInvolvingPhysicalPaths(edge).size() > 1) {
if (edgeEditPart != null) {
EditPart nameEditPart = edgeEditPart.getChildren().stream().filter(child -> child instanceof DEdgeBeginNameEditPart || child instanceof DEdgeEndNameEditPart).findAny().get();
if (nameEditPart != null) {
StyleConfiguration c = StyleConfigurationRegistry.getInstance().getStyleConfiguration(edge.getDiagramElementMapping(), edge.getStyle());
return c.getLabelIcon(edge, (IGraphicalEditPart) nameEditPart) != null;
}
return nameEditPart != null;
}
}
}
}
return false;
}
}
}

0 comments on commit 98e77d9

Please sign in to comment.