Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Notot2013-04-22 15:57:44 +0000
committerCedric Notot2013-04-22 16:00:54 +0000
commit8ba3baa669152f985ff16cc79e83d5b13280c61a (patch)
treec7ff27072b45d65cb5e34ef9c65d5c6550c7c467
parent47b0282107e884c508185a1d65413f14983c2632 (diff)
downloadorg.eclipse.emf.compare-8ba3baa669152f985ff16cc79e83d5b13280c61a.tar.gz
org.eclipse.emf.compare-8ba3baa669152f985ff16cc79e83d5b13280c61a.tar.xz
org.eclipse.emf.compare-8ba3baa669152f985ff16cc79e83d5b13280c61a.zip
Bugs fixes on diagram changes:
- To avoid a NPE if no configuration found for coordinates change. - It is needed to add a requirement link from a macroscopic change and the related semantic one.
-rw-r--r--plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/CoordinatesChangeFactory.java5
-rw-r--r--plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/NodeChangeFactory.java57
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java32
3 files changed, 62 insertions, 32 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/CoordinatesChangeFactory.java b/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/CoordinatesChangeFactory.java
index f40a8c482..0f5ec7a6e 100644
--- a/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/CoordinatesChangeFactory.java
+++ b/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/CoordinatesChangeFactory.java
@@ -201,7 +201,10 @@ public class CoordinatesChangeFactory extends NodeChangeFactory {
final int rightY = ((Bounds)right).getY();
final int deltaX = Math.abs(leftX - rightX);
final int deltaY = Math.abs(leftY - rightY);
- final int threshold = configuration.getMoveThreshold();
+ int threshold = 0;
+ if (configuration != null) {
+ threshold = configuration.getMoveThreshold();
+ }
return deltaX + deltaY > threshold;
}
return false;
diff --git a/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/NodeChangeFactory.java b/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/NodeChangeFactory.java
index 4f3910c58..5f5ff816b 100644
--- a/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/NodeChangeFactory.java
+++ b/plugins/org.eclipse.emf.compare.diagram/src/org/eclipse/emf/compare/diagram/internal/factories/extensions/NodeChangeFactory.java
@@ -10,10 +10,18 @@
*******************************************************************************/
package org.eclipse.emf.compare.diagram.internal.factories.extensions;
+import static com.google.common.base.Predicates.and;
+import static com.google.common.base.Predicates.instanceOf;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+
import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.ReferenceChange;
@@ -22,8 +30,10 @@ import org.eclipse.emf.compare.diagram.internal.extensions.ExtensionsFactory;
import org.eclipse.emf.compare.diagram.internal.extensions.NodeChange;
import org.eclipse.emf.compare.diagram.internal.factories.AbstractDiagramChangeFactory;
import org.eclipse.emf.compare.utils.ReferenceUtil;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
/**
* Factory of node changes.
@@ -68,9 +78,52 @@ public class NodeChangeFactory extends AbstractDiagramChangeFactory {
public void setRefiningChanges(Diff extension, DifferenceKind extensionKind, Diff refiningDiff) {
// Macroscopic change on a node is refined by the unit main change and unit children related changes.
extension.getRefinedBy().add(refiningDiff);
- if (extensionKind != DifferenceKind.MOVE) {
- extension.getRefinedBy().addAll(getAllContainedDifferences(refiningDiff));
+ // if (extensionKind != DifferenceKind.MOVE) {
+ extension.getRefinedBy().addAll(getAllContainedDifferences(refiningDiff));
+ // }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.internal.postprocessor.factories.AbstractChangeFactory#fillRequiredDifferences(org.eclipse.emf.compare.Comparison,
+ * org.eclipse.emf.compare.Diff)
+ */
+ @Override
+ public void fillRequiredDifferences(Comparison comparison, Diff extension) {
+ super.fillRequiredDifferences(comparison, extension);
+ fillRequiredDifferencesForMove(comparison, extension);
+ }
+
+ /**
+ * MOVE case: The MOVE of a Node requires the MOVE of the semantic object.
+ *
+ * @see NodeChangeFactory#fillRequiredDifferences(Comparison, Diff).
+ * @param comparison
+ * the comparison.
+ * @param extension
+ * the node change.
+ */
+ private void fillRequiredDifferencesForMove(Comparison comparison, Diff extension) {
+ Set<Diff> requiredExtensions = new HashSet<Diff>();
+ Set<Diff> requiringExtensions = new HashSet<Diff>();
+ final Predicate<Diff> moveReference = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.MOVE));
+ Collection<Diff> refiningMoves = Collections2.filter(extension.getRefinedBy(), moveReference);
+ for (Diff diff : refiningMoves) {
+ EObject target = ((ReferenceChange)diff).getValue();
+ if (target instanceof View) {
+ EObject semanticTarget = ((View)target).getElement();
+ Collection<Diff> requiredDiffs = Collections2.filter(comparison
+ .getDifferences(semanticTarget), moveReference);
+ requiredExtensions.addAll(requiredDiffs);
+ // The graphical object and the semantic one are linked, they change their container both
+ // (difference case of ADD/DELETE)
+ requiringExtensions.addAll(requiredDiffs);
+ }
}
+ extension.getRequires().addAll(requiredExtensions);
+ extension.getRequiredBy().addAll(requiringExtensions);
}
/**
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java
index f459daa51..0b0d7cd06 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java
@@ -377,8 +377,9 @@ public abstract class AbstractChangeFactory implements IChangeFactory {
for (Diff candidate : match.getDifferences()) {
// Keep only unit changes...
if (!getExtensionKind().isInstance(candidate)) {
- // ... which are not related to an other macroscopic ADD or DELETE of a graphical object.
- if (!isAMainRefiningDifference(candidate)) {
+ // ... which are not related to an other macroscopic ADD or DELETE or MOVE of a graphical
+ // object.
+ if (getRelatedExtensionKind(candidate) == null) {
result.add(candidate);
} else if (candidate instanceof ReferenceChange
&& ((ReferenceChange)candidate).getReference().isContainment()) {
@@ -399,33 +400,6 @@ public abstract class AbstractChangeFactory implements IChangeFactory {
}
/**
- * It checks that the given difference is the main difference of a macroscopic change.
- *
- * @param difference
- * the difference to check.
- * @return True if the given difference is the main difference of a macroscopic change.
- */
- private boolean isAMainRefiningDifference(Diff difference) {
- CompareSwitch<Boolean> compareSwitch = new CompareSwitch<Boolean>() {
- @Override
- public Boolean caseReferenceChange(ReferenceChange object) {
- return isRelatedToAnExtensionAdd(object) || isRelatedToAnExtensionDelete(object);
- }
-
- @Override
- public Boolean caseResourceAttachmentChange(ResourceAttachmentChange object) {
- return isRelatedToAnExtensionAdd(object) || isRelatedToAnExtensionDelete(object);
- }
-
- @Override
- public Boolean defaultCase(EObject object) {
- return Boolean.FALSE;
- }
- };
- return compareSwitch.doSwitch(difference).booleanValue();
- }
-
- /**
* Get the distinct differences refined by the given differences.
*
* @param refiningDifferences

Back to the top