Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Guilet2019-08-21 10:50:37 -0400
committerPierre Guilet2019-08-22 11:03:48 -0400
commit40b209bd3a113aad8b924a6a514f83b6afdc48c3 (patch)
treef4fe6f8d18a5afe5edfbc1dbf90cc2726d2af68f
parentf1189d52815ecf0a1a71710865b27cdcaa1088fa (diff)
downloadorg.eclipse.sirius-40b209bd3a113aad8b924a6a514f83b6afdc48c3.tar.gz
org.eclipse.sirius-40b209bd3a113aad8b924a6a514f83b6afdc48c3.tar.xz
org.eclipse.sirius-40b209bd3a113aad8b924a6a514f83b6afdc48c3.zip
[548631] Fix tests and bugs after name and description move
Bug: 548631 Change-Id: I3a9bd957062db26cd023099722fc75e49fae0e0a Signed-off-by: Pierre Guilet <pierre.guilet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/DRepresentationDescriptorChangeIdTests.java31
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/DRepresentationQuery.java54
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java17
3 files changed, 53 insertions, 49 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/DRepresentationDescriptorChangeIdTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/DRepresentationDescriptorChangeIdTests.java
index 110c031f37..c68c97052f 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/DRepresentationDescriptorChangeIdTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/common/DRepresentationDescriptorChangeIdTests.java
@@ -61,6 +61,8 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
private DDiagram diagram2;
+ private IEditorPart editor;
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -68,7 +70,8 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
initViewpoint(DESIGN_VIEWPOINT_NAME);
diagram = (DDiagram) getRepresentations(ENTITIES_DESC_NAME).toArray()[0];
diagram2 = (DDiagram) getRepresentations(ENTITIES_DESC_NAME).toArray()[1];
-
+ editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
+ TestsUtil.synchronizationWithUIThread();
}
/**
@@ -76,9 +79,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
* {@link DRepresentationDescriptor} is updated.
*/
public void testDRepresentationElementUpdate() {
- final IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
- TestsUtil.synchronizationWithUIThread();
-
final EPackage ePackage = (EPackage) semanticModel;
final EClass eClass = createEClass(ePackage);
@@ -102,9 +102,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
* {@link DRepresentationDescriptor} is updated.
*/
public void testGMFElementUpdate() {
- final IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
- TestsUtil.synchronizationWithUIThread();
-
final EPackage ePackage = (EPackage) semanticModel;
final EClass eClass = createEClass(ePackage);
@@ -162,9 +159,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
* {@link DRepresentationDescriptor} is updated.
*/
public void testDRepresentationUpdate() {
- final IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
- TestsUtil.synchronizationWithUIThread();
-
String changeIdBeforeModification = new DRepresentationQuery(diagram).getRepresentationDescriptor().getChangeId();
session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
@@ -179,8 +173,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
assertNotEquals("Change id has not been updated.", changeIdBeforeModification, changeIdAfterModification);
- DialectUIManager.INSTANCE.closeEditor(editor, false);
- TestsUtil.synchronizationWithUIThread();
}
/**
@@ -188,9 +180,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
* {@link DRepresentationDescriptor} are updated.
*/
public void testmultiDRepresentationUpdate() {
- final IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
- TestsUtil.synchronizationWithUIThread();
-
String changeIdBeforeModification = new DRepresentationQuery(diagram).getRepresentationDescriptor().getChangeId();
String changeIdBeforeModification2 = new DRepresentationQuery(diagram2).getRepresentationDescriptor().getChangeId();
@@ -217,9 +206,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
* Tests that when a new {@link DRepresentationDescriptor} is modified, then its change id is not modified.
*/
public void testDRepresentationDescriptorNoChange() {
- final IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
- TestsUtil.synchronizationWithUIThread();
-
String changeIdBeforeModification = new DRepresentationQuery(diagram).getRepresentationDescriptor().getChangeId();
session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
@@ -242,9 +228,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
* Tests that when a transient feature related to a representation is modified, then its change id is not modified.
*/
public void testTransientFeatureNoChange() {
- final IEditorPart editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
- TestsUtil.synchronizationWithUIThread();
-
String changeIdBeforeModification = new DRepresentationQuery(diagram).getRepresentationDescriptor().getChangeId();
session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
@@ -258,9 +241,6 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
String changeIdAfterModification = new DRepresentationQuery(diagram).getRepresentationDescriptor().getChangeId();
assertEquals("Change id should not have been changed", changeIdBeforeModification, changeIdAfterModification);
-
- DialectUIManager.INSTANCE.closeEditor(editor, false);
- TestsUtil.synchronizationWithUIThread();
}
private EClass createEClass(final EPackage ePackage) {
@@ -271,7 +251,8 @@ public class DRepresentationDescriptorChangeIdTests extends SiriusDiagramTestCas
@Override
protected void tearDown() throws Exception {
-
+ DialectUIManager.INSTANCE.closeEditor(editor, false);
+ TestsUtil.synchronizationWithUIThread();
diagram = null;
super.tearDown();
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/DRepresentationQuery.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/DRepresentationQuery.java
index 9ef24b63bb..654318022c 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/DRepresentationQuery.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query/DRepresentationQuery.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
+import org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
import org.eclipse.sirius.viewpoint.DAnalysis;
@@ -148,27 +149,27 @@ public class DRepresentationQuery {
session = SessionManager.INSTANCE.getSession(((DSemanticDecorator) representation).getTarget());
}
if (session != null) {
- Collection<EStructuralFeature.Setting> usages = session.getSemanticCrossReferencer().getInverseReferences(representation);
- for (EStructuralFeature.Setting setting : usages) {
- if (ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR.isInstance(setting.getEObject())
- && setting.getEStructuralFeature() == ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR__REPRESENTATION) {
- result = (DRepresentationDescriptor) setting.getEObject();
- }
- }
+ result = findDescriptorFromCrossReferencer();
if (result == null) {
- EObject eObject = session.getAllSessionResources().iterator().next().getContents().get(0);
- if (eObject instanceof DAnalysis) {
- EList<DView> ownedViews = ((DAnalysis) eObject).getOwnedViews();
- for (DView view : ownedViews) {
- EList<DRepresentationDescriptor> ownedRepresentationDescriptors = view.getOwnedRepresentationDescriptors();
- for (DRepresentationDescriptor descriptor : ownedRepresentationDescriptors) {
- DRepresentation representationTemp = descriptor.getRepresentation();
- if (representation.equals(representationTemp)) {
- result = descriptor;
- break;
- }
- }
- }
+ result = findDescriptorFromAnalysis();
+ }
+ }
+ }
+ return result;
+ }
+
+ private DRepresentationDescriptor findDescriptorFromAnalysis() {
+ DRepresentationDescriptor result = null;
+ Collection<DAnalysis> allAnalyses = ((DAnalysisSessionImpl) session).allAnalyses();
+ for (DAnalysis dAnalysis : allAnalyses) {
+ EList<DView> ownedViews = dAnalysis.getOwnedViews();
+ for (DView view : ownedViews) {
+ EList<DRepresentationDescriptor> ownedRepresentationDescriptors = view.getOwnedRepresentationDescriptors();
+ for (DRepresentationDescriptor descriptor : ownedRepresentationDescriptors) {
+ DRepresentation representationTemp = descriptor.getRepresentation();
+ if (representation.equals(representationTemp)) {
+ result = descriptor;
+ break;
}
}
}
@@ -176,4 +177,17 @@ public class DRepresentationQuery {
return result;
}
+ private DRepresentationDescriptor findDescriptorFromCrossReferencer() {
+ DRepresentationDescriptor result = null;
+ Collection<EStructuralFeature.Setting> usages = session.getSemanticCrossReferencer().getInverseReferences(representation);
+ for (EStructuralFeature.Setting setting : usages) {
+ if (ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR.isInstance(setting.getEObject())
+ && setting.getEStructuralFeature() == ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR__REPRESENTATION) {
+ result = (DRepresentationDescriptor) setting.getEObject();
+ break;
+ }
+ }
+ return result;
+ }
+
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
index 2d5fb3f95e..f6988280ef 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
@@ -121,7 +121,6 @@ import org.eclipse.sirius.viewpoint.DView;
import org.eclipse.sirius.viewpoint.Messages;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.sirius.viewpoint.ViewpointPackage;
-import org.eclipse.sirius.viewpoint.description.IdentifiedElement;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.eclipse.sirius.viewpoint.impl.DAnalysisSessionEObjectImpl;
@@ -199,6 +198,10 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
private RepresentationNameListener representationNameListener;
+ private DRepresentationChangeListener dRepresentationChangeListener;
+
+ private ChangeIdUpdaterListener changeIdUpdaterListener;
+
/**
* Listener that clears the sub diagram decoration descriptors when a {@link DRepresentation} is either created or
* deleted.
@@ -285,7 +288,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
Object notifier = notification.getNotifier();
boolean isEObject = notifier instanceof EObject;
boolean isTransient = notification.getFeature() instanceof EStructuralFeature && ((EStructuralFeature) notification.getFeature()).isTransient();
- if (isEObject && !isTransient && notifier instanceof IdentifiedElement) {
+ if (isEObject && !isTransient && ViewpointPackage.Literals.IDENTIFIED_ELEMENT.isInstance(notifier)) {
final DRepresentationDescriptor representationDescriptor = getDRepresentationDescriptor((EObject) notifier);
if (representationDescriptor != null) {
descriptorsToUpdate.add(representationDescriptor);
@@ -372,8 +375,10 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
setResourceCollector(new LocalResourceCollector(getTransactionalEditingDomain().getResourceSet()));
setDeferSaveToPostCommit(true);
setSaveInExclusiveTransaction(true);
- getTransactionalEditingDomain().addResourceSetListener(new DRepresentationChangeListener(this));
- getTransactionalEditingDomain().addResourceSetListener(new ChangeIdUpdaterListener());
+ dRepresentationChangeListener = new DRepresentationChangeListener(this);
+ getTransactionalEditingDomain().addResourceSetListener(dRepresentationChangeListener);
+ changeIdUpdaterListener = new ChangeIdUpdaterListener();
+ getTransactionalEditingDomain().addResourceSetListener(changeIdUpdaterListener);
}
// *******************
@@ -1452,6 +1457,10 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
if (getRefreshEditorsListener() != null) {
removeListener(getRefreshEditorsListener());
}
+ getTransactionalEditingDomain().removeResourceSetListener(dRepresentationChangeListener);
+ dRepresentationChangeListener = null;
+ getTransactionalEditingDomain().removeResourceSetListener(changeIdUpdaterListener);
+ changeIdUpdaterListener = null;
refreshEditorsListeners = null;
reloadingPolicy = null;
savingPolicy = null;

Back to the top