The "accept/reject" all non-conflicting action shouldn't touch conflilts

Change-Id: I7977fcf32e86c86f75369563d438bf3f7abdc628
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeConflictingRunnable.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeConflictingRunnable.java
index 3084aa6..a486a90 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeConflictingRunnable.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeConflictingRunnable.java
@@ -15,6 +15,7 @@
 import static org.eclipse.emf.compare.ConflictKind.REAL;
 import static org.eclipse.emf.compare.DifferenceSource.LEFT;
 import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
+import static org.eclipse.emf.compare.merge.IMergeCriterion.NONE;
 import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasConflict;
 
 import com.google.common.collect.Sets;
@@ -35,6 +36,7 @@
 import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
 import org.eclipse.emf.compare.internal.utils.DiffUtil;
 import org.eclipse.emf.compare.merge.ComputeDiffsToMerge;
+import org.eclipse.emf.compare.merge.DiffRelationshipComputer;
 import org.eclipse.emf.compare.merge.IDiffRelationshipComputer;
 import org.eclipse.emf.compare.merge.IMerger;
 import org.eclipse.emf.compare.merge.IMerger.Registry;
@@ -114,7 +116,8 @@
 		}
 
 		final List<Diff> affectedDiffs = new ArrayList<Diff>();
-		final ComputeDiffsToMerge computer = new ComputeDiffsToMerge(!leftToRight, registry);
+		final ComputeDiffsToMerge computer = new ComputeDiffsToMerge(getMergeMode(), isLeftEditable(),
+				isRightEditable(), new DiffRelationshipComputer(registry, NONE));
 		computer.failOnRealConflictUnless(alwaysTrue());
 
 		conflictingDiffs.add(diff);
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java
index 0474482..2025065 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java
@@ -235,8 +235,9 @@
 			Registry mergerRegistry) {
 		final List<Diff> affectedDiffs = new ArrayList<Diff>();
 		final Monitor emfMonitor = new BasicMonitor();
-		ComputeDiffsToMerge computer = new ComputeDiffsToMerge(!leftToRight,
-				getDiffRelationshipComputer(mergerRegistry)).failOnRealConflictUnless(alwaysFalse());
+		ComputeDiffsToMerge computer = new ComputeDiffsToMerge(getMergeMode(), isLeftEditable(),
+				isRightEditable(), getDiffRelationshipComputer(mergerRegistry))
+						.failOnRealConflictUnless(alwaysFalse());
 
 		final Predicate<? super Diff> filter;
 		MergeMode mode = getMergeMode();
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ComputeDiffsToMerge.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ComputeDiffsToMerge.java
index 006d149..ae3f270 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ComputeDiffsToMerge.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ComputeDiffsToMerge.java
@@ -12,7 +12,6 @@
 package org.eclipse.emf.compare.merge;
 
 import static org.eclipse.emf.compare.ConflictKind.REAL;
-import static org.eclipse.emf.compare.merge.IMergeCriterion.NONE;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Sets;
@@ -25,6 +24,7 @@
 
 import org.eclipse.emf.compare.Conflict;
 import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
 
 /**
  * This class computes the diffs to merge for a given diff in the correct order, taking into account the
@@ -32,7 +32,7 @@
  * <dl>
  * <dt>Required diffs</dt>
  * <dd>These are the diffs that need to be merged (from a structural point of view) before a given diff for
- * this diff to be mergeabl by th merger.</dd>
+ * this diff to be mergeable by the merger.</dd>
  * <dt>Consequent diffs</dt>
  * <dd>These are all the diffs that, for some reason, the merger considers necessary to merge along with a
  * given diff, but which need not be merged before this diff for the merger to be able to merge it. This is
@@ -47,11 +47,23 @@
 public class ComputeDiffsToMerge {
 
 	/**
-	 * The direction of the merge, <code>true</code> for right to left.
+	 * If this is not acting on a MergeMode (i.e. direction is on a diff-by-diff basis), this will define the
+	 * global direction of the merge.
 	 */
 	private final boolean rightToLeft;
 
 	/**
+	 * The current merging mode.
+	 */
+	private final MergeMode mergeMode;
+
+	/** Tells us whether the left side of the comparison we're operating on is editable. */
+	private final boolean isLeftEditable;
+
+	/** Tells us whether the right side of the comparison we're operating on is editable. */
+	private final boolean isRightEditable;
+
+	/**
 	 * The ordered set of diffs to merge.
 	 */
 	private Set<Diff> result = new LinkedHashSet<Diff>();
@@ -76,39 +88,50 @@
 	/**
 	 * Constructor.
 	 * 
-	 * @param rightToLeft
-	 *            The merge direction
-	 * @param registry
-	 *            The Registry to use.
+	 * @param mergeMode
+	 *            The kind of merging we're about to implement.
+	 * @param isLeftEditable
+	 *            Whether the left side of the comparison we're operating on is editable.
+	 * @param isRightEditable
+	 *            Whether the right side of the comparison we're operating on is editable.
+	 * @param relationshipComputer
+	 *            The relationship computer used to calculate dependencies and requirements of diffs.
 	 */
-	public ComputeDiffsToMerge(boolean rightToLeft, IMerger.Registry2 registry) {
-		this(rightToLeft, new DiffRelationshipComputer(registry, NONE));
+	public ComputeDiffsToMerge(MergeMode mergeMode, boolean isLeftEditable, boolean isRightEditable,
+			IDiffRelationshipComputer relationshipComputer) {
+		this(true, mergeMode, isLeftEditable, isRightEditable, relationshipComputer);
 	}
 
 	/**
-	 * Constructor.
+	 * Constructor if there is no merge mode for this action.
 	 * 
 	 * @param rightToLeft
-	 *            The merge direction
-	 * @param registry
-	 *            The Registry to use.
-	 * @param criterion
-	 *            The merge criterion, must not be <code>null</code>
-	 */
-	public ComputeDiffsToMerge(boolean rightToLeft, IMerger.Registry2 registry, IMergeCriterion criterion) {
-		this(rightToLeft, new DiffRelationshipComputer(registry, criterion));
-	}
-
-	/**
-	 * Constructor.
-	 * 
-	 * @param rightToLeft
-	 *            The merge direction
+	 *            Direction of the merge.
 	 * @param relationshipComputer
 	 *            The relationship computer used to calculate dependencies and requirements of diffs.
 	 */
 	public ComputeDiffsToMerge(boolean rightToLeft, IDiffRelationshipComputer relationshipComputer) {
+		this(rightToLeft, null, true, true, relationshipComputer);
+	}
+
+	/**
+	 * @param rightToLeft
+	 *            Direction of the merge. Ignored if {@link MergeMode} is not null.
+	 * @param mergeMode
+	 *            The kind of merging we're about to implement.
+	 * @param isLeftEditable
+	 *            Whether the left side of the comparison we're operating on is editable.
+	 * @param isRightEditable
+	 *            Whether the right side of the comparison we're operating on is editable.
+	 * @param relationshipComputer
+	 *            The relationship computer used to calculate dependencies and requirements of diffs.
+	 */
+	private ComputeDiffsToMerge(boolean rightToLeft, MergeMode mergeMode, boolean isLeftEditable,
+			boolean isRightEditable, IDiffRelationshipComputer relationshipComputer) {
 		this.rightToLeft = rightToLeft;
+		this.mergeMode = mergeMode;
+		this.isLeftEditable = isLeftEditable;
+		this.isRightEditable = isRightEditable;
 		this.relationshipComputer = relationshipComputer;
 	}
 
@@ -224,7 +247,11 @@
 				}
 			}
 
-			Set<Diff> dependencies = relationshipComputer.getDirectMergeDependencies(diff, rightToLeft);
+			boolean mergeRightToLeft = rightToLeft;
+			if (mergeMode != null) {
+				mergeRightToLeft = !mergeMode.isLeftToRight(diff, isLeftEditable, isRightEditable);
+			}
+			Set<Diff> dependencies = relationshipComputer.getDirectMergeDependencies(diff, mergeRightToLeft);
 			for (Diff required : dependencies) {
 				addDiff(required, consequences, diffPath);
 			}
@@ -233,7 +260,7 @@
 			computing.remove(diff);
 
 			final Set<Diff> directResultingMerges = relationshipComputer.getDirectResultingMerges(diff,
-					rightToLeft);
+					mergeRightToLeft);
 			consequences.addAll(directResultingMerges);
 
 			if (addedToPath) {