Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfesenko2010-12-09 10:33:48 +0000
committertfesenko2010-12-09 10:33:48 +0000
commit204499c88d7e70cec7308749019efdd93c2b3028 (patch)
tree20a17cdf74f5b3422b42184984d0b327a6d2ed7d /extraplugins
parent1698e99d5046388c62f3e85d137867a774078091 (diff)
downloadorg.eclipse.papyrus-204499c88d7e70cec7308749019efdd93c2b3028.tar.gz
org.eclipse.papyrus-204499c88d7e70cec7308749019efdd93c2b3028.tar.xz
org.eclipse.papyrus-204499c88d7e70cec7308749019efdd93c2b3028.zip
330183 - [Usability] Papyrus shall enable comparing/merging models.
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/CompareTwoElementsEngine.java68
-rw-r--r--extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/action/CompareTwoElementsAction.java11
2 files changed, 76 insertions, 3 deletions
diff --git a/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/CompareTwoElementsEngine.java b/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/CompareTwoElementsEngine.java
new file mode 100644
index 00000000000..9f11cb66714
--- /dev/null
+++ b/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/CompareTwoElementsEngine.java
@@ -0,0 +1,68 @@
+package org.eclipse.papyrus.compare;
+
+import java.util.Collection;
+
+import org.eclipse.emf.compare.FactoryException;
+import org.eclipse.emf.compare.diff.metamodel.DiffFactory;
+import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
+import org.eclipse.emf.compare.diff.metamodel.DiffModel;
+import org.eclipse.emf.compare.match.metamodel.Match2Elements;
+import org.eclipse.emf.compare.match.metamodel.MatchFactory;
+import org.eclipse.emf.compare.match.metamodel.MatchModel;
+import org.eclipse.emf.compare.match.metamodel.MatchPackage;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+
+public class CompareTwoElementsEngine extends PapyrusDiffEngine {
+
+ public EObject left;
+
+ public EObject right;
+ @Override
+ public DiffModel doDiff(MatchModel match) {
+ // TODO Auto-generated method stub
+ return super.doDiff(match);
+ }
+
+ protected DiffGroup doDiffTwoWay(MatchModel match) {
+ final DiffGroup diffRoot = DiffFactory.eINSTANCE.createDiffGroup();
+
+ // It is a possibility that no elements were matched
+ if (match.getMatchedElements().size() > 0) {
+ // we have to browse the model and create the corresponding operations
+ final Match2Elements matchRoot = (Match2Elements)match.getMatchedElements().get(0);
+ // browsing the match model
+
+ final DiffGroup current = diffRoot;
+ Match2Elements match2Element = MatchFactory.eINSTANCE.createMatch2Elements();
+ match2Element.setLeftElement(left);
+ match2Element.setRightElement(right);
+ current.setRightParent(match2Element.getRightElement());
+ try {
+ checkForDiffs(current, match2Element);
+ } catch (final FactoryException e) {
+ log(e);
+ }
+ }
+ // iterate over the unmatched elements end determine if they have been
+ // added or removed.
+ processUnmatchedElements(diffRoot, match.getUnmatchedElements());
+ return diffRoot;
+ }
+
+
+
+ protected EObject getMatch(EObject from) {
+ final Collection<EStructuralFeature.Setting> settings = matchCrossReferencer.get(from);
+ if (settings == null)
+ return null;
+ for (final org.eclipse.emf.ecore.EStructuralFeature.Setting setting : settings) {
+ if (setting.getEObject() instanceof Match2Elements) {
+ return setting.getEObject();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/action/CompareTwoElementsAction.java b/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/action/CompareTwoElementsAction.java
index 0c8a79824dc..9fc52658052 100644
--- a/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/action/CompareTwoElementsAction.java
+++ b/extraplugins/compare/org.eclipse.papyrus.compare/src/org/eclipse/papyrus/compare/action/CompareTwoElementsAction.java
@@ -31,10 +31,12 @@ import org.eclipse.emf.compare.match.metamodel.MatchFactory;
import org.eclipse.emf.compare.match.metamodel.MatchModel;
import org.eclipse.emf.compare.match.service.MatchService;
import org.eclipse.emf.compare.util.EMFCompareMap;
+import org.eclipse.emf.compare.util.EngineConstants;
import org.eclipse.emf.compare.util.ModelUtils;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.papyrus.compare.CompareTwoElementsEngine;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.actions.TeamAction;
import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
@@ -125,9 +127,12 @@ public class CompareTwoElementsAction extends TeamAction {
// do comparison
final MatchModel match;
options.put(MatchOptions.OPTION_MATCH_SCOPE_PROVIDER, new GenericMatchScopeProvider(
- left, right));
- match = MatchService.doContentMatch(left, right, options);
- final DiffModel diff = DiffService.doDiff(match, false);
+ left.eResource(), right.eResource()));
+ match = MatchService.doMatch(left, right, options);
+ CompareTwoElementsEngine engine = new CompareTwoElementsEngine();
+ engine.left = left;
+ engine.right = right;
+ final DiffModel diff = engine.doDiff(match);
snapshot.setDiff(diff);
snapshot.setMatch(match);
}

Back to the top