Skip to content

Commit

Permalink
eclipse-capella#2061 Correcting the behavior of DiagramServices
Browse files Browse the repository at this point in the history
When DiagramServices tests an EdgeMapping for selection or visibility,
the disconnect between EdgeMappingImpl and EdgeMappingWrapper is now
managed,
allowing easier integration of external features and plugins into
Capella.
  • Loading branch information
ebausson-obeo authored and SteveMonnier committed Apr 11, 2024
1 parent 8c7a8dc commit fe4d18e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
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.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -30,8 +30,10 @@
import org.eclipse.sirius.diagram.DragAndDropTarget;
import org.eclipse.sirius.diagram.description.DiagramDescription;
import org.eclipse.sirius.diagram.description.DiagramElementMapping;
import org.eclipse.sirius.diagram.description.IEdgeMapping;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.polarsys.capella.common.helpers.EcoreUtil2;
import org.polarsys.capella.core.sirius.analysis.helpers.EdgeMappingHelper;
import org.polarsys.capella.core.sirius.analysis.tool.HashMapSet;

/**
Expand Down Expand Up @@ -271,7 +273,7 @@ public boolean containsView(EObject target, DiagramElementMapping mapping) {
}

for (DDiagramElement view : getDiagramElements(target)) {
if (mapping != null && DiagramServices.getDiagramServices().isMapping(view, mapping)) {
if (mapping != null && mapping.equals(view.getDiagramElementMapping())) {
return true;
}
}
Expand All @@ -295,8 +297,15 @@ public Collection<DDiagramElement> getDiagramElements(EObject target, DiagramEle

ArrayList<DDiagramElement> result = new ArrayList<>();
for (DDiagramElement view : getMapDiagramElements().get(target)) {
if (mapping != null && DiagramServices.getDiagramServices().isMapping(view, mapping)) {
DiagramElementMapping diagramElementMapping = view.getDiagramElementMapping();
if (mapping != null && mapping.equals(diagramElementMapping)) {
result.add(view);
} else if (mapping instanceof IEdgeMapping && diagramElementMapping instanceof IEdgeMapping) {
IEdgeMapping unwrappedMapping = EdgeMappingHelper.unwrapEdgeMapping((IEdgeMapping) mapping);
IEdgeMapping unwrappedDiagramElementMapping = EdgeMappingHelper.unwrapEdgeMapping((IEdgeMapping) diagramElementMapping);
if (unwrappedMapping.equals(unwrappedDiagramElementMapping)) {
result.add(view);
}
}
}
return result;
Expand All @@ -320,7 +329,7 @@ public Collection<DDiagramElement> getDiagramElements(EObject target, DiagramEle

ArrayList<DDiagramElement> result = new ArrayList<>();
for (DDiagramElement view : getMapDiagramElements().get(target)) {
if (mapping == null || DiagramServices.getDiagramServices().isMapping(view, mapping)) {
if ((mapping == null) || mapping.equals(view.getDiagramElementMapping())) {
if ((containerView == null) || EcoreUtil2.isContainedBy(view, containerView)) {
result.add(view);
}
Expand Down
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.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand Down Expand Up @@ -1261,7 +1261,7 @@ public void remove() {
}

public boolean validMapping(DiagramElementMapping mapping, DDiagramElement element) {
return isSameDomain(mapping, element) && isMapping(element, mapping);
return isSameDomain(mapping, element) && checkMappingConsistency(mapping, element);
}

public boolean isSameDomain(DiagramElementMapping mapping, DDiagramElement element) {
Expand All @@ -1273,6 +1273,17 @@ public boolean isSameDomain(DiagramElementMapping mapping, DDiagramElement eleme
return false;
}

private boolean checkMappingConsistency(DiagramElementMapping mapping, DDiagramElement element) {
DiagramElementMapping elementMapping = element.getDiagramElementMapping();
if (mapping instanceof IEdgeMapping && elementMapping instanceof IEdgeMapping) {
IEdgeMapping unwrappedMapping = org.polarsys.capella.core.sirius.analysis.helpers.EdgeMappingHelper.unwrapEdgeMapping((IEdgeMapping) mapping);
IEdgeMapping unwrappedDiagramElementMapping = org.polarsys.capella.core.sirius.analysis.helpers.EdgeMappingHelper.unwrapEdgeMapping((IEdgeMapping) elementMapping);
return unwrappedMapping.equals(unwrappedDiagramElementMapping);
} else {
return mapping.equals(element.getDiagramElementMapping());
}
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2023 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
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.core.sirius.analysis.helpers;

import org.eclipse.sirius.diagram.description.IEdgeMapping;
import org.eclipse.sirius.diagram.description.impl.EdgeMappingImportImpl;
import org.eclipse.sirius.diagram.model.business.internal.description.spec.EdgeMappingImportWrapper;

public class EdgeMappingHelper {

public static IEdgeMapping unwrapEdgeMapping(IEdgeMapping edgeMapping) {
if (edgeMapping instanceof EdgeMappingImportWrapper) {
return unwrapEdgeMapping(((EdgeMappingImportWrapper) edgeMapping).getWrappedEdgeMappingImport());
} else if (edgeMapping instanceof EdgeMappingImportImpl) {
return unwrapEdgeMapping(((EdgeMappingImportImpl) edgeMapping).getImportedMapping());
}
return edgeMapping;
}
}

0 comments on commit fe4d18e

Please sign in to comment.