diff options
| author | Florian Barbin | 2015-08-17 09:39:31 +0000 |
|---|---|---|
| committer | Florian Barbin | 2015-08-25 12:57:35 +0000 |
| commit | 99d08188a34dd5269fca743074d293938195d3e2 (patch) | |
| tree | 8e636b4e9a2c574200336c95e05d7c50e318c8d1 | |
| parent | f412500d16622f7c6bd42a5fbcede13566077cc4 (diff) | |
| download | org.eclipse.sirius-99d08188a34dd5269fca743074d293938195d3e2.tar.gz org.eclipse.sirius-99d08188a34dd5269fca743074d293938195d3e2.tar.xz org.eclipse.sirius-99d08188a34dd5269fca743074d293938195d3e2.zip | |
[460610] Avoids selection changes with the same semantic element.
* To avoid the behavior described in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=460610#c13 and
https://bugs.eclipse.org/bugs/show_bug.cgi?id=460610#c15, we avoid to
change the diagram selection if the set of selected semantic elements in
the common navigator is the same than the set of selected semantic
targets in the representation.
* This commit also completes the existing test.
Bug: 460610
Change-Id: I57f24247d6aa64c605db888d7de4bc41126b5cdb
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
5 files changed, 73 insertions, 10 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.aird index 41e39295df..b2ec9a0961 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.aird +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.aird @@ -38,7 +38,7 @@ <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_iptsQDT9EeWob9ff_334oA" source="DANNOTATION_CUSTOMIZATION_KEY"> <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_iptsQTT9EeWob9ff_334oA"/> </ownedAnnotationEntries> - <ownedDiagramElements xmi:type="diagram:DNodeList" xmi:id="_dT4aQGO5EeKAT86OkL5_zA" name="NewEClass1" tooltipText=".NewEClass1"> + <ownedDiagramElements xmi:type="diagram:DNodeList" xmi:id="_dT4aQGO5EeKAT86OkL5_zA" name="NewEClass1" tooltipText="root.NewEClass1"> <target xmi:type="ecore:EClass" href="VP-3832.ecore#//NewEClass1"/> <semanticElements xmi:type="ecore:EClass" href="VP-3832.ecore#//NewEClass1"/> <arrangeConstraints>KEEP_LOCATION</arrangeConstraints> @@ -130,6 +130,12 @@ <ownedStyle xmi:type="tree:TreeItemStyle" xmi:id="_cEQPxjXwEeWKWI3qJ9vddA"/> <actualMapping xmi:type="description_3:TreeItemMapping" href="tree.odesign#//@ownedViewpoints[name='tree']/@ownedRepresentations[name='Tree']/@subItemMappings[name='EPackage']"/> </ownedTreeItems> + <ownedTreeItems xmi:type="tree:DTreeItem" xmi:id="_NJ_EgETFEeW9NPfL0IWi9A" name="NewEClass12"> + <target xmi:type="ecore:EClass" href="VP-3832.ecore#//NewEClass1"/> + <semanticElements xmi:type="ecore:EClass" href="VP-3832.ecore#//NewEClass1"/> + <ownedStyle xmi:type="tree:TreeItemStyle" xmi:id="_NJ_EgUTFEeW9NPfL0IWi9A"/> + <actualMapping xmi:type="description_3:TreeItemMapping" href="tree.odesign#//@ownedViewpoints[name='tree']/@ownedRepresentations[name='Tree']/@subItemMappings[name='EClass2']"/> + </ownedTreeItems> <description xmi:type="description_3:TreeDescription" href="tree.odesign#//@ownedViewpoints[name='tree']/@ownedRepresentations[name='Tree']"/> </ownedRepresentations> <viewpoint xmi:type="description:Viewpoint" href="tree.odesign#//@ownedViewpoints[name='tree']"/> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.ecore b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.ecore index 104f5c8c0d..bfc8a8b1f1 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.ecore +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/VP-3832.ecore @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<ecore:EPackage xmi:version="2.0" - xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name=""> +<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="root" nsURI=""> <eClassifiers xsi:type="ecore:EClass" name="NewEClass1"/> <eSubpackages name="newPackage1"/> <eSubpackages name="newPackage2"/> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/tree.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/tree.odesign index 039dc31c19..8ea3fb9736 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/tree.odesign +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/VP-3832/tree.odesign @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/tree/description/1.0.0" name="cellEditor" version="10.1.0.201507101000"> +<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/tree/description/1.0.0" name="cellEditor" version="10.1.0.201507271600"> <ownedViewpoints name="tree"> <ownedRepresentations xsi:type="description_1:TreeDescription" name="Tree" domainClass="EPackage"> <subItemMappings name="EClass" domainClass="EClass" semanticCandidatesExpression="feature:eClassifiers"> @@ -14,6 +14,12 @@ <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> </defaultStyle> </subItemMappings> + <subItemMappings name="EClass2" domainClass="EClass" semanticCandidatesExpression="feature:eClassifiers"> + <defaultStyle labelExpression="[name + '2'/]"> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + </defaultStyle> + </subItemMappings> </ownedRepresentations> </ownedViewpoints> </description:Group> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/modelexplorer/LinkWithEditorFeatureWithModelExplorerViewTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/modelexplorer/LinkWithEditorFeatureWithModelExplorerViewTest.java index bdb9a1fc54..ae2eef9dbe 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/modelexplorer/LinkWithEditorFeatureWithModelExplorerViewTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/modelexplorer/LinkWithEditorFeatureWithModelExplorerViewTest.java @@ -41,6 +41,7 @@ public class LinkWithEditorFeatureWithModelExplorerViewTest extends AbstractSiri private static final String NEW_PACKAGE1 = "newPackage1"; private static final String NEW_PACKAGE2 = "newPackage2"; + private static final String ECLASS1 = "NewEClass1"; private static final String SEMANTIC_RESOURCE_NAME = "VP-3832.ecore"; @@ -259,6 +260,19 @@ public class LinkWithEditorFeatureWithModelExplorerViewTest extends AbstractSiri // We wait until it's actually selected in the model explorer view. bot.waitUntil(new ModelExplorerSelectionCondition(modelExplorerView, NEW_PACKAGE2)); + // Test with two graphical elements on the same semantic object. + selectNode(ECLASS1, modelExplorerView); + bot.waitUntil(new ModelExplorerSelectionCondition(modelExplorerView, ECLASS1)); + assertEquals("The Tree should have two selected elements", 2, representation.selection().rowCount()); + assertEquals("The first selected is not the one expected", ECLASS1, representation.selection().get(0, 0)); + assertEquals("The second selected is not the one expected", ECLASS1 + "2", + representation.selection().get(1, 0)); + + representation.getTreeItem(ECLASS1).select(); + bot.waitUntil(new ModelExplorerSelectionCondition(modelExplorerView, ECLASS1)); + + assertEquals("The Tree should have one selected elements", 1, representation.selection().rowCount()); + // we deactivate the link with editor modelExplorerView.toolbarToggleButton("Link with Editor").click(); @@ -267,7 +281,7 @@ public class LinkWithEditorFeatureWithModelExplorerViewTest extends AbstractSiri SWTBotUtils.waitAllUiEvents(); // The NewPackage2 should still be selected. - bot.waitUntil(new ModelExplorerSelectionCondition(modelExplorerView, NEW_PACKAGE2)); + bot.waitUntil(new ModelExplorerSelectionCondition(modelExplorerView, ECLASS1)); } finally { if (linkWithEditorInitialStatus != modelExplorerView.toolbarToggleButton("Link with Editor").isChecked()) { @@ -276,6 +290,13 @@ public class LinkWithEditorFeatureWithModelExplorerViewTest extends AbstractSiri } } + private void selectNode(String name, SWTBotView view) { + SWTBot projectExplorerBot = view.bot(); + SWTBotTreeItem projectItem = projectExplorerBot.tree().expandNode(getProjectName()); + SWTBotTreeItem fileNode = projectItem.expandNode(REPRESENTATIONS_RESOURCE_NAME).getNode(1).expand(); + fileNode.getNode("root").select(ECLASS1); + } + private void openDiagram(String representationName) { editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_DESCRIPTION_NAME, representationName, DDiagram.class); diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/SiriusDialectLinkWithEditorSelectionListener.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/SiriusDialectLinkWithEditorSelectionListener.java index 0a88aabee4..3fec39f0bf 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/SiriusDialectLinkWithEditorSelectionListener.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/SiriusDialectLinkWithEditorSelectionListener.java @@ -116,11 +116,15 @@ public class SiriusDialectLinkWithEditorSelectionListener implements ISelectionC IWorkbenchPage page = EclipseUIUtil.getActivePage(); IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof DialectEditor) { - page.bringToTop(activeEditor); DialectEditor dialectEditor = (DialectEditor) activeEditor; - List<DRepresentationElement> representationElements = getRepresentationElements(dialectEditor.getRepresentation(), ((IStructuredSelection) selection).toList()); - if (!representationElements.isEmpty()) { - DialectUIManager.INSTANCE.setSelection(dialectEditor, representationElements); + // We validate that the navigator selection is not already + // selected in the diagram. That avoids for instance to + // select multiple representation elements (with the same + // semantic target) if one of this element has already been + // selected in the representation. + if (isNotAlreadySelected((IStructuredSelection) selection, dialectEditor)) { + page.bringToTop(dialectEditor); + selectRepresentationElements(selection, dialectEditor); } } } else { @@ -137,6 +141,33 @@ public class SiriusDialectLinkWithEditorSelectionListener implements ISelectionC } } + private void selectRepresentationElements(ISelection selection, DialectEditor dialectEditor) { + List<DRepresentationElement> representationElements = getRepresentationElements(dialectEditor.getRepresentation(), ((IStructuredSelection) selection).toList()); + if (!representationElements.isEmpty()) { + DialectUIManager.INSTANCE.setSelection(dialectEditor, representationElements); + } + } + + @SuppressWarnings("unchecked") + private boolean isNotAlreadySelected(IStructuredSelection selection, DialectEditor dialectEditor) { + Set<EObject> selectedSemantics = getSelectedSemanticElementsInRepresentation(dialectEditor); + Set<EObject> navigatorSelection = new HashSet<EObject>(selection.toList()); + return !selectedSemantics.equals(navigatorSelection); + + } + + private Set<EObject> getSelectedSemanticElementsInRepresentation(DialectEditor editor) { + Set<EObject> semanticElements = new HashSet<EObject>(); + Collection<DSemanticDecorator> semanticDecorators = DialectUIManager.INSTANCE.getSelection(editor); + for (DSemanticDecorator decorator : semanticDecorators) { + EObject target = decorator.getTarget(); + if (target != null) { + semanticElements.add(target); + } + } + return semanticElements; + } + private List<DRepresentationElement> getRepresentationElements(final DRepresentation representation, final List<?> selection) { List<DRepresentationElement> result = Lists.newArrayList(); if (representation != null) { |
