From a166879c3e0a908df7ec8dfa64a60aee1a4869ef Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Thu, 23 May 2024 15:10:58 +0200 Subject: [PATCH 1/5] [380] Add test to reveal the problem of DropDescription tool Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/380 --- .../data/unit/dragAndDrop/tc-1041/tc1041.aird | 74 ++++++++++- .../unit/dragAndDrop/tc-1041/tc1041.odesign | 49 ++++++- .../sirius/tests/swtbot/DragNDropTest.java | 121 ++++++++++++------ 3 files changed, 202 insertions(+), 42 deletions(-) diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.aird index 736ca34464..aeef579cc4 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.aird +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.aird @@ -1,6 +1,6 @@ - + tc1041.ecore @@ -24,6 +24,18 @@ + + + + + + + + + + + + @@ -173,4 +185,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.odesign index 44d75d50f0..13efc78ab4 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.odesign +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/dragAndDrop/tc-1041/tc1041.odesign @@ -1,5 +1,5 @@ - + @@ -39,9 +39,9 @@ - + - + + + - + @@ -71,7 +73,7 @@ - + @@ -300,5 +302,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DragNDropTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DragNDropTest.java index 87499be24b..3e1f8628f6 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DragNDropTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DragNDropTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2023 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -69,6 +69,12 @@ public class DragNDropTest extends AbstractSiriusSwtBotGefTestCase { private static final String REPRESENTATION_INSTANCE_2BLANK = "new TC1041 representation 2 Blank"; + private static final String REPRESENTATION_INSTANCE_2BLANK_BIS = "new TC1041 representation 2 BlankBis"; + + private static final String REPRESENTATION_INSTANCE_2BLANK_TER = "new TC1041 representation 2 BlankTer"; + + private static final String REPRESENTATION_INSTANCE_2BLANK_QUATER = "new TC1041 representation 2 BlankQuater"; + private static final String REPRESENTATION_INSTANCE_5BLANK = "new TC1041 representation 5 Blank"; private static final String TEST_NO_NPE_RAISED_DURING_DND = "Test no NPE raised during DND"; @@ -79,6 +85,12 @@ public class DragNDropTest extends AbstractSiriusSwtBotGefTestCase { private static final String REPRESENTATION_NAME_2 = "TC1041 representation 2 Blank"; + private static final String REPRESENTATION_NAME_2_BIS = "TC1041 representation 2 BlankBis"; + + private static final String REPRESENTATION_NAME_2_TER = "TC1041 representation 2 BlankTer"; + + private static final String REPRESENTATION_NAME_2_QUATER = "TC1041 representation 2 BlankQuater"; + private static final String REPRESENTATION_NAME_3 = "TC1041 representation 3"; private static final String REPRESENTATION_NAME_5 = "TC1041 representation 5 Blank"; @@ -184,11 +196,8 @@ protected void onSetUpAfterOpeningDesignerPerspective() throws Exception { semanticResourceNode = localSession.getSemanticResourceNode(ecoreEcoreResource); } - /** - * Open "TC1041 representation 2 Blank" diagram. - */ - private void openRepresentation2() { - editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_NAME_2, REPRESENTATION_INSTANCE_2BLANK, DDiagram.class); + private void openRepresentation(String representationDescriptionName, final String representationName) { + editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), representationDescriptionName, representationName, DDiagram.class); if (snapToGrid) { editor.setSnapToGrid(true, GRID_STEP, 2); } else { @@ -200,12 +209,7 @@ private void openRepresentation2() { * Open "TC1041 representation 5 Blank" diagram. */ private void openRepresentation5() { - editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_NAME_5, REPRESENTATION_INSTANCE_5BLANK, DDiagram.class); - if (snapToGrid) { - editor.setSnapToGrid(true, GRID_STEP, 2); - } else { - editor.setSnapToGrid(false); - } + openRepresentation(REPRESENTATION_NAME_5, REPRESENTATION_INSTANCE_5BLANK); } /** @@ -219,36 +223,20 @@ private void openRepresentation3() { * Open "TC1041 representation 6 Blank" diagram. */ private void openRepresentation6() { - editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_NAME_6, REPRESENTATION_INSTANCE_6BLANK, DDiagram.class); - if (snapToGrid) { - editor.setSnapToGrid(true, GRID_STEP, 2); - } else { - editor.setSnapToGrid(false); - } + openRepresentation(REPRESENTATION_NAME_6, REPRESENTATION_INSTANCE_6BLANK); } /** * Open "TC1041 representation 7 Blank" diagram. */ private void openRepresentation7() { + openRepresentation(REPRESENTATION_NAME_7, REPRESENTATION_INSTANCE_7BLANK); editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_NAME_7, REPRESENTATION_INSTANCE_7BLANK, DDiagram.class); - if (snapToGrid) { - editor.setSnapToGrid(true, GRID_STEP, 2); - } else { - editor.setSnapToGrid(false); - } } - /** - * @throws Exception - * Test the drag&drop of P1(EPackage) from the Model Content - * view to the diagram. This test is done on a "TC1041 - * representation 2 Blank" diagram. - */ - @Test - public void test_DnDPackageFromMC2DiagramBlank2() throws Exception { + private void test_DnDPackageFromMC2DiagramBlank2X(String representationDescriptionName, final String representationName, final boolean dropAllowed) throws Exception { - openRepresentation2(); + openRepresentation(representationDescriptionName, representationName); startToListenErrorLog(true, true); @@ -257,11 +245,72 @@ public void test_DnDPackageFromMC2DiagramBlank2() throws Exception { final SWTBotTreeItem ecoreTreeItem = semanticResourceNode.expandNode(ROOTPACKAGE_NAME).getNode(CONTAINER_TO_DRAG_P1); ecoreTreeItem.dragAndDrop(editor.getCanvas()); - bot.waitUntil(new DiagramWithChildrensCondition(editor, 1)); + if (dropAllowed) { + bot.waitUntil(new DiagramWithChildrensCondition(editor, 1)); + } else { + bot.waitUntil(new DiagramWithChildrensCondition(editor, 0)); + } assertFalse("An error message was generated !", doesAWarningOccurs() || doesAnErrorOccurs()); - IGraphicalEditPart p1EditPart = (IGraphicalEditPart) editor.getEditPart(CONTAINER_TO_DRAG_P1, DNodeContainerEditPart.class).part(); - checkEditPartLocation(p1EditPart); + try { + IGraphicalEditPart p1EditPart = (IGraphicalEditPart) editor.getEditPart(CONTAINER_TO_DRAG_P1, DNodeContainerEditPart.class).part(); + if (dropAllowed) { + checkEditPartLocation(p1EditPart); + } else { + fail("The drop should not be allowed in this case."); + } + } catch (WidgetNotFoundException e) { + if (dropAllowed) { + // If drop is not allowed the exception is expected. + throw e; + } + } + } + + /** + * @throws Exception + * Test the drag&drop of P1(EPackage) from the Model Content view to the diagram. This test is done on a + * "TC1041 representation 2 Blank" diagram. + */ + @Test + public void test_DnDPackageFromMC2DiagramBlank2() throws Exception { + test_DnDPackageFromMC2DiagramBlank2X(REPRESENTATION_NAME_2, REPRESENTATION_INSTANCE_2BLANK, true); + } + + /** + * Test the drag&drop of P1(EPackage) from the Model Content view to the diagram. This test is done on a "TC1041 + * representation 2 BlankBis" diagram and uses a drop tool of an additional layer of another diagram (and not + * imported). + * + * @throws Exception + */ + @Test + public void test_DnDPackageFromMC2DiagramBlank2Bis() throws Exception { + test_DnDPackageFromMC2DiagramBlank2X(REPRESENTATION_NAME_2_BIS, REPRESENTATION_INSTANCE_2BLANK_BIS, false); + } + + /** + * Test the drag&drop of P1(EPackage) from the Model Content view to the diagram. This test is done on a "TC1041 + * representation 2 BlankTer" diagram and imports a drop tool of an additional layer of another diagram in the + * default layer. + * + * @throws Exception + */ + @Test + public void test_DnDPackageFromMC2DiagramBlank2Ter() throws Exception { + test_DnDPackageFromMC2DiagramBlank2X(REPRESENTATION_NAME_2_TER, REPRESENTATION_INSTANCE_2BLANK_TER, true); + } + + /** + * Test the drag&drop of P1(EPackage) from the Model Content view to the diagram. This test is done on a "TC1041 + * representation 2 BlankQuater" diagram and imports a drop tool of an additional layer of another diagram in an + * additional layer. + * + * @throws Exception + */ + @Test + public void test_DnDPackageFromMC2DiagramBlank2Quater() throws Exception { + test_DnDPackageFromMC2DiagramBlank2X(REPRESENTATION_NAME_2_QUATER, REPRESENTATION_INSTANCE_2BLANK_QUATER, true); } /** @@ -654,7 +703,7 @@ public void test_DnDContainerFromContainer2ContainerBlank2_zoom200() throws Exce @Test public void test_DnDEClassFromMC2DiagramBlank2() throws Exception { - openRepresentation2(); + openRepresentation(REPRESENTATION_NAME_2, REPRESENTATION_INSTANCE_2BLANK); startToListenErrorLog(true, true); From 0255e12711b24a9e146086adf9ea92e1a1ff3a21 Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Thu, 23 May 2024 14:54:55 +0200 Subject: [PATCH 2/5] [380] Consider Drag'n'drop tools of other diagrams Before this commit the drag'n'drop tools of other diagrams are visible in the VSM by the specifier but ignored at runtime. Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/380 --- ...entContainerWithInterpreterOperations.java | 81 +++++++++++++++---- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/operations/DDiagramElementContainerWithInterpreterOperations.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/operations/DDiagramElementContainerWithInterpreterOperations.java index 9b15d2e264..baea4a6a48 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/operations/DDiagramElementContainerWithInterpreterOperations.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/operations/DDiagramElementContainerWithInterpreterOperations.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2021 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -16,6 +16,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; @@ -32,13 +35,13 @@ import org.eclipse.sirius.diagram.business.api.query.DDiagramQuery; import org.eclipse.sirius.diagram.business.api.query.DiagramElementMappingQuery; import org.eclipse.sirius.diagram.business.internal.metamodel.helper.ContainerMappingWithInterpreterHelper; +import org.eclipse.sirius.diagram.description.AdditionalLayer; import org.eclipse.sirius.diagram.description.DiagramElementMapping; import org.eclipse.sirius.diagram.description.DragAndDropTargetDescription; import org.eclipse.sirius.diagram.description.Layer; import org.eclipse.sirius.diagram.description.tool.ContainerDropDescription; import org.eclipse.sirius.diagram.tools.api.Messages; import org.eclipse.sirius.tools.api.SiriusPlugin; -import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription; import org.eclipse.sirius.viewpoint.description.tool.DragSource; import org.eclipse.sirius.viewpoint.description.tool.ToolPackage; @@ -112,7 +115,7 @@ public static ContainerDropDescription getBestDropDescription(final DragAndDropT /* find valid candidates */ final Collection candidates = new ArrayList<>(); - for (final ContainerDropDescription dropTool : DDiagramElementContainerWithInterpreterOperations.getDropToolsOnActivatedLayers(diagram, description)) { + for (final ContainerDropDescription dropTool : DDiagramElementContainerWithInterpreterOperations.getActivatedDropTools(diagram, description)) { if (DDiagramElementContainerWithInterpreterOperations.checkDragSource(dropTool, dragSource) && DDiagramElementContainerWithInterpreterOperations.checkDroppedDiagramElement(dropTool, droppedDiagramElement, newViewContainer)) { if (DDiagramElementContainerWithInterpreterOperations.checkPrecondition(dropTool, safeInterpreter, droppedElement)) { @@ -169,20 +172,6 @@ private static boolean checkPrecondition(final ContainerDropDescription dropTool return true; } - private static Collection getDropToolsOnActivatedLayers(final DDiagram diagram, final DragAndDropTargetDescription mapping) { - if (diagram.getDescription().getDefaultLayer() != null) { - final Collection allActivatedTools = new HashSet<>(); - allActivatedTools.addAll(diagram.getDescription().getDefaultLayer().getAllTools()); - for (Layer layer : new DDiagramQuery(diagram).getAllActivatedLayers()) { - allActivatedTools.addAll(layer.getAllTools()); - } - Collection dropTools = DDiagramElementContainerWithInterpreterOperations.getDropTools(mapping); - dropTools.retainAll(allActivatedTools); - return dropTools; - } - return DDiagramElementContainerWithInterpreterOperations.getDropTools(mapping); - } - /** * Returns the drop tools of the mapping. * @@ -198,4 +187,62 @@ private static Collection getDropTools(final DragAndDr } return dropTools; } + + /** + * Returns the list of the activated drop tools for the mapping. An activated drop tool is: + *
    + *
  • in a default layer of any diagram,
  • + *
  • or in an activated layer of the current diagram (contained in or reused by).
  • + *
+ * + * @param diagram + * The current diagram + * @param mapping + * The mapping of the current drag'n'droped element + * @return the list of the activated drop tools. + */ + private static Collection getActivatedDropTools(final DDiagram diagram, final DragAndDropTargetDescription mapping) { + Collection dropTools = DDiagramElementContainerWithInterpreterOperations.getDropTools(mapping); + return dropTools.stream().filter(desc -> isActive(desc, diagram)).collect(Collectors.toCollection(HashSet::new)); + } + + /** + * Tests whether a {@link ContainerDropDescription} belongs to a default layer or to an activated layer of the + * current diagram. + * + * @param dropDesc + * the current {@link ContainerDropDescription} of the drag'n'dropped element. + * @param diagram + * the current diagram + * @return true if the ContainerDropDescription is active, false otherwise. + */ + private static boolean isActive(final ContainerDropDescription dropDesc, final DDiagram diagram) { + boolean result = false; + Optional optionalParentLayer = getLayer(dropDesc); + if (optionalParentLayer.isPresent()) { + if (!(optionalParentLayer.get() instanceof AdditionalLayer)) { + // This layer is a default layer. + result = true; + } else { + List activatedLayers = new DDiagramQuery(diagram).getAllActivatedLayers(); + if (activatedLayers.contains(optionalParentLayer.get()) || activatedLayers.stream().anyMatch(layer -> layer.getReusedTools().contains(dropDesc))) { + // The dropDesc is in an activated layer of the current diagram or it is reused by an activated + // layer of the current diagram. + result = true; + } + } + } + return result; + } + + private static Optional getLayer(ContainerDropDescription containerDropDescription) { + EObject current = containerDropDescription; + while (current != null) { + if (current instanceof Layer) { + return Optional.of((Layer) current); + } + current = current.eContainer(); + } + return Optional.empty(); + } } From 8709ad506981f5f2f8fdbf9272080af337f6b308 Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Thu, 23 May 2024 15:23:50 +0200 Subject: [PATCH 3/5] [380] Migrate test data without any change Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/380 --- .../data/unit/copyPaste/1894.aird | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird index 9293a6db22..9eaffc4bd5 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird @@ -1,24 +1,24 @@ - - + + 1894.ecore - + - + - + - + - - + + @@ -120,129 +120,129 @@ - - + + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + - + - + - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + - - + + @@ -405,124 +405,124 @@ - - + + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + - + - + - + - + - + - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + - + - + - + From f4ddca285746ebc872d85d5aa49516540c1f078e Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Thu, 23 May 2024 15:36:52 +0200 Subject: [PATCH 4/5] [380] Add test to reveal the problem of PasteDescription tool This commit adds a new diagram that uses the PasteDescription tool of an another diagram. Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/380 --- .../data/unit/copyPaste/1894.aird | 495 +++++++++++++++++- .../data/unit/copyPaste/vp-1894.odesign | 60 ++- .../AbstractClipboardSupportTest.java | 32 +- .../clipboard/CustomClipboardSupportTest.java | 56 +- 4 files changed, 638 insertions(+), 5 deletions(-) diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird index 9eaffc4bd5..3137e7c872 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/1894.aird @@ -4,10 +4,22 @@ 1894.ecore - + + + + + + + + + + + + + @@ -526,4 +538,485 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + labelSize + + + + + + + + + + + + + + + + + labelSize + + + + + + + + + + + + + + + + + labelSize + + + + + + + + + + + + + + + + + labelSize + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/vp-1894.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/vp-1894.odesign index 95795f6872..63a1920c6e 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/vp-1894.odesign +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/copyPaste/vp-1894.odesign @@ -1,5 +1,5 @@ - + @@ -87,5 +87,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/AbstractClipboardSupportTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/AbstractClipboardSupportTest.java index 67fd5e9507..57a07fa35b 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/AbstractClipboardSupportTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/AbstractClipboardSupportTest.java @@ -92,6 +92,21 @@ public abstract class AbstractClipboardSupportTest extends AbstractSiriusSwtBotG */ protected static final String REPRESENTATION_WITH_CUSTOM_PASTE = "CustomClipboard"; + /** + * Custom representation using PasteTool of another diagram instance name. + */ + protected static final String REPRESENTATION_WITH_CUSTOM_PASTE_2 = "CustomClipboard2"; + + /** + * Instance name of a custom representation importing PasteTool of another diagram in the default layer. + */ + protected static final String REPRESENTATION_WITH_CUSTOM_PASTE_3 = "CustomClipboard3"; + + /** + * Instance name of a custom representation importing PasteTool of another diagram in an additional layer. + */ + protected static final String REPRESENTATION_WITH_CUSTOM_PASTE_4 = "CustomClipboard4"; + /** * Generic representation instance name bis. */ @@ -128,10 +143,25 @@ public abstract class AbstractClipboardSupportTest extends AbstractSiriusSwtBotG protected static final String GENERIC_DESCRIPTION = "Entities"; /** - * Sirius name. + * Name of the diagram description. */ protected static final String CUSTOM_DESCRIPTION = "diagramWithCustomClipboard"; + /** + * Name of the diagram description using a PasteDescription of another diagram. + */ + protected static final String CUSTOM_DESCRIPTION_2 = "diagramWithCustomClipboard2"; + + /** + * Name of the diagram description importing a PasteDescription of another diagram in the default layer. + */ + protected static final String CUSTOM_DESCRIPTION_3 = "diagramWithCustomClipboard3"; + + /** + * Name of the diagram description importing a PasteDescription of another diagram in an additional layer. + */ + protected static final String CUSTOM_DESCRIPTION_4 = "diagramWithCustomClipboard4"; + /** * Sirius specific model. */ diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/CustomClipboardSupportTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/CustomClipboardSupportTest.java index 99e447452b..a103c7c089 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/CustomClipboardSupportTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/clipboard/CustomClipboardSupportTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -60,6 +60,59 @@ public void testCopyPasteFromEditMenuWithAlwaysPasteClassTool() { checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable_Class", 1); } + /** + * Test copy and paste for menu on Edit Part without Clipboard that uses the PasteDescription of another diagram. + */ + public void testCopyPasteFromEditMenuWithAlwaysPasteClassTool_Reuse() { + editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION_2, REPRESENTATION_WITH_CUSTOM_PASTE_2, DDiagram.class); + checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable_Class", 1); + } + + /** + * Test copy and paste for menu on Edit Part without Clipboard that imports the PasteDescription of another diagram + * in the default layer. + */ + public void testCopyPasteFromEditMenuWithAlwaysPasteClassTool_ImportDefault() { + editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION_3, REPRESENTATION_WITH_CUSTOM_PASTE_3, DDiagram.class); + checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable_Class", 1); + } + + /** + * Test copy and paste for menu on Edit Part without Clipboard that imports the PasteDescription of another diagram + * in an additional layer. + */ + public void testCopyPasteFromEditMenuWithAlwaysPasteClassTool_ImportAdditional() { + editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION_4, REPRESENTATION_WITH_CUSTOM_PASTE_4, DDiagram.class); + checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable_Class", 1); + } + + /** + * Test copy and paste for menu on Edit Part that uses the PasteDescription from a transient layer of another + * diagram without importing it (Paste is not possible). + */ + public void testCopyPasteFromEditMenuWithAlwaysPasteClassToolFromTransientLayer_Reuse() { + editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION_2, REPRESENTATION_WITH_CUSTOM_PASTE_2, DDiagram.class); + checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable2_Class"), editor2, false, (SWTBotGefEditPart) null, "pasted_pastable2_Class", 1); + } + + /** + * Test copy and paste for menu on Edit Part that imports the PasteDescription, from a transient layer of another + * diagram, in the default layer. + */ + public void testCopyPasteFromEditMenuWithAlwaysPasteClassToolFromTransientLayer_ImportDefault() { + editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION_3, REPRESENTATION_WITH_CUSTOM_PASTE_3, DDiagram.class); + checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable2_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable2_Class", 1); + } + + /** + * Test copy and paste for menu on Edit Part that imports the PasteDescription, from a transient layer of another + * diagram, in an additional layer. + */ + public void testCopyPasteFromEditMenuWithAlwaysPasteClassToolFromTransientLayer_ImportAdditional() { + editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION_4, REPRESENTATION_WITH_CUSTOM_PASTE_4, DDiagram.class); + checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable2_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable2_Class", 1); + } + /** * Test copy and paste for menu on Edit Part from a transient layer. */ @@ -67,7 +120,6 @@ public void testCopyPasteFromEditMenuWithAlwaysPasteClassToolFromTransientLayer( editor2 = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), CUSTOM_DESCRIPTION, REPRESENTATION_WITH_CUSTOM_PASTE, DDiagram.class); checkCopyPaste(editor2, editor2.getSelectableEditPart("pastable2_Class"), editor2, true, (SWTBotGefEditPart) null, "pasted_pastable2_Class", 1); } - /** * Test copy and paste for menu on Edit Part without Clipboard. */ From 8767e65a7c6b35f9aeba555c91882baf2d543a27 Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Thu, 23 May 2024 16:39:51 +0200 Subject: [PATCH 5/5] [380] Consider PasteDescription tools of other diagrams Before this commit the PasteDescription tools of other diagrams are visible in the VSM by the specifier but ignored at runtime. Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/380 --- .../internal/query/PasteTargetQuery.java | 84 +++++++++++++++---- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/query/PasteTargetQuery.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/query/PasteTargetQuery.java index 8fd5ef40a6..a2d77325eb 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/query/PasteTargetQuery.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/query/PasteTargetQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2011, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,18 +15,22 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import org.eclipse.emf.ecore.EObject; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DDiagramElement; import org.eclipse.sirius.diagram.business.api.query.DDiagramQuery; import org.eclipse.sirius.diagram.business.api.query.DiagramDescriptionQuery; import org.eclipse.sirius.diagram.business.api.query.DiagramElementMappingQuery; +import org.eclipse.sirius.diagram.description.AdditionalLayer; import org.eclipse.sirius.diagram.description.DiagramDescription; import org.eclipse.sirius.diagram.description.DiagramElementMapping; import org.eclipse.sirius.diagram.description.Layer; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.description.PasteTargetDescription; -import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription; import org.eclipse.sirius.viewpoint.description.tool.PasteDescription; import com.google.common.collect.Sets; @@ -63,30 +67,16 @@ public Collection getAvailablePasteTools() { final Collection result = new ArrayList<>(); if (semDec instanceof DDiagram) { DDiagram diag = (DDiagram) semDec; - result.addAll(getPasteToolsOnActivatedLayers(diag, diag.getDescription())); + result.addAll(getActivatedPasteTools(diag, diag.getDescription())); } else if (semDec instanceof DDiagramElement) { DDiagramElement dde = (DDiagramElement) semDec; - result.addAll(getPasteToolsOnActivatedLayers(dde.getParentDiagram(), dde.getDiagramElementMapping())); + result.addAll(getActivatedPasteTools(dde.getParentDiagram(), dde.getDiagramElementMapping())); } // No other cases : DDiagram could only handle paste operation on itself // or on of its element. return result; } - private Collection getPasteToolsOnActivatedLayers(final DDiagram dDiagram, final PasteTargetDescription pasteTargetDescription) { - if (dDiagram.getDescription().getDefaultLayer() != null) { - final Collection allActivatedTools = new HashSet<>(); - allActivatedTools.addAll(dDiagram.getDescription().getDefaultLayer().getAllTools()); - for (Layer layer : new DDiagramQuery(dDiagram).getAllActivatedLayers()) { - allActivatedTools.addAll(layer.getAllTools()); - } - Collection pasteTools = getAllPasteTools(pasteTargetDescription); - pasteTools.retainAll(allActivatedTools); - return pasteTools; - } - return getAllPasteTools(pasteTargetDescription); - } - /** * Returns the paste tools of the pasteTargetDescription. * @@ -104,4 +94,62 @@ private Collection getAllPasteTools(final PasteTargetDescripti } return pasteTools; } + + /** + * Returns the list of the activated drop tools for the mapping. An activated drop tool is: + *
    + *
  • in a default layer of any diagram,
  • + *
  • or in an activated layer of the current diagram (contained in or reused by).
  • + *
+ * + * @param diagram + * The current diagram + * @param pasteTargetDesc + * The current paste target description + * @return the list of the activated paste tools. + */ + private Collection getActivatedPasteTools(final DDiagram diagram, final PasteTargetDescription pasteTargetDesc) { + Collection pasteTools = getAllPasteTools(pasteTargetDesc); + return pasteTools.stream().filter(desc -> isActive(desc, diagram)).collect(Collectors.toCollection(HashSet::new)); + } + + /** + * Tests whether a {@link PasteDescription} belongs to a default layer or to an activated layer of the current + * diagram. + * + * @param pasteDesc + * the current {@link PasteDescription} of the drag'n'dropped element. + * @param diagram + * the current diagram + * @return true if the PasteDescription is active, false otherwise. + */ + private static boolean isActive(final PasteDescription pasteDesc, final DDiagram diagram) { + boolean result = false; + Optional optionalParentLayer = getLayer(pasteDesc); + if (optionalParentLayer.isPresent()) { + if (!(optionalParentLayer.get() instanceof AdditionalLayer)) { + // This layer is a default layer. + result = true; + } else { + List activatedLayers = new DDiagramQuery(diagram).getAllActivatedLayers(); + if (activatedLayers.contains(optionalParentLayer.get()) || activatedLayers.stream().anyMatch(layer -> layer.getReusedTools().contains(pasteDesc))) { + // The pasteDesc is in an activated layer of the current diagram or it is reused by an activated + // layer of the current diagram. + result = true; + } + } + } + return result; + } + + private static Optional getLayer(PasteDescription containerDropDescription) { + EObject current = containerDropDescription; + while (current != null) { + if (current instanceof Layer) { + return Optional.of((Layer) current); + } + current = current.eContainer(); + } + return Optional.empty(); + } }