diff options
author | Mikaël Barbero | 2013-10-08 10:18:42 +0000 |
---|---|---|
committer | Mikaël Barbero | 2013-10-11 14:22:30 +0000 |
commit | 693a08962392bdb31c894bd02c31dfffe3d61847 (patch) | |
tree | 3114de2e0fb321bacc771863f0bf2fdd3f94230e | |
parent | b09d1f1e084aaa201b87ee9de2b8d5a8c1611b79 (diff) | |
download | org.eclipse.emf.compare-693a08962392bdb31c894bd02c31dfffe3d61847.tar.gz org.eclipse.emf.compare-693a08962392bdb31c894bd02c31dfffe3d61847.tar.xz org.eclipse.emf.compare-693a08962392bdb31c894bd02c31dfffe3d61847.zip |
Introduce MergeMode and rewrite actions.
This simplifies implementation of merge actions and all UI related to
merge.
Change-Id: I3330c7de23abbca9744d4082b11e2b30b26e9e2f
35 files changed, 1170 insertions, 1763 deletions
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeCommand.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeCommand.java new file mode 100644 index 000000000..b77e05715 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/command/impl/MergeCommand.java @@ -0,0 +1,66 @@ +/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.command.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.domain.IMergeRunnable;
+import org.eclipse.emf.compare.merge.IMerger;
+import org.eclipse.emf.ecore.change.util.ChangeRecorder;
+
+/**
+ * A merge command that delegates it {@link #doExecute()} to the
+ * {@link IMergeRunnable#merge(List, boolean, IMerger.Registry)} method.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public class MergeCommand extends AbstractCopyCommand {
+
+ /** The merge runnable to delegate to. */
+ private final IMergeRunnable runnable;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param changeRecorder
+ * The change recorder associated to this command.
+ * @param notifiers
+ * The collection of notifiers that will be notified of this command's execution.
+ * @param differences
+ * The list of differences that this command should merge.
+ * @param leftToRight
+ * The direction in which {@code differences} should be merged.
+ * @param mergerRegistry
+ * The registry of mergers.
+ * @param runnable
+ * The merge runnable to delegate to.
+ */
+ public MergeCommand(ChangeRecorder changeRecorder, Collection<Notifier> notifiers,
+ List<? extends Diff> differences, boolean leftToRight, IMerger.Registry mergerRegistry,
+ IMergeRunnable runnable) {
+ super(changeRecorder, notifiers, differences, leftToRight, mergerRegistry);
+ this.runnable = runnable;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.edit.command.ChangeCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ runnable.merge(differences, leftToRight, mergerRegistry);
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/ICompareEditingDomain.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/ICompareEditingDomain.java index 5c57f2303..043377d3f 100644 --- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/ICompareEditingDomain.java +++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/ICompareEditingDomain.java @@ -15,6 +15,7 @@ import java.util.List; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.compare.Diff; import org.eclipse.emf.compare.command.ICompareCommandStack; +import org.eclipse.emf.compare.command.ICompareCopyCommand; import org.eclipse.emf.compare.merge.IMerger; import org.eclipse.emf.ecore.change.util.ChangeRecorder; @@ -58,4 +59,24 @@ public interface ICompareEditingDomain { Command createCopyCommand(List<? extends Diff> differences, boolean leftToRight, IMerger.Registry mergerRegistry); + /** + * Creates a new command that will execute the given {@link IMergeRunnable} that is expected to merge the + * given differences in from right to left or left to right by using the mergers defined in the given + * merger registry. + * + * @param differences + * the differences to merge. + * @param leftToRight + * whether the merge has to be merge from left to right or right to left. + * @param mergerRegistry + * the merger registry to query to get the appropriate mergers for each difference to be + * merged. + * @param runnable + * the runnable that will implement the merge + * @return the created command. + * @since 4.0 + */ + ICompareCopyCommand createCopyCommand(List<? extends Diff> differences, boolean leftToRight, + IMerger.Registry mergerRegistry, IMergeRunnable runnable); + } diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/IMergeRunnable.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/IMergeRunnable.java new file mode 100644 index 000000000..fe2213660 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/IMergeRunnable.java @@ -0,0 +1,38 @@ +/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.domain;
+
+import java.util.List;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.merge.IMerger.Registry;
+
+/**
+ * Interface for executing merge commands from the {@link ICompareEditingDomain}.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public interface IMergeRunnable {
+
+ /**
+ * Execute the merge operation.
+ *
+ * @param differences
+ * the differences to merge.
+ * @param leftToRight
+ * whether the merge has to be merge from left to right or right to left.
+ * @param mergerRegistry
+ * the merger registry to query to get the appropriate mergers for each difference to be
+ * merged.
+ */
+ void merge(List<? extends Diff> differences, boolean leftToRight, Registry mergerRegistry);
+
+}
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/impl/EMFCompareEditingDomain.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/impl/EMFCompareEditingDomain.java index 9164c356c..d262cefee 100644 --- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/impl/EMFCompareEditingDomain.java +++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/domain/impl/EMFCompareEditingDomain.java @@ -22,11 +22,15 @@ import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.compare.Diff; import org.eclipse.emf.compare.command.ICompareCommandStack; +import org.eclipse.emf.compare.command.ICompareCopyCommand; import org.eclipse.emf.compare.command.impl.CompareCommandStack; import org.eclipse.emf.compare.command.impl.CopyCommand; import org.eclipse.emf.compare.command.impl.DualCompareCommandStack; +import org.eclipse.emf.compare.command.impl.MergeCommand; import org.eclipse.emf.compare.domain.ICompareEditingDomain; +import org.eclipse.emf.compare.domain.IMergeRunnable; import org.eclipse.emf.compare.merge.IMerger; +import org.eclipse.emf.compare.merge.IMerger.Registry; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.change.util.ChangeRecorder; import org.eclipse.emf.ecore.resource.Resource; @@ -268,6 +272,25 @@ public class EMFCompareEditingDomain implements ICompareEditingDomain { /** * {@inheritDoc} * + * @see org.eclipse.emf.compare.domain.ICompareEditingDomain#createCopyCommand(java.util.List, boolean, + * org.eclipse.emf.compare.merge.IMerger.Registry, + * org.eclipse.emf.compare.command.ICompareCopyCommand.IMergeRunnable) + */ + public ICompareCopyCommand createCopyCommand(List<? extends Diff> differences, boolean leftToRight, + Registry mergerRegistry, IMergeRunnable runnable) { + ImmutableSet.Builder<Notifier> notifiersBuilder = ImmutableSet.builder(); + for (Diff diff : differences) { + notifiersBuilder.add(diff.getMatch().getComparison()); + } + ImmutableSet<Notifier> notifiers = notifiersBuilder.addAll(fNotifiers).build(); + + return new MergeCommand(fChangeRecorder, notifiers, differences, leftToRight, mergerRegistry, + runnable); + } + + /** + * {@inheritDoc} + * * @see org.eclipse.emf.compare.domain.ICompareEditingDomain#getChangeRecorder() */ public ChangeRecorder getChangeRecorder() { diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java index 1d12f0130..238a28b66 100644 --- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java +++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java @@ -25,7 +25,7 @@ import org.eclipse.emf.compare.DifferenceKind; import org.eclipse.emf.compare.DifferenceSource; import org.eclipse.emf.compare.DifferenceState; import org.eclipse.emf.compare.Match; -import org.eclipse.emf.compare.internal.merge.IDiffMergeData; +import org.eclipse.emf.compare.internal.merge.IMergeData; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.edit.provider.ComposedImage; @@ -36,6 +36,15 @@ import org.eclipse.emf.edit.provider.ComposedImage; */ public class OverlayImageProvider { + /** The base name of the change (and move) kind of diff overlay. */ + private static final String CHG_OV = "chg_ov"; //$NON-NLS-1$ + + /** The base name of the deletion kind of diff overlay. */ + private static final String DEL_OV = "del_ov"; //$NON-NLS-1$ + + /** The base name of the add kind of diff overlay. */ + private static final String ADD_OV = "add_ov"; //$NON-NLS-1$ + /** The base name of the merge to right diff overlay. */ private static final String MERGED_TO_RIGHT_OV = "merged_right_ov"; //$NON-NLS-1$ @@ -129,22 +138,7 @@ public class OverlayImageProvider { } else if (comparison.isThreeWay()) { path += getThreeWayOverlay(diff); } else { - final DifferenceKind diffKind = diff.getKind(); - switch (diffKind) { - case ADD: - path += "add_ov"; - break; - case DELETE: - path += "del_ov"; - break; - case CHANGE: - // fallthrough - case MOVE: - path += "chg_ov"; - break; - default: - break; - } + path += getTwoWayDiffOverlay(diff); } return path; } @@ -187,15 +181,15 @@ public class OverlayImageProvider { switch (diffKind) { case ADD: - path += "add_ov"; + path += ADD_OV; break; case DELETE: - path += "del_ov"; + path += DEL_OV; break; case CHANGE: // fallthrough case MOVE: - path += "chg_ov"; + path += CHG_OV; break; default: // Cannot happen ... for now @@ -213,26 +207,62 @@ public class OverlayImageProvider { */ private String getMergedOverlay(Diff diff) { final String path; - Adapter adapter = EcoreUtil.getExistingAdapter(diff, IDiffMergeData.class); + Adapter adapter = EcoreUtil.getExistingAdapter(diff, IMergeData.class); if (adapter != null) { - IDiffMergeData mergeData = (IDiffMergeData)adapter; - if (!mergeData.isLeftEditable() || !mergeData.isRightEditable()) { - if (mergeData.mergedTo() == diff.getSource()) { - path = REJECTED_OV; - } else { - path = ACCEPTED_OV; - } - } else if (mergeData.isLeftEditable() && mergeData.isRightEditable()) { - if (mergeData.hasBeenMergedToLeft()) { - path = MERGED_TO_LEFT_OV; - } else { + IMergeData mergeData = (IMergeData)adapter; + switch (mergeData.getMergeMode()) { + case LEFT_TO_RIGHT: path = MERGED_TO_RIGHT_OV; - } - } else { - path = ACCEPTED_OV; + break; + case RIGHT_TO_LEFT: + path = MERGED_TO_LEFT_OV; + break; + case ACCEPT: + path = ACCEPTED_OV; + break; + case REJECT: + path = REJECTED_OV; + break; + default: + throw new IllegalStateException(); } } else { - path = ACCEPTED_OV; + // fall-back to standard overlay. + final Match match = diff.getMatch(); + final Comparison comparison = match.getComparison(); + if (comparison.isThreeWay()) { + path = getThreeWayOverlay(diff); + } else { + path = getTwoWayDiffOverlay(diff); + } + } + return path; + } + + /** + * Returns the overlay path for the given unmerged diff. + * + * @param diff + * the diff we have to find an image for. + * @return the overlay path for the given unmerged diff. + */ + private String getTwoWayDiffOverlay(Diff diff) { + final String path; + final DifferenceKind diffKind = diff.getKind(); + switch (diffKind) { + case ADD: + path = ADD_OV; + break; + case DELETE: + path = DEL_OV; + break; + case CHANGE: + // fallthrough + case MOVE: + path = CHG_OV; + break; + default: + throw new IllegalStateException(); } return path; } diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java index ef5da4b93..8de0ae5d5 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/configuration/EMFCompareConfiguration.java @@ -26,6 +26,7 @@ import org.eclipse.emf.compare.Comparison; import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration;
import org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
@@ -65,8 +66,6 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl private static final String PREVIEW_MERGE_MODE = EMFCompareIDEUIPlugin.PLUGIN_ID + ".PREVIEW_MERGE_MODE"; //$NON-NLS-1$
- private static final Boolean PREVIEW_MERGE_MODE__DEFAULT_VALUE = Boolean.FALSE;
-
private final List<IEMFCompareConfigurationChangeListener> listeners;
private final PropertyChangeListener propertyChangeListener;
@@ -97,7 +96,11 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl SELECTED_DIFFERENCE_GROUP_PROVIDER__DEFAULT_VALUE);
}
- compareConfiguration.setProperty(PREVIEW_MERGE_MODE, PREVIEW_MERGE_MODE__DEFAULT_VALUE);
+ if (compareConfiguration.isLeftEditable() && compareConfiguration.isRightEditable()) {
+ compareConfiguration.setProperty(PREVIEW_MERGE_MODE, MergeMode.RIGHT_TO_LEFT);
+ } else {
+ compareConfiguration.setProperty(PREVIEW_MERGE_MODE, MergeMode.ACCEPT);
+ }
}
/**
@@ -192,12 +195,13 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl setProperty(SELECTED_DIFFERENCE_GROUP_PROVIDER, groupProvider);
}
- public boolean getPreviewMergeMode() {
- return ((Boolean)getProperty(PREVIEW_MERGE_MODE)).booleanValue();
+ public MergeMode getMergePreviewMode() {
+ return (MergeMode)getProperty(PREVIEW_MERGE_MODE);
}
- public void setPreviewMergeMode(boolean previewMergeMode) {
- setProperty(PREVIEW_MERGE_MODE, Boolean.valueOf(previewMergeMode));
+ public void setMergePreviewMode(MergeMode previewMergeMode) {
+ Preconditions.checkNotNull(previewMergeMode);
+ setProperty(PREVIEW_MERGE_MODE, previewMergeMode);
}
public AdapterFactory getAdapterFactory() {
@@ -306,10 +310,10 @@ public class EMFCompareConfiguration extends ForwardingCompareConfiguration impl }
protected void handlePreviewMergeModeChange(PropertyChangeEvent event) {
- Boolean oldValue = (Boolean)event.getOldValue();
- Boolean newValue = (Boolean)event.getNewValue();
+ MergeMode oldValue = (MergeMode)event.getOldValue();
+ MergeMode newValue = (MergeMode)event.getNewValue();
for (IEMFCompareConfigurationChangeListener listener : listeners) {
- listener.previewMergeModeChange(oldValue.booleanValue(), newValue.booleanValue());
+ listener.mergePreviewModeChange(oldValue, newValue);
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java index 22499aa45..daf15d86e 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeRuler.java @@ -15,7 +15,6 @@ import static com.google.common.collect.Iterables.filter; import com.google.common.base.Predicate; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -33,6 +32,7 @@ import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.compare.Diff; import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; +import org.eclipse.emf.compare.internal.merge.MergeMode; import org.eclipse.emf.compare.internal.utils.DiffUtil; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter; import org.eclipse.emf.ecore.EObject; @@ -239,28 +239,11 @@ public class EMFCompareDiffTreeRuler extends Canvas { public void computeConsequences() { clearAllData(); if (selectedDiff != null) { - boolean ltr = fConfiguration.getPreviewMergeMode(); - boolean leftEditable = fConfiguration.isLeftEditable(); - boolean rightEditable = fConfiguration.isRightEditable(); - - if (rightEditable) { - if (leftEditable) { // RW both sides - requires = DiffUtil.getRequires(selectedDiff, ltr); - unmergeables = DiffUtil.getUnmergeables(selectedDiff, ltr); - } else { // !leftEditable - requires = DiffUtil.getRequires(selectedDiff, !ltr); - unmergeables = DiffUtil.getUnmergeables(selectedDiff, !ltr); - } - } else { // !rightEditable - if (leftEditable) { - requires = DiffUtil.getRequires(selectedDiff, ltr); - unmergeables = DiffUtil.getUnmergeables(selectedDiff, ltr); - } else { // R-Only both - // nothing - requires = ImmutableSet.of(); - unmergeables = ImmutableSet.of(); - } - } + MergeMode mergePreviewMode = fConfiguration.getMergePreviewMode(); + boolean leftToRigh = mergePreviewMode.isLeftToRight(fConfiguration.isLeftEditable(), + fConfiguration.isRightEditable()); + requires = DiffUtil.getRequires(selectedDiff, leftToRigh); + unmergeables = DiffUtil.getUnmergeables(selectedDiff, leftToRigh); associateTreeItems(Lists.newLinkedList(Iterables.concat(requires, unmergeables))); } } diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java index 8b5b64058..c36001ba0 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareDiffTreeViewer.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer; +import static com.google.common.base.Predicates.instanceOf; +import static com.google.common.collect.Iterables.any; +import static com.google.common.collect.Lists.newArrayListWithCapacity; import static com.google.common.collect.Sets.newHashSet; import static com.google.common.collect.Sets.newLinkedHashSet; @@ -25,6 +28,7 @@ import com.google.common.eventbus.Subscribe; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; +import java.util.EnumSet; import java.util.List; import java.util.ListIterator; import java.util.Set; @@ -42,28 +46,27 @@ import org.eclipse.emf.compare.Comparison; import org.eclipse.emf.compare.Conflict; import org.eclipse.emf.compare.Diff; import org.eclipse.emf.compare.DifferenceSource; +import org.eclipse.emf.compare.domain.ICompareEditingDomain; import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AcceptAllChangesAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AcceptChangeAction; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.CollapseAllModelAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.DropDownAcceptRejectMenuAction; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.DropDownMergeMenuAction; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.ExpandAllModelAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAllToLeftAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAllToRightAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeToLeftAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeToRightAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.RejectAllChangesAction; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.RejectChangeAction; +import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAction; +import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAllNonConflictingAction; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.SaveComparisonModelAction; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.SelectNextDiffAction; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.SelectPreviousDiffAction; +import org.eclipse.emf.compare.internal.merge.MergeMode; import org.eclipse.emf.compare.internal.utils.DiffUtil; +import org.eclipse.emf.compare.merge.IMerger; +import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; +import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.actions.FilterActionMenu; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.actions.GroupActionMenu; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilterSelectionChangeEvent; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.StructureMergeViewerFilter; +import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl.CascadingDifferencesFilter; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.StructureMergeViewerGrouper; import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl.DefaultGroupProvider; @@ -150,6 +153,10 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { private AdapterFactory adapterFactory; + private List<MergeAction> mergeActions = newArrayListWithCapacity(4); + + private List<MergeAllNonConflictingAction> mergeAllNonConflictingActions = newArrayListWithCapacity(2); + /** * @param parent * @param adapterFactory @@ -252,6 +259,62 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { } }; getTree().setData(INavigatable.NAVIGATOR_PROPERTY, nav); + + configurationChangeListener = new EMFCompareConfigurationChangeListener() { + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#editingDomainChange(org.eclipse.emf.compare.domain.ICompareEditingDomain, + * org.eclipse.emf.compare.domain.ICompareEditingDomain) + */ + @Override + public void editingDomainChange(ICompareEditingDomain oldValue, ICompareEditingDomain newValue) { + for (MergeAction mergeAction : mergeActions) { + mergeAction.setEditingDomain(newValue); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#selectedDifferenceFiltersChange(java.util.Set, + * java.util.Set) + */ + @Override + public void selectedDifferenceFiltersChange(Set<IDifferenceFilter> oldValue, + Set<IDifferenceFilter> newValue) { + final boolean enabled = any(newValue, instanceOf(CascadingDifferencesFilter.class)); + for (MergeAction mergeAction : mergeActions) { + mergeAction.setCascadingDifferencesFilterEnabled(enabled); + } + getTree().redraw(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#mergePreviewModeChange(org.eclipse.emf.compare.internal.merge.MergeMode, + * org.eclipse.emf.compare.internal.merge.MergeMode) + */ + @Override + public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) { + getTree().redraw(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener#comparisonChange(org.eclipse.emf.compare.Comparison, + * org.eclipse.emf.compare.Comparison) + */ + @Override + public void comparisonChange(Comparison oldValue, Comparison newValue) { + for (MergeAllNonConflictingAction mergeAction : mergeAllNonConflictingActions) { + mergeAction.setComparison(newValue); + } + } + }; + configuration.addChangeListener(configurationChangeListener); } /** @@ -409,6 +472,8 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { } }; + private final EMFCompareConfigurationChangeListener configurationChangeListener; + /** * Returns the sorted and filtered set of TreeNode children of the given element. * @@ -664,19 +729,21 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { boolean leftEditable = getCompareConfiguration().isLeftEditable(); boolean rightEditable = getCompareConfiguration().isRightEditable(); + final EnumSet<MergeMode> modes; if (rightEditable && leftEditable) { - toolbarManager.add(new DropDownMergeMenuAction(getCompareConfiguration())); - toolbarManager.add(new MergeToRightAction(getCompareConfiguration(), this)); - toolbarManager.add(new MergeToLeftAction(getCompareConfiguration(), this)); - toolbarManager.add(new MergeAllToRightAction(getCompareConfiguration())); - toolbarManager.add(new MergeAllToLeftAction(getCompareConfiguration())); + modes = EnumSet.of(MergeMode.RIGHT_TO_LEFT, MergeMode.LEFT_TO_RIGHT); } else { - toolbarManager.add(new DropDownAcceptRejectMenuAction(getCompareConfiguration())); - toolbarManager.add(new AcceptChangeAction(getCompareConfiguration(), this)); - toolbarManager.add(new RejectChangeAction(getCompareConfiguration(), this)); - toolbarManager.add(new AcceptAllChangesAction(getCompareConfiguration())); - toolbarManager.add(new RejectAllChangesAction(getCompareConfiguration())); + modes = EnumSet.of(MergeMode.ACCEPT, MergeMode.REJECT); + } + + toolbarManager.add(new DropDownMergeMenuAction(getCompareConfiguration(), modes)); + for (MergeMode mode : modes) { + toolbarManager.add(createMergeAction(mode)); + } + for (MergeMode mode : modes) { + toolbarManager.add(createMergeAllNonConflictingAction(mode)); } + toolbarManager.add(new Separator()); toolbarManager.add(new SelectNextDiffAction(getCompareConfiguration())); toolbarManager.add(new SelectPreviousDiffAction(getCompareConfiguration())); @@ -690,6 +757,27 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { toolbarManager.add(new SaveComparisonModelAction(getCompareConfiguration())); } + private MergeAction createMergeAction(MergeMode mergeMode) { + EMFCompareConfiguration cc = getCompareConfiguration(); + IMerger.Registry mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry(); + MergeAction mergeAction = new MergeAction(cc.getEditingDomain(), mergerRegistry, mergeMode, cc + .isLeftEditable(), cc.isRightEditable()); + addSelectionChangedListener(mergeAction); + mergeActions.add(mergeAction); + return mergeAction; + } + + private MergeAction createMergeAllNonConflictingAction(MergeMode mergeMode) { + EMFCompareConfiguration cc = getCompareConfiguration(); + IMerger.Registry mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry(); + MergeAllNonConflictingAction mergeAction = new MergeAllNonConflictingAction(cc.getEditingDomain(), cc + .getComparison(), mergerRegistry, mergeMode, cc.isLeftEditable(), cc.isRightEditable()); + addSelectionChangedListener(mergeAction); + mergeActions.add(mergeAction); + mergeAllNonConflictingActions.add(mergeAction); + return mergeAction; + } + /** * Returns the viewer filter that is to be applied on the structure viewer. * <p> @@ -805,6 +893,10 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { @Override protected void handleDispose(DisposeEvent event) { getControl().removeListener(SWT.EraseItem, fEraseItemListener); + for (MergeAction mergeAction : mergeActions) { + removeSelectionChangedListener(mergeAction); + } + getCompareConfiguration().removeChangeListener(configurationChangeListener); super.handleDispose(event); } @@ -872,30 +964,14 @@ public class EMFCompareDiffTreeViewer extends DiffTreeViewer { Notifier targetItem = ((Adapter)dataTreeItem).getTarget(); if (targetItem instanceof TreeNode) { EObject dataItem = ((TreeNode)targetItem).getData(); - final Set<Diff> unmergeables; - final Set<Diff> requires; - boolean ltr = getCompareConfiguration().getPreviewMergeMode(); + MergeMode mergePreviewMode = getCompareConfiguration().getMergePreviewMode(); boolean leftEditable = getCompareConfiguration().isLeftEditable(); boolean rightEditable = getCompareConfiguration().isRightEditable(); Diff selectedDiff = (Diff)selectionData; - if (rightEditable) { - if (leftEditable) { // RW both sides - requires = DiffUtil.getRequires(selectedDiff, ltr); - unmergeables = DiffUtil.getUnmergeables(selectedDiff, ltr); - } else { // !leftEditable - requires = DiffUtil.getRequires(selectedDiff, !ltr); - unmergeables = DiffUtil.getUnmergeables(selectedDiff, !ltr); - } - } else { // !rightEditable - if (leftEditable) { - requires = DiffUtil.getRequires(selectedDiff, ltr); - unmergeables = DiffUtil.getUnmergeables(selectedDiff, ltr); - } else { // R-Only both - // nothing - requires = ImmutableSet.of(); - unmergeables = ImmutableSet.of(); - } - } + boolean leftToRight = mergePreviewMode.isLeftToRight(leftEditable, rightEditable); + final Set<Diff> requires = DiffUtil.getRequires(selectedDiff, leftToRight); + final Set<Diff> unmergeables = DiffUtil + .getUnmergeables(selectedDiff, leftToRight); final GC g = event.gc; if (requires.contains(dataItem)) { paintItemBackground(g, item, requiredDiffColor); diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java index 2e45a4226..40e392596 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java @@ -60,6 +60,7 @@ import org.eclipse.emf.compare.ide.ui.internal.util.PlatformElementUtil; import org.eclipse.emf.compare.ide.ui.internal.util.SWTUtil; import org.eclipse.emf.compare.ide.ui.logical.IModelResolver; import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor; +import org.eclipse.emf.compare.internal.merge.MergeMode; import org.eclipse.emf.compare.internal.utils.ComparisonUtil; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener; @@ -106,7 +107,7 @@ public class EMFCompareStructureMergeViewer extends AbstractViewerWrapper implem */ private final class EMFCompareStructureMergeViewerConfigurationChangeListener extends EMFCompareConfigurationChangeListener { @Override - public void previewMergeModeChange(Boolean oldValue, Boolean newValue) { + public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) { treeRuler.computeConsequences(); treeRuler.redraw(); } diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractAcceptRejectAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractAcceptRejectAction.java deleted file mode 100644 index c76bc6e30..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractAcceptRejectAction.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import com.google.common.collect.ImmutableSet; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceState; -import org.eclipse.emf.compare.command.ICompareCopyCommand; -import org.eclipse.emf.compare.domain.ICompareEditingDomain; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil; -import org.eclipse.emf.compare.internal.utils.DiffUtil; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.change.util.ChangeRecorder; -import org.eclipse.emf.edit.command.ChangeCommand; -import org.eclipse.emf.edit.tree.TreeNode; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; - -/** - * Abstract action that manages the accept and reject actions (when one side of a diff is not editable). - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - */ -public abstract class AbstractAcceptRejectAction extends Action implements ISelectionChangedListener { - - /** The compare configuration object used to get the compare model. */ - private final EMFCompareConfiguration configuration; - - private final ISelectionProvider selectionProvider; - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public AbstractAcceptRejectAction(EMFCompareConfiguration configuration, - ISelectionProvider selectionProvider) { - this.configuration = configuration; - this.selectionProvider = selectionProvider; - selectionProvider.addSelectionChangedListener(this); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.action.Action#run() - */ - @Override - public void run() { - ISelection selection = selectionProvider.getSelection(); - if (selection instanceof IStructuredSelection) { - Object diffNode = ((IStructuredSelection)selection).getFirstElement(); - if (diffNode instanceof Adapter) { - Notifier target = ((Adapter)diffNode).getTarget(); - if (target instanceof TreeNode) { - EObject data = ((TreeNode)target).getData(); - if (data instanceof Diff) { - boolean rightEditableOnly = !configuration.isLeftEditable() - && configuration.isRightEditable(); - boolean leftEditableOnly = configuration.isLeftEditable() - && !configuration.isRightEditable(); - if (leftEditableOnly) { - if (isCopyDiffCase((Diff)data, false)) { - EMFCompareUIActionUtil.copyDiff((Diff)data, false, configuration); - } else { - changeStateFromUnresolvedToMerged((Diff)data, true); - } - } else if (rightEditableOnly) { - if (isCopyDiffCase((Diff)data, true)) { - EMFCompareUIActionUtil.copyDiff((Diff)data, true, configuration); - } else { - changeStateFromUnresolvedToMerged((Diff)data, false); - } - } - // Select next diff - EMFCompareUIActionUtil.navigate(true, configuration); - } - } - } - } - } - - /** - * Check if the way of merge of the given diff correspond to a copy or a simple change state (unresolved - * to merged). - * - * @param diff - * the given diff. - * @param leftToRight - * the way of merge. - * @return true if the way of merge of the given diff correspond to a copy, false if it corresponds to a - * simple change state. - */ - protected abstract boolean isCopyDiffCase(Diff diff, boolean leftToRight); - - /** - * Execute a command that change the state of the given diff from {@link DifferenceState#UNRESOLVED} to - * {@link DifferenceState#MERGED}. - * - * @param diffToChangeState - * the given diff. - * @param leftToRight - * the way of merge. - */ - private void changeStateFromUnresolvedToMerged(Diff diffToChangeState, boolean leftToRight) { - if (diffToChangeState != null) { - ICompareEditingDomain compareEditingDomain = configuration.getEditingDomain(); - Command changeStateCommand = new AcceptRejectChangeCommand(compareEditingDomain - .getChangeRecorder(), diffToChangeState, leftToRight, configuration); - compareEditingDomain.getCommandStack().execute(changeStateCommand); - } - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - boolean ret = false; - ISelection selection = event.getSelection(); - if (selection instanceof IStructuredSelection) { - Object diffNode = ((IStructuredSelection)selection).getFirstElement(); - if (diffNode instanceof Adapter) { - Notifier target = ((Adapter)diffNode).getTarget(); - if (target instanceof TreeNode) { - EObject data = ((TreeNode)target).getData(); - ret = data instanceof Diff; - } - } - } - setEnabled(ret); - } - - /** - * A specific {@link ChangeCommand} that change the state of the given diff and all its required diffs - * from {@link DifferenceState#UNRESOLVED} to {@link DifferenceState#MERGED}. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - */ - private static class AcceptRejectChangeCommand extends ChangeCommand implements ICompareCopyCommand { - - /** The difference concerned by the command. */ - private Diff difference; - - /** The way of merge. */ - private boolean leftToRight; - - /** The compare configuration object. */ - private CompareConfiguration configuration; - - /** - * Constructor. - * - * @param changeRecorder - * the change recorder used by the command. - * @param difference - * the difference concerned by the command. - * @param leftToRight - * the way of merge. - * @param configuration - * the compare configuration object. - */ - public AcceptRejectChangeCommand(ChangeRecorder changeRecorder, Diff difference, boolean leftToRight, - CompareConfiguration configuration) { - super(changeRecorder, ImmutableSet.<Notifier> builder().add(difference).addAll( - DiffUtil.getRequires(difference, leftToRight)).build()); - this.difference = difference; - this.leftToRight = leftToRight; - this.configuration = configuration; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.edit.command.ChangeCommand#doExecute() - */ - @Override - public void doExecute() { - for (Diff require : DiffUtil.getRequires(difference, leftToRight)) { - EMFCompareUIActionUtil.setMergeDataForDiff(require, leftToRight, configuration - .isLeftEditable(), configuration.isRightEditable()); - require.setState(DifferenceState.MERGED); - } - EMFCompareUIActionUtil.setMergeDataForDiff(difference, leftToRight, configuration - .isLeftEditable(), configuration.isRightEditable()); - difference.setState(DifferenceState.MERGED); - - } - - /** - * Returns true if the command will be applied from left to right side, false otherwise. - * - * @return true if the command will be applied from left to right side, false otherwise. - */ - public boolean isLeftToRight() { - return leftToRight; - } - } - -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractAcceptRejectAllAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractAcceptRejectAllAction.java deleted file mode 100644 index 4bec403c0..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractAcceptRejectAllAction.java +++ /dev/null @@ -1,251 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import static com.google.common.collect.Iterables.filter; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -import java.util.List; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.command.CompoundCommand; -import org.eclipse.emf.compare.Comparison; -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceSource; -import org.eclipse.emf.compare.DifferenceState; -import org.eclipse.emf.compare.command.ICompareCopyCommand; -import org.eclipse.emf.compare.domain.ICompareEditingDomain; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil; -import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; -import org.eclipse.emf.compare.utils.EMFComparePredicates; -import org.eclipse.emf.ecore.change.util.ChangeRecorder; -import org.eclipse.emf.edit.command.ChangeCommand; -import org.eclipse.jface.action.Action; - -/** - * Abstract action that manages the accept all and reject all actions (when one side of a diff is not - * editable). - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - */ -public abstract class AbstractAcceptRejectAllAction extends Action { - - /** The compare configuration object used to get the compare model. */ - protected EMFCompareConfiguration configuration; - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public AbstractAcceptRejectAllAction(EMFCompareConfiguration configuration) { - this.configuration = configuration; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.action.Action#run() - */ - @Override - public void run() { - boolean rightEditableOnly = !configuration.isLeftEditable() && configuration.isRightEditable(); - boolean leftEditableOnly = configuration.isLeftEditable() && !configuration.isRightEditable(); - if (leftEditableOnly) { - manageChanges(false); - } else if (rightEditableOnly) { - manageChanges(true); - } - } - - /** - * Check if the way of merge of the given diff correspond to a copy or a simple change state (unresolved - * to merged). - * - * @param diff - * the given diff. - * @param leftToRight - * the way of merge. - * @return true if the way of merge of the given diff correspond to a copy, false if it corresponds to a - * simple change state. - */ - protected abstract boolean isCopyDiffCase(Diff diff, boolean leftToRight); - - /** - * Manage changes (copy or change state) for all non-conflicting diffs. - * - * @param leftToRight - * the way of merge. - */ - private void manageChanges(final boolean leftToRight) { - final List<Diff> differences; - Comparison comparison = configuration.getComparison(); - if (comparison.isThreeWay()) { - differences = ImmutableList.copyOf(filter(comparison.getDifferences(), new Predicate<Diff>() { - public boolean apply(Diff diff) { - final boolean unresolved = diff.getState() == DifferenceState.UNRESOLVED; - final boolean nonConflictual = diff.getConflict() == null; - final boolean fromLeftToRight = leftToRight && diff.getSource() == DifferenceSource.LEFT; - final boolean fromRightToLeft = !leftToRight - && diff.getSource() == DifferenceSource.RIGHT; - return unresolved && nonConflictual && (fromLeftToRight || fromRightToLeft); - } - })); - } else { - differences = ImmutableList.copyOf(filter(comparison.getDifferences(), EMFComparePredicates - .hasState(DifferenceState.UNRESOLVED))); - } - - if (differences.size() > 0) { - - ICompareEditingDomain editingDomain = configuration.getEditingDomain(); - - AcceptRejectAllChangesCompoundCommand compoundCommand = new AcceptRejectAllChangesCompoundCommand( - leftToRight); - - for (Diff diff : differences) { - if (DifferenceState.UNRESOLVED == diff.getState()) { - if (isCopyDiffCase(diff, leftToRight)) { - EMFCompareUIActionUtil.setMergeDataForDiff(diff, leftToRight, configuration - .isLeftEditable(), configuration.isRightEditable()); - compoundCommand.append(editingDomain.createCopyCommand(Lists.newArrayList(diff), - leftToRight, EMFCompareRCPPlugin.getDefault().getMergerRegistry())); - } else { - compoundCommand.append(createChangeStateFromUnresolvedToMergedCommand(diff, - !leftToRight)); - } - } - } - - editingDomain.getCommandStack().execute(compoundCommand); - } - } - - /** - * Execute a command that change the state of the given diff from {@link DifferenceState#UNRESOLVED} to - * {@link DifferenceState#MERGED}. - * - * @param diffToChangeState - * the given diff. - * @param leftToRight - * the way of merge. - * @return A command that change the state of the given diff from {@link DifferenceState#UNRESOLVED} to - * {@link DifferenceState#MERGED}. - */ - protected Command createChangeStateFromUnresolvedToMergedCommand(Diff diffToChangeState, - boolean leftToRight) { - if (diffToChangeState != null) { - ICompareEditingDomain compareEditingDomain = configuration.getEditingDomain(); - Command changeStateCommand = new AcceptRejectAllChangesCommand(compareEditingDomain - .getChangeRecorder(), diffToChangeState, leftToRight, configuration); - return changeStateCommand; - } - return null; - } - - /** - * A specific {@link ChangeCommand} that change the state of the given diff from - * {@link DifferenceState#UNRESOLVED} to {@link DifferenceState#MERGED}. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - */ - private static class AcceptRejectAllChangesCommand extends ChangeCommand implements ICompareCopyCommand { - - /** The difference concerned by the command. */ - private Diff difference; - - /** The way of merge. */ - private boolean leftToRight; - - /** The compare configuration object. */ - private CompareConfiguration configuration; - - /** - * Constructor. - * - * @param changeRecorder - * the change recorder used by the command. - * @param difference - * the difference concerned by the command. - * @param leftToRight - * the way of merge. - * @param configuration - * the compare configuration object. - */ - public AcceptRejectAllChangesCommand(ChangeRecorder changeRecorder, Diff difference, - boolean leftToRight, CompareConfiguration configuration) { - super(changeRecorder, difference); - this.difference = difference; - this.leftToRight = leftToRight; - this.configuration = configuration; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.edit.command.ChangeCommand#doExecute() - */ - @Override - public void doExecute() { - EMFCompareUIActionUtil.setMergeDataForDiff(difference, leftToRight, configuration - .isLeftEditable(), configuration.isRightEditable()); - difference.setState(DifferenceState.MERGED); - - } - - /** - * Returns true if the command will be applied from left to right side, false otherwise. - * - * @return true if the command will be applied from left to right side, false otherwise. - */ - public boolean isLeftToRight() { - return leftToRight; - } - - } - - /** - * A specific {@link CompoundCommand} that implements {@link ICompareCopyCommand}. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - */ - private static class AcceptRejectAllChangesCompoundCommand extends CompoundCommand implements ICompareCopyCommand { - - /** The way of merge. */ - private boolean leftToRight; - - /** - * Constructor. - * - * @param leftToRight - * the way of merge. - */ - public AcceptRejectAllChangesCompoundCommand(boolean leftToRight) { - this.leftToRight = leftToRight; - } - - /** - * Returns true if the command will be applied from left to right side, false otherwise. - * - * @return true if the command will be applied from left to right side, false otherwise. - */ - public boolean isLeftToRight() { - return leftToRight; - } - - } -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeAction.java deleted file mode 100644 index b7e547bf5..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeAction.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.edit.tree.TreeNode; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; - -/** - * Abstract Action that manages a merge of a difference in case of both sides of the comparison are editable. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.0 - */ -public abstract class AbstractMergeAction extends Action implements ISelectionChangedListener { - - /** The compare configuration object used to get the compare model. */ - private final EMFCompareConfiguration configuration; - - private final ISelectionProvider selectionProvider; - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public AbstractMergeAction(EMFCompareConfiguration configuration, ISelectionProvider selectionProvider) { - this.configuration = configuration; - this.selectionProvider = selectionProvider; - selectionProvider.addSelectionChangedListener(this); - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.action.Action#run() - */ - @Override - public void run() { - ISelection selection = selectionProvider.getSelection(); - if (selection instanceof IStructuredSelection) { - Object diffNode = ((IStructuredSelection)selection).getFirstElement(); - if (diffNode instanceof Adapter) { - Notifier target = ((Adapter)diffNode).getTarget(); - if (target instanceof TreeNode) { - EObject data = ((TreeNode)target).getData(); - if (data instanceof Diff) { - copyDiff((Diff)data); - // Select next diff - EMFCompareUIActionUtil.navigate(true, configuration); - } - } - } - } - } - - /** - * Get the compare configuration object. - * - * @return the configuration - */ - public EMFCompareConfiguration getConfiguration() { - return configuration; - } - - /** - * Copy the diff. - * - * @param diff - * the given diff. - */ - protected abstract void copyDiff(Diff diff); - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - boolean ret = false; - ISelection selection = event.getSelection(); - if (selection instanceof IStructuredSelection) { - Object diffNode = ((IStructuredSelection)selection).getFirstElement(); - if (diffNode instanceof Adapter) { - Notifier target = ((Adapter)diffNode).getTarget(); - if (target instanceof TreeNode) { - EObject data = ((TreeNode)target).getData(); - ret = data instanceof Diff; - } - } - } - setEnabled(ret); - } - -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeAllAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeAllAction.java deleted file mode 100644 index 20bcc4afb..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeAllAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.jface.action.Action; - -/** - * Abstract Action that manages a merge of a all non-conflicting difference in case of both sides of the - * comparison are editable. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.0 - */ -public abstract class AbstractMergeAllAction extends Action { - - /** The compare configuration object used to get the compare model. */ - private EMFCompareConfiguration configuration; - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public AbstractMergeAllAction(EMFCompareConfiguration configuration) { - this.configuration = configuration; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.jface.action.Action#run() - */ - @Override - public void run() { - copyAllDiffs(); - } - - /** - * Get the compare configuration object. - * - * @return the configuration - */ - public EMFCompareConfiguration getConfiguration() { - return configuration; - } - - /** - * Copy all non-conflicting differences. - */ - protected abstract void copyAllDiffs(); -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AcceptAllChangesAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AcceptAllChangesAction.java deleted file mode 100644 index b846fe851..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AcceptAllChangesAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide; - -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceSource; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * Action that manages a merge of all non-conflicting differences in case of one side of the comparison is not - * editable. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.0 - */ -public class AcceptAllChangesAction extends AbstractAcceptRejectAllAction { - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public AcceptAllChangesAction(EMFCompareConfiguration configuration) { - super(configuration); - setToolTipText(EMFCompareIDEUIMessages.getString("accept.all.changes.tooltip")); //$NON-NLS-1$ - setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID, - "icons/full/toolb16/accept_all_changes.gif")); //$NON-NLS-1$ - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AcceptAllChangesAction#isCopyDiffCase(org.eclipse.emf.compare.Diff, - * boolean) - */ - @Override - protected boolean isCopyDiffCase(Diff diff, boolean leftToRight) { - if (leftToRight) { - return fromSide(DifferenceSource.LEFT).apply(diff); - } else { - return fromSide(DifferenceSource.RIGHT).apply(diff); - } - } - -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AcceptChangeAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AcceptChangeAction.java deleted file mode 100644 index 701a3317c..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AcceptChangeAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide; - -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceSource; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * Action that manages a merge of a difference in case of one side of the comparison is not editable. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.0 - */ -public class AcceptChangeAction extends AbstractAcceptRejectAction { - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public AcceptChangeAction(EMFCompareConfiguration configuration, ISelectionProvider selectionProvider) { - super(configuration, selectionProvider); - setToolTipText(EMFCompareIDEUIMessages.getString("accept.change.tooltip")); //$NON-NLS-1$ - setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID, - "icons/full/toolb16/accept_change.gif")); //$NON-NLS-1$ - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.RejectChangeAction#isCopyDiffCase(org.eclipse.emf.compare.Diff, - * boolean) - */ - @Override - protected boolean isCopyDiffCase(Diff diff, boolean leftToRight) { - if (leftToRight) { - return fromSide(DifferenceSource.LEFT).apply(diff); - } else { - return fromSide(DifferenceSource.RIGHT).apply(diff); - } - } - -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownAcceptRejectMenuAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownAcceptRejectMenuAction.java deleted file mode 100644 index 5e554a711..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownAcceptRejectMenuAction.java +++ /dev/null @@ -1,216 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2013 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
-
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
-import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
-import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.ActionContributionItem;
-import org.eclipse.jface.action.IMenuCreator;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * Action that manages the dropdown menu that allows to show the consequences of an accept or a reject.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class DropDownAcceptRejectMenuAction extends Action implements IMenuCreator {
-
- /** The compare configuration object used to get the compare model. */
- private final EMFCompareConfiguration configuration;
-
- /** The menu associated with this action. */
- private Menu fMenu;
-
- /** The accept menu item. */
- private final Action acceptItem;
-
- /** The reject menu item. */
- private final Action rejectItem;
-
- private final EMFCompareConfigurationChangeListener changeListener;
-
- /**
- * Constructor.
- *
- * @param configuration
- * The compare configuration object.
- */
- public DropDownAcceptRejectMenuAction(EMFCompareConfiguration configuration) {
- this.configuration = configuration;
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.accept.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/accept.gif")); //$NON-NLS-1$
-
- changeListener = new EMFCompareConfigurationChangeListener() {
- @Override
- public void previewMergeModeChange(Boolean oldValue, Boolean newValue) {
- updateMenu(newValue.booleanValue());
- }
- };
- configuration.addChangeListener(changeListener);
-
- acceptItem = new DropDownAction(configuration, true);
- rejectItem = new DropDownAction(configuration, false);
- updateMenu(configuration.getPreviewMergeMode());
-
- setMenuCreator(this);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- boolean mergeWay = configuration.getPreviewMergeMode();
- configuration.setPreviewMergeMode(!mergeWay);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.IMenuCreator#dispose()
- */
- public void dispose() {
- if (fMenu != null) {
- fMenu.dispose();
- fMenu = null;
- }
- configuration.removeChangeListener(changeListener);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
- */
- public Menu getMenu(Menu parent) {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
- */
- public Menu getMenu(Control parent) {
- if (fMenu != null) {
- fMenu.dispose();
- }
-
- fMenu = new Menu(parent);
- addActionToMenu(fMenu, acceptItem);
- addActionToMenu(fMenu, rejectItem);
-
- return fMenu;
- }
-
- /**
- * Add action to the given menu.
- *
- * @param parent
- * the given menu.
- * @param action
- * the given action.
- */
- protected void addActionToMenu(Menu parent, Action action) {
- ActionContributionItem item = new ActionContributionItem(action);
- item.fill(parent, -1);
- }
-
- /**
- * Update the icon and tooltip of the dropdown menu.
- */
- protected void updateMenu(boolean mergeWay) {
- boolean rightEditableOnly = !configuration.isLeftEditable() && configuration.isRightEditable();
- boolean leftEditableOnly = configuration.isLeftEditable() && !configuration.isRightEditable();
- if (mergeWay) {
- if (leftEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.accept.tooltip")); //$NON-NLS-1$
- } else if (rightEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.reject.tooltip")); //$NON-NLS-1$
- }
- } else {
- if (leftEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.reject.tooltip")); //$NON-NLS-1$
- } else if (rightEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.accept.tooltip")); //$NON-NLS-1$
- }
- }
- }
-
- private static class DropDownAction extends Action {
-
- /** The compare configuration object used to get the compare model. */
- private final EMFCompareConfiguration configuration;
-
- private final boolean mode;
-
- /**
- * Constructor.
- *
- * @param configuration
- * The compare configuration object.
- */
- public DropDownAction(EMFCompareConfiguration configuration, boolean mode) {
- this.configuration = configuration;
- this.mode = mode;
- boolean rightEditableOnly = !configuration.isLeftEditable() && configuration.isRightEditable();
- boolean leftEditableOnly = configuration.isLeftEditable() && !configuration.isRightEditable();
- if (mode) {
- if (leftEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.accept.tooltip")); //$NON-NLS-1$
- } else if (rightEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.reject.tooltip")); //$NON-NLS-1$
- }
- } else {
- if (leftEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.reject.tooltip")); //$NON-NLS-1$
- } else if (rightEditableOnly) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.accept.tooltip")); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
- @Override
- public void run() {
- configuration.setPreviewMergeMode(mode);
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java index b853b8465..45e3268ff 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/DropDownMergeMenuAction.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
+ * Copyright (c) 2013 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,35 +10,40 @@ *******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.util.EnumSet;
+import java.util.List;
+
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.rcp.ui.internal.configuration.EMFCompareConfigurationChangeListener;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
- * Action that manages the click on the dropdown menu of the toolbar of the structure merge viewer.
+ * Action that manages the dropdown menu that allows to show the consequences of an accept or a reject.
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
*/
public class DropDownMergeMenuAction extends Action implements IMenuCreator {
- /** The compare configuration object. */
+ /** The compare configuration object used to get the compare model. */
private final EMFCompareConfiguration configuration;
/** The menu associated with this action. */
private Menu fMenu;
- /** The left to right menu item. */
- private final Action leftToRightItem;
-
- /** The right to left menu item. */
- private final Action rightToLeftItem;
+ /** The accept menu item. */
+ private final List<Action> actions;
private final EMFCompareConfigurationChangeListener changeListener;
@@ -48,23 +53,22 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { * @param configuration
* The compare configuration object.
*/
- public DropDownMergeMenuAction(EMFCompareConfiguration configuration) {
+ public DropDownMergeMenuAction(EMFCompareConfiguration configuration, EnumSet<MergeMode> previewModes) {
this.configuration = configuration;
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/left_to_right.gif")); //$NON-NLS-1$
+ actions = newArrayList();
changeListener = new EMFCompareConfigurationChangeListener() {
@Override
- public void previewMergeModeChange(Boolean oldValue, Boolean newValue) {
- updateMenu(newValue.booleanValue());
+ public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
+ updateMenu(newValue);
}
};
configuration.addChangeListener(changeListener);
- leftToRightItem = new DropDownAction(configuration, true);
- rightToLeftItem = new DropDownAction(configuration, false);
- updateMenu(configuration.getPreviewMergeMode());
+ for (MergeMode mergePreviewMode : previewModes) {
+ actions.add(new DropDownAction(configuration, mergePreviewMode));
+ }
+ updateMenu(configuration.getMergePreviewMode());
setMenuCreator(this);
}
@@ -76,8 +80,8 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { */
@Override
public void run() {
- boolean mergeWay = configuration.getPreviewMergeMode();
- configuration.setPreviewMergeMode(!mergeWay);
+ MergeMode mergeWay = configuration.getMergePreviewMode();
+ configuration.setMergePreviewMode(mergeWay.inverse());
}
/**
@@ -113,9 +117,9 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { }
fMenu = new Menu(parent);
- addActionToMenu(fMenu, leftToRightItem);
- addActionToMenu(fMenu, rightToLeftItem);
-
+ for (IAction action : actions) {
+ addActionToMenu(fMenu, action);
+ }
return fMenu;
}
@@ -127,7 +131,7 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { * @param action
* the given action.
*/
- protected void addActionToMenu(Menu parent, Action action) {
+ protected void addActionToMenu(Menu parent, IAction action) {
ActionContributionItem item = new ActionContributionItem(action);
item.fill(parent, -1);
}
@@ -135,15 +139,34 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { /**
* Update the icon and tooltip of the dropdown menu.
*/
- protected void updateMenu(boolean mergeWay) {
- if (mergeWay) {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/left_to_right.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.left.to.right.tooltip")); //$NON-NLS-1$
- } else {
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/right_to_left.gif")); //$NON-NLS-1$
- setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.right.to.left.tooltip")); //$NON-NLS-1$
+ protected void updateMenu(MergeMode mergeWay) {
+ setToolTipTextAndImage(this, mergeWay);
+ }
+
+ static void setToolTipTextAndImage(IAction action, MergeMode mergeMode) {
+ switch (mergeMode) {
+ case LEFT_TO_RIGHT:
+ action.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
+ EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/left_to_right.gif")); //$NON-NLS-1$
+ action.setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.left.to.right.tooltip")); //$NON-NLS-1$
+ break;
+ case RIGHT_TO_LEFT:
+ action.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
+ EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/right_to_left.gif")); //$NON-NLS-1$
+ action.setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.right.to.left.tooltip")); //$NON-NLS-1$
+ break;
+ case ACCEPT:
+ action.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
+ EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept.gif")); //$NON-NLS-1$
+ action.setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.accept.tooltip")); //$NON-NLS-1$
+ break;
+ case REJECT:
+ action.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
+ EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject.gif")); //$NON-NLS-1$
+ action.setToolTipText(EMFCompareIDEUIMessages.getString("dropdown.reject.tooltip")); //$NON-NLS-1$
+ break;
+ default:
+ throw new IllegalStateException();
}
}
@@ -152,7 +175,7 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { /** The compare configuration object used to get the compare model. */
private final EMFCompareConfiguration configuration;
- private final boolean mode;
+ private final MergeMode mergeMode;
/**
* Constructor.
@@ -160,18 +183,10 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { * @param configuration
* The compare configuration object.
*/
- public DropDownAction(EMFCompareConfiguration configuration, boolean mode) {
+ public DropDownAction(EMFCompareConfiguration configuration, MergeMode mergeMode) {
this.configuration = configuration;
- this.mode = mode;
- if (mode) {
- setText(EMFCompareIDEUIMessages.getString("dropdown.left.to.right.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/left_to_right.gif")); //$NON-NLS-1$
- } else {
- setText(EMFCompareIDEUIMessages.getString("dropdown.right.to.left.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
- EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/right_to_left.gif")); //$NON-NLS-1$
- }
+ this.mergeMode = mergeMode;
+ setToolTipTextAndImage(this, mergeMode);
}
/**
@@ -181,7 +196,7 @@ public class DropDownMergeMenuAction extends Action implements IMenuCreator { */
@Override
public void run() {
- configuration.setPreviewMergeMode(mode);
+ configuration.setMergePreviewMode(mergeMode);
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAction.java new file mode 100644 index 000000000..6180c60d6 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAction.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * Copyright (c) 2013 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; + +import static com.google.common.collect.Iterables.addAll; +import static com.google.common.collect.Iterables.concat; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; +import static com.google.common.collect.Lists.newArrayList; + +import com.google.common.base.Function; +import com.google.common.base.Preconditions; + +import java.util.List; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.compare.Diff; +import org.eclipse.emf.compare.command.ICompareCopyCommand; +import org.eclipse.emf.compare.domain.ICompareEditingDomain; +import org.eclipse.emf.compare.domain.IMergeRunnable; +import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages; +import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; +import org.eclipse.emf.compare.internal.merge.MergeMode; +import org.eclipse.emf.compare.merge.IMerger; +import org.eclipse.emf.compare.merge.IMerger.Registry; +import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroup; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.tree.TreeNode; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.actions.BaseSelectionListenerAction; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * Abstract Action that manages a merge of a difference in case of both sides of the comparison are editable. + * + * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> + * @since 3.0 + */ +public class MergeAction extends BaseSelectionListenerAction { + + private static final Function<? super Adapter, ? extends Notifier> ADAPTER__TARGET = new Function<Adapter, Notifier>() { + public Notifier apply(Adapter adapter) { + return adapter.getTarget(); + } + }; + + private final Registry mergerRegistry; + + private final boolean leftToRight; + + private final IMergeRunnable mergeRunnable; + + private ICompareEditingDomain editingDomain; + + private boolean cascadingDifferencesFilterEnabled; + + private final List<Diff> selectedDifferences; + + /** + * Constructor. + * + * @param configuration + * The compare configuration object. + */ + public MergeAction(ICompareEditingDomain editingDomain, IMerger.Registry mergerRegistry, MergeMode mode, + boolean isLeftEditable, boolean isRightEditable) { + super(""); //$NON-NLS-1$ + + Preconditions.checkNotNull(mode); + // at least should be editable + Preconditions.checkState(isLeftEditable || isRightEditable); + // if left and right editable, the only accepted mode are LtR or RtL + if (isLeftEditable && isRightEditable) { + Preconditions.checkState(mode == MergeMode.LEFT_TO_RIGHT || mode == MergeMode.RIGHT_TO_LEFT); + } + // if mode is accept or reject, left and right can't be both read only (no action should be created in + // this case) and can't be both editable. + if (isLeftEditable != isRightEditable) { + Preconditions.checkState(mode == MergeMode.ACCEPT || mode == MergeMode.REJECT); + } + + this.editingDomain = editingDomain; + this.mergerRegistry = mergerRegistry; + this.leftToRight = mode.isLeftToRight(isLeftEditable, isRightEditable); + this.mergeRunnable = createMergeRunnable(mode, isLeftEditable, isRightEditable); + this.selectedDifferences = newArrayList(); + + initToolTipAndImage(mode); + } + + protected IMergeRunnable createMergeRunnable(MergeMode mode, boolean isLeftEditable, + boolean isRightEditable) { + return new MergeRunnableImpl(isLeftEditable, isRightEditable, mode); + } + + protected void initToolTipAndImage(MergeMode mode) { + switch (mode) { + case LEFT_TO_RIGHT: + setToolTipText(EMFCompareIDEUIMessages.getString("merged.to.right.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/merge_to_right.gif")); //$NON-NLS-1$ + break; + case RIGHT_TO_LEFT: + setToolTipText(EMFCompareIDEUIMessages.getString("merged.to.left.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/merge_to_left.gif")); //$NON-NLS-1$ + break; + case ACCEPT: + setToolTipText(EMFCompareIDEUIMessages.getString("accept.change.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept_change.gif")); //$NON-NLS-1$ + break; + case REJECT: + setToolTipText(EMFCompareIDEUIMessages.getString("reject.change.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject_change.gif")); //$NON-NLS-1$ + break; + default: + throw new IllegalStateException(); + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + List<Diff> differences = getDifferencesToMerge(); + ICompareCopyCommand mergeCommand = editingDomain.createCopyCommand(differences, leftToRight, + mergerRegistry, mergeRunnable); + editingDomain.getCommandStack().execute(mergeCommand); + + // Select next diff + // EMFCompareUIActionUtil.navigate(true, configuration); + } + + protected List<Diff> getDifferencesToMerge() { + List<Diff> differencesToMerge = newArrayList(selectedDifferences); + + if (cascadingDifferencesFilterEnabled) { + Iterable<Diff> cascadingDifferences = concat(transform(selectedDifferences, + org.eclipse.emf.compare.utils.DiffUtil.getSubDiffs(leftToRight))); + addAll(differencesToMerge, cascadingDifferences); + } + + return differencesToMerge; + } + + public final void setCascadingDifferencesFilterEnabled(boolean enable) { + this.cascadingDifferencesFilterEnabled = enable; + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + @Override + protected boolean updateSelection(IStructuredSelection selection) { + addAll(selectedDifferences, getSelectedDifferences(selection)); + return selection.toList().size() == selectedDifferences.size(); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.ui.actions.BaseSelectionListenerAction#clearCache() + */ + @Override + protected void clearCache() { + selectedDifferences.clear(); + } + + private Iterable<Diff> getSelectedDifferences(IStructuredSelection selection) { + List<?> selectedObjects = selection.toList(); + Iterable<Adapter> selectedAdapters = filter(selectedObjects, Adapter.class); + Iterable<Notifier> selectedNotifiers = transform(selectedAdapters, ADAPTER__TARGET); + Iterable<TreeNode> selectedTreeNode = filter(selectedNotifiers, TreeNode.class); + Iterable<EObject> selectedEObjects = transform(selectedTreeNode, IDifferenceGroup.TREE_NODE_DATA); + return filter(selectedEObjects, Diff.class); + } + + /** + * @param newValue + */ + public final void setEditingDomain(ICompareEditingDomain editingDomain) { + this.editingDomain = editingDomain; + clearCache(); + setEnabled(editingDomain != null && updateSelection(getStructuredSelection())); + } + + /** + * @return the leftToRight + */ + protected final boolean isLeftToRight() { + return leftToRight; + } + +} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingAction.java new file mode 100644 index 000000000..ff6c2eaba --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllNonConflictingAction.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2013 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; + +import static com.google.common.base.Predicates.or; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Lists.newArrayList; +import static org.eclipse.emf.compare.utils.EMFComparePredicates.WITHOUT_CONFLICT; +import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState; + +import java.util.List; + +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.Diff; +import org.eclipse.emf.compare.DifferenceState; +import org.eclipse.emf.compare.domain.ICompareEditingDomain; +import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages; +import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; +import org.eclipse.emf.compare.internal.merge.MergeMode; +import org.eclipse.emf.compare.merge.IMerger; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * Abstract Action that manages a merge of a all non-conflicting difference in case of both sides of the + * comparison are editable. + * + * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> + * @since 3.0 + */ +public class MergeAllNonConflictingAction extends MergeAction { + + private Comparison comparison; + + /** + * Constructor. + * + * @param configuration + * The compare configuration object. + */ + public MergeAllNonConflictingAction(ICompareEditingDomain editingDomain, Comparison comparison, + IMerger.Registry mergerRegistry, MergeMode mode, boolean isLeftEditable, boolean isRightEditable) { + super(editingDomain, mergerRegistry, mode, isLeftEditable, isRightEditable); + this.comparison = comparison; + } + + @Override + protected void initToolTipAndImage(MergeMode mode) { + switch (mode) { + case LEFT_TO_RIGHT: + setToolTipText(EMFCompareIDEUIMessages.getString("merged.all.to.right.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/merge_all_to_right.gif")); //$NON-NLS-1$ + break; + case RIGHT_TO_LEFT: + setToolTipText(EMFCompareIDEUIMessages.getString("merged.all.to.left.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/merge_all_to_left.gif")); //$NON-NLS-1$ + break; + case ACCEPT: + setToolTipText(EMFCompareIDEUIMessages.getString("accept.all.changes.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/accept_all_changes.gif")); //$NON-NLS-1$ + break; + case REJECT: + setToolTipText(EMFCompareIDEUIMessages.getString("reject.all.changes.tooltip")); //$NON-NLS-1$ + setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin( + EMFCompareIDEUIPlugin.PLUGIN_ID, "icons/full/toolb16/reject_all_changes.gif")); //$NON-NLS-1$ + break; + default: + throw new IllegalStateException(); + } + } + + public void setComparison(Comparison comparison) { + this.comparison = comparison; + clearCache(); + // update the enablement of this action by simulating a selection change. + setEnabled(comparison != null); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAction#getDifferencesToMerge() + */ + @Override + protected List<Diff> getDifferencesToMerge() { + Iterable<Diff> differences = filter(comparison.getDifferences(), or(WITHOUT_CONFLICT, + hasState(DifferenceState.UNRESOLVED))); + return newArrayList(differences); + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + @Override + protected boolean updateSelection(IStructuredSelection selection) { + // this subclass does not care about the selection change event. + return true; + } + +} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllToLeftAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllToLeftAction.java deleted file mode 100644 index 6adc12582..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllToLeftAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2013 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
-
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
-import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * Action that manages a merge from left to right of all non-conflicting differences in case of both sides of
- * the comparison are editable.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class MergeAllToLeftAction extends AbstractMergeAllAction {
-
- /**
- * Constructor.
- *
- * @param configuration
- * The compare configuration object.
- */
- public MergeAllToLeftAction(EMFCompareConfiguration configuration) {
- super(configuration);
- setToolTipText(EMFCompareIDEUIMessages.getString("merged.all.to.left.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/merge_all_to_left.gif")); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AbstractMergeAllAction#copyAllDiffs()
- */
- @Override
- protected void copyAllDiffs() {
- EMFCompareUIActionUtil.copyAllDiffs(false, getConfiguration());
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllToRightAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllToRightAction.java deleted file mode 100644 index a76146e19..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeAllToRightAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2013 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
-
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
-import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * Action that manages a merge from right to left of all non-conflicting differences in case of both sides of
- * the comparison are editable.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class MergeAllToRightAction extends AbstractMergeAllAction {
-
- /**
- * Constructor.
- *
- * @param configuration
- * The compare configuration object.
- */
- public MergeAllToRightAction(EMFCompareConfiguration configuration) {
- super(configuration);
- setToolTipText(EMFCompareIDEUIMessages.getString("merged.all.to.right.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/merge_all_to_right.gif")); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AbstractMergeAllAction#copyAllDiffs()
- */
- @Override
- protected void copyAllDiffs() {
- EMFCompareUIActionUtil.copyAllDiffs(true, getConfiguration());
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java new file mode 100644 index 000000000..406800e95 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java @@ -0,0 +1,124 @@ +/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+import com.google.common.base.Preconditions;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.util.BasicMonitor;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceState;
+import org.eclipse.emf.compare.domain.IMergeRunnable;
+import org.eclipse.emf.compare.internal.merge.IMergeData;
+import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.merge.MergeOperation;
+import org.eclipse.emf.compare.internal.utils.DiffUtil;
+import org.eclipse.emf.compare.merge.BatchMerger;
+import org.eclipse.emf.compare.merge.IBatchMerger;
+import org.eclipse.emf.compare.merge.IMerger.Registry;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+/**
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+final class MergeRunnableImpl implements IMergeRunnable {
+
+ private final boolean isLeftEditable;
+
+ private final boolean isRightEditable;
+
+ private final MergeMode mergeMode;
+
+ public MergeRunnableImpl(boolean isLeftEditable, boolean isRightEditable, MergeMode mergeMode) {
+ this.isLeftEditable = isLeftEditable;
+ this.isRightEditable = isRightEditable;
+ this.mergeMode = mergeMode;
+ }
+
+ public void merge(List<? extends Diff> differences, boolean leftToRight, Registry mergerRegistry) {
+ Preconditions.checkState(mergeMode.isLeftToRight(isLeftEditable, isRightEditable) == leftToRight);
+
+ // Execute merge
+ if (mergeMode == MergeMode.LEFT_TO_RIGHT || mergeMode == MergeMode.RIGHT_TO_LEFT) {
+ mergeAll(differences, leftToRight, mergerRegistry);
+ } else if (mergeMode == MergeMode.ACCEPT || mergeMode == MergeMode.REJECT) {
+ List<Diff> diffToMarkAsMerged = newArrayList();
+ List<Diff> diffToCopy = newArrayList();
+ for (Diff diff : differences) {
+ MergeOperation mergeAction = mergeMode.getMergeAction(diff, isLeftEditable, isRightEditable);
+ if (mergeAction == MergeOperation.MARK_AS_MERGE) {
+ diffToMarkAsMerged.add(diff);
+ } else {
+ diffToCopy.add(diff);
+ }
+ }
+ mergeAll(diffToCopy, leftToRight, mergerRegistry);
+ markAllAsMerged(diffToMarkAsMerged, mergeMode);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * @param diffToMarkAsMerged
+ * @param leftToRight
+ * @param isLeftEditable
+ * @param isRightEditable
+ */
+ private void markAllAsMerged(Collection<Diff> diffToMarkAsMerged, MergeMode mergeMode) {
+ for (Diff diff : diffToMarkAsMerged) {
+ markAsMerged(diff, mergeMode);
+ }
+ }
+
+ private void markAsMerged(Diff diff, MergeMode mergeMode) {
+ diff.setState(DifferenceState.MERGED);
+ addOrUpdateMergeData(diff, mergeMode);
+ }
+
+ private void addOrUpdateMergeData(Collection<Diff> differences, MergeMode mergeMode) {
+ for (Diff difference : differences) {
+ addOrUpdateMergeData(difference, mergeMode);
+ }
+ }
+
+ private void addOrUpdateMergeData(Diff diff, MergeMode mergeMode) {
+ IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
+ if (mergeData != null) {
+ mergeData.setMergeMode(mergeMode);
+ mergeData.setLeftEditable(isLeftEditable);
+ mergeData.setRightEditable(isRightEditable);
+ } else {
+ mergeData = new MergeDataImpl(mergeMode, isLeftEditable, isRightEditable);
+ diff.eAdapters().add(mergeData);
+ }
+ }
+
+ private void mergeAll(Collection<? extends Diff> differences, boolean leftToRight, Registry mergerRegistry) {
+ final IBatchMerger merger = new BatchMerger(mergerRegistry);
+ if (leftToRight) {
+ merger.copyAllLeftToRight(differences, new BasicMonitor());
+ } else {
+ merger.copyAllRightToLeft(differences, new BasicMonitor());
+ }
+
+ for (Diff difference : differences) {
+ addOrUpdateMergeData(difference, mergeMode);
+ addOrUpdateMergeData(DiffUtil.getRequires(difference, leftToRight), mergeMode);
+ addOrUpdateMergeData(DiffUtil.getUnmergeables(difference, leftToRight), mergeMode);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeToLeftAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeToLeftAction.java deleted file mode 100644 index e384dfc37..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeToLeftAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2013 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
-
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
-import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * Action that manages a merge from right to left of a difference in case of both sides of the comparison are
- * editable.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class MergeToLeftAction extends AbstractMergeAction {
-
- /**
- * Constructor.
- *
- * @param configuration
- * The compare configuration object.
- */
- public MergeToLeftAction(EMFCompareConfiguration configuration, ISelectionProvider selectionProvider) {
- super(configuration, selectionProvider);
- setToolTipText(EMFCompareIDEUIMessages.getString("merged.to.left.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/merge_to_left.gif")); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AbstractMergeAction#copyDiff(org.eclipse.emf.compare.Diff)
- */
- @Override
- protected void copyDiff(Diff diff) {
- EMFCompareUIActionUtil.copyDiff(diff, false, getConfiguration());
- }
-
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeToRightAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeToRightAction.java deleted file mode 100644 index d5e5131bb..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeToRightAction.java +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2013 Obeo.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
-
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
-import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
-import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration;
-import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util.EMFCompareUIActionUtil;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-
-/**
- * Action that manages a merge from left to right of a difference in case of both sides of the comparison are
- * editable.
- *
- * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
- * @since 3.0
- */
-public class MergeToRightAction extends AbstractMergeAction {
-
- /**
- * Constructor.
- *
- * @param configuration
- * The compare configuration object.
- */
- public MergeToRightAction(EMFCompareConfiguration configuration, ISelectionProvider selectionProvider) {
- super(configuration, selectionProvider);
- setToolTipText(EMFCompareIDEUIMessages.getString("merged.to.right.tooltip")); //$NON-NLS-1$
- setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
- "icons/full/toolb16/merge_to_right.gif")); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AbstractMergeAction#copyDiff(org.eclipse.emf.compare.Diff)
- */
- @Override
- protected void copyDiff(Diff diff) {
- EMFCompareUIActionUtil.copyDiff(diff, true, getConfiguration());
- }
-
-}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/RejectAllChangesAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/RejectAllChangesAction.java deleted file mode 100644 index 3aa2567aa..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/RejectAllChangesAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide; - -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceSource; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * Action that manages a merge of all non-conflicting differences in case of one side of the comparison is not - * editable. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.0 - */ -public class RejectAllChangesAction extends AbstractAcceptRejectAllAction { - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public RejectAllChangesAction(EMFCompareConfiguration configuration) { - super(configuration); - setToolTipText(EMFCompareIDEUIMessages.getString("reject.all.changes.tooltip")); //$NON-NLS-1$ - setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID, - "icons/full/toolb16/reject_all_changes.gif")); //$NON-NLS-1$ - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.AcceptAllChangesAction#isCopyDiffCase(org.eclipse.emf.compare.Diff, - * boolean) - */ - @Override - protected boolean isCopyDiffCase(Diff diff, boolean leftToRight) { - if (leftToRight) { - return fromSide(DifferenceSource.RIGHT).apply(diff); - } else { - return fromSide(DifferenceSource.LEFT).apply(diff); - } - } - -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/RejectChangeAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/RejectChangeAction.java deleted file mode 100644 index 33a4c6a61..000000000 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/RejectChangeAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions; - -import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide; - -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceSource; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages; -import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * Action that manages a merge of a difference in case of one side of the comparison is not editable. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.0 - */ -public class RejectChangeAction extends AbstractAcceptRejectAction { - - /** - * Constructor. - * - * @param configuration - * The compare configuration object. - */ - public RejectChangeAction(EMFCompareConfiguration configuration, ISelectionProvider selectionProvider) { - super(configuration, selectionProvider); - setToolTipText(EMFCompareIDEUIMessages.getString("reject.change.tooltip")); //$NON-NLS-1$ - setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID, - "icons/full/toolb16/reject_change.gif")); //$NON-NLS-1$ - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.RejectChangeAction#isCopyDiffCase(org.eclipse.emf.compare.Diff, - * boolean) - */ - @Override - protected boolean isCopyDiffCase(Diff diff, boolean leftToRight) { - if (leftToRight) { - return fromSide(DifferenceSource.RIGHT).apply(diff); - } else { - return fromSide(DifferenceSource.LEFT).apply(diff); - } - } - -} diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java index 5edf93992..05ff425d7 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/util/EMFCompareUIActionUtil.java @@ -10,37 +10,9 @@ *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.util; -import static com.google.common.collect.Iterables.addAll; -import static com.google.common.collect.Iterables.filter; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.CompareNavigator; import org.eclipse.compare.ICompareNavigator; -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.compare.Comparison; -import org.eclipse.emf.compare.Conflict; -import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceKind; -import org.eclipse.emf.compare.DifferenceSource; -import org.eclipse.emf.compare.DifferenceState; -import org.eclipse.emf.compare.domain.ICompareEditingDomain; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.emf.compare.internal.merge.DiffMergeDataAdapter; -import org.eclipse.emf.compare.internal.merge.IDiffMergeData; -import org.eclipse.emf.compare.internal.utils.DiffUtil; -import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; -import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter; -import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl.CascadingDifferencesFilter; -import org.eclipse.emf.compare.utils.EMFComparePredicates; -import org.eclipse.emf.ecore.util.EcoreUtil; /** * Util class that provides utilities methods for IDE UI actions. @@ -58,130 +30,6 @@ public final class EMFCompareUIActionUtil { } /** - * Checks the state of the cascading differences filter. - * - * @param configuration - * the compare configuration object. - * @return true, if the cascading differences filter is active, false otherwise. - */ - public static boolean isCascadingDifferencesFilterActive(EMFCompareConfiguration configuration) { - Set<IDifferenceFilter> selectedFilters = configuration.getSelectedDifferenceFilters(); - for (IDifferenceFilter iDifferenceFilter : selectedFilters) { - if (iDifferenceFilter instanceof CascadingDifferencesFilter) { - return true; - } - } - return false; - } - - /** - * Copy the given diff. - * - * @param diffToCopy - * the given diff to copy. - * @param leftToRight - * the way of merge. - * @param configuration - * the compare configuration object. - */ - public static void copyDiff(Diff diffToCopy, boolean leftToRight, EMFCompareConfiguration configuration) { - if (diffToCopy != null) { - List<Diff> diffsToCopy = new ArrayList<Diff>(); - diffsToCopy.add(diffToCopy); - // Add merge data for required diffs - for (Diff require : DiffUtil.getRequires(diffToCopy, leftToRight)) { - EMFCompareUIActionUtil.setMergeDataForDiff(require, leftToRight, configuration - .isLeftEditable(), configuration.isRightEditable()); - } - if (EMFCompareUIActionUtil.isCascadingDifferencesFilterActive(configuration)) { - addAll(diffsToCopy, org.eclipse.emf.compare.utils.DiffUtil.getSubDiffs(leftToRight).apply( - diffToCopy)); - } - // Add merge data for subs diffs - for (Diff diff : diffsToCopy) { - EMFCompareUIActionUtil.setMergeDataForDiff(diff, leftToRight, configuration.isLeftEditable(), - configuration.isRightEditable()); - } - // Add merge data for diffs in conflicts - addMergeDataForConflictedDiffs(diffToCopy, leftToRight, configuration); - - // Execute merge - ICompareEditingDomain editingDomain = configuration.getEditingDomain(); - Command copyCommand = editingDomain.createCopyCommand(diffsToCopy, leftToRight, - EMFCompareRCPPlugin.getDefault().getMergerRegistry()); - editingDomain.getCommandStack().execute(copyCommand); - } - } - - /** - * Add merge data for diffs in conflict with the given diff. - * - * @param diffToCopy - * the given diff. - * @param leftToRight - * the way of merge. - * @param configuration - * the compare configuration object. - */ - private static void addMergeDataForConflictedDiffs(Diff diffToCopy, boolean leftToRight, - CompareConfiguration configuration) { - Conflict conflict = diffToCopy.getConflict(); - if (conflict != null) { - for (Diff conflictedDiff : conflict.getDifferences()) { - if (diffToCopy != conflictedDiff) { - if (diffToCopy.getKind() != DifferenceKind.MOVE - && ((diffToCopy.getSource() == DifferenceSource.LEFT && conflictedDiff - .getSource() == DifferenceSource.RIGHT) || (diffToCopy.getSource() == DifferenceSource.RIGHT && conflictedDiff - .getSource() == DifferenceSource.LEFT))) { - EMFCompareUIActionUtil.setMergeDataForDiff(conflictedDiff, leftToRight, configuration - .isLeftEditable(), configuration.isRightEditable()); - } - } - } - } - } - - /** - * Copy all non-conflicting changes. - * - * @param leftToRight - * the way of merge. - * @param configuration - * the compare configuration object. - */ - public static void copyAllDiffs(final boolean leftToRight, EMFCompareConfiguration configuration) { - final List<Diff> differences; - Comparison comparison = configuration.getComparison(); - if (comparison.isThreeWay()) { - differences = ImmutableList.copyOf(filter(comparison.getDifferences(), new Predicate<Diff>() { - public boolean apply(Diff diff) { - final boolean unresolved = diff.getState() == DifferenceState.UNRESOLVED; - final boolean nonConflictual = diff.getConflict() == null; - final boolean fromLeftToRight = leftToRight && diff.getSource() == DifferenceSource.LEFT; - final boolean fromRightToLeft = !leftToRight - && diff.getSource() == DifferenceSource.RIGHT; - return unresolved && nonConflictual && (fromLeftToRight || fromRightToLeft); - } - })); - } else { - differences = ImmutableList.copyOf(filter(comparison.getDifferences(), EMFComparePredicates - .hasState(DifferenceState.UNRESOLVED))); - } - - if (differences.size() > 0) { - for (Diff diff : differences) { - EMFCompareUIActionUtil.setMergeDataForDiff(diff, leftToRight, configuration.isLeftEditable(), - configuration.isRightEditable()); - } - ICompareEditingDomain editingDomain = configuration.getEditingDomain(); - final Command copyCommand = editingDomain.createCopyCommand(differences, leftToRight, - EMFCompareRCPPlugin.getDefault().getMergerRegistry()); - - editingDomain.getCommandStack().execute(copyCommand); - } - } - - /** * Called by the framework to navigate to the next (or previous) difference. This will open the content * viewer for the next (or previous) diff displayed in the structure viewer. * @@ -197,28 +45,4 @@ public final class EMFCompareUIActionUtil { navigator.selectChange(next); } } - - /** - * Set the merge way for the given diff. After a merge, it allows to know the way of the merge. - * - * @param diff - * the given diff. - * @param leftToRight - * the way of the merge. - * @param leftEditable - * the left side of the difference is editable. - * @param rightEditable - * the right side of the difference is editable. - */ - public static void setMergeDataForDiff(Diff diff, boolean leftToRight, boolean leftEditable, - boolean rightEditable) { - Adapter adapter = EcoreUtil.getExistingAdapter(diff, IDiffMergeData.class); - if (adapter != null) { - ((IDiffMergeData)adapter).setMergedTo(leftToRight); - ((IDiffMergeData)adapter).setLeftEditable(leftEditable); - ((IDiffMergeData)adapter).setRightEditable(rightEditable); - } else { - diff.eAdapters().add(new DiffMergeDataAdapter(leftToRight, leftEditable, rightEditable)); - } - } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/EMFCompareConfigurationChangeListener.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/EMFCompareConfigurationChangeListener.java index 1a6662b01..04fd9a575 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/EMFCompareConfigurationChangeListener.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/EMFCompareConfigurationChangeListener.java @@ -18,6 +18,7 @@ import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.ecore.EObject;
@@ -103,10 +104,10 @@ public class EMFCompareConfigurationChangeListener implements IEMFCompareConfigu /**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener#previewMergeModeChange(org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration.PreviewMergeMode,
+ * @see org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfigurationChangeListener#mergePreviewModeChange(org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration.PreviewMergeMode,
* org.eclipse.emf.compare.rcp.ui.internal.configuration.IEMFCompareConfiguration.PreviewMergeMode)
*/
- public void previewMergeModeChange(Boolean oldValue, Boolean newValue) {
+ public void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue) {
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfiguration.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfiguration.java index 12f208f7f..10f91a998 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfiguration.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfiguration.java @@ -19,6 +19,7 @@ import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.ecore.EObject;
@@ -78,9 +79,9 @@ public interface IEMFCompareConfiguration { void setComparator(EMFCompare comparator);
- boolean getPreviewMergeMode();
+ MergeMode getMergePreviewMode();
- void setPreviewMergeMode(boolean mergeWay);
+ void setMergePreviewMode(MergeMode mergePreviewMode);
/**
* Adds a listener for property changes to this notifier. Has no effect if an identical listener is
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfigurationChangeListener.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfigurationChangeListener.java index 70422af05..77d6a7190 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfigurationChangeListener.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/IEMFCompareConfigurationChangeListener.java @@ -18,6 +18,7 @@ import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.domain.ICompareEditingDomain;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.IDifferenceFilter;
import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.IDifferenceGroupProvider;
import org.eclipse.emf.ecore.EObject;
@@ -51,6 +52,6 @@ public interface IEMFCompareConfigurationChangeListener { * @param oldValue
* @param newValue
*/
- void previewMergeModeChange(Boolean oldValue, Boolean newValue);
+ void mergePreviewModeChange(MergeMode oldValue, MergeMode newValue);
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IDiffMergeData.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IDiffMergeData.java deleted file mode 100644 index bb5de723e..000000000 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IDiffMergeData.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Obeo. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.internal.merge; - -import org.eclipse.emf.compare.DifferenceSource; - -/** - * Interface implemented by {@link org.eclipse.emf.compare.internal.merge.DiffMergeDataAdapter}. It helps to - * know the way of merge and the editable sides of a difference. - * - * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - */ -public interface IDiffMergeData { - - /** - * Check if the difference has been merged from right to left. - * - * @return true if the difference has been merged from right to left, false otherwise. - */ - boolean hasBeenMergedToLeft(); - - /** - * Check if the difference has been merged from left to right. - * - * @return true if the difference has been merged from left to right, false otherwise. - */ - boolean hasBeenMergedToRight(); - - /** - * Returns on which side the difference has been merged to. - * - * @return on which side the difference has been merged to - */ - DifferenceSource mergedTo(); - - /** - * Set the way of merge. - * - * @param leftToRight - * true if the difference has been merge from left to right, false otehrwise. - */ - void setMergedTo(boolean leftToRight); - - /** - * Check if the left side of the difference is editable. - * - * @return true if the left side of the difference is editable, false otherwise. - */ - boolean isLeftEditable(); - - /** - * Check if the right side of the difference is editable. - * - * @return true if the right side of the difference is editable, false otherwise. - */ - boolean isRightEditable(); - - /** - * Set that the left side of the difference is editable or not. - * - * @param leftEditable - * true if the left side of the difference is editable, false otherwise. - */ - void setLeftEditable(boolean leftEditable); - - /** - * Set that the right side of the difference is editable or not. - * - * @param rightEditable - * true if the right side of the difference is editable, false otherwise. - */ - void setRightEditable(boolean rightEditable); - -} diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java new file mode 100644 index 000000000..0db05234a --- /dev/null +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2013 Obeo. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.internal.merge; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.compare.DifferenceSource; + +/** + * Interface implemented by {@link org.eclipse.emf.compare.internal.merge.MergeDataImpl}. It helps to + * know the way of merge and the editable sides of a difference. + * + * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> + */ +public interface IMergeData extends Adapter { + + /** + * Returns the merge mode the {@link #getTarget() associated} diff has been merged with. + * + * @return the merge mode the {@link #getTarget() associated} diff has been merged with. + */ + MergeMode getMergeMode(); + + /** + * Set the merge mode the {@link #getTarget() associated} diff has been merged with. + * + * @param mergeMode + * the merge mode the {@link #getTarget() associated} diff has been merged with. + */ + void setMergeMode(MergeMode mergeMode); + + /** + * Returns the target side of the merge. + * + * @return the target side of the merge. + */ + DifferenceSource getMergeTarget(); + + /** + * Returns whether the left side of the comparison is editable. + * + * @return true if the left side of the comparison is editable, false otherwise. + */ + boolean isLeftEditable(); + + /** + * Set whether the left side of the comparison is editable. + * + * @param leftEditable + * whether the left side of the comparison is editable. + */ + void setLeftEditable(boolean leftEditable); + + /** + * Returns whether the right side of the comparison is editable. + * + * @return true if the right side of the comparison is editable, false otherwise. + */ + boolean isRightEditable(); + + /** + * Set whether the right side of the comparison is editable. + * + * @param rightEditable + * whether the right side of the comparison is editable. + */ + void setRightEditable(boolean rightEditable); + +} diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/DiffMergeDataAdapter.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java index b17818273..305280bbb 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/DiffMergeDataAdapter.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java @@ -19,29 +19,29 @@ import org.eclipse.emf.compare.DifferenceSource; * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> * @since 3.0 */ -public class DiffMergeDataAdapter extends AdapterImpl implements IDiffMergeData { - - /** The merge way. */ - boolean leftToRight; +public class MergeDataImpl extends AdapterImpl implements IMergeData { /** Left side is editable. */ - boolean leftEditable; + private boolean leftEditable; /** Right side is editable. */ - boolean rightEditable; + private boolean rightEditable; + + /** The merge mode used to merge the associated diff. */ + private MergeMode mergeMode; /** * Constructor. * - * @param leftToRight - * The merge way. + * @param mergeMode + * The merge mode. * @param leftEditable * Left side editable. * @param rightEditable * Right side editable. */ - public DiffMergeDataAdapter(boolean leftToRight, boolean leftEditable, boolean rightEditable) { - this.leftToRight = leftToRight; + public MergeDataImpl(MergeMode mergeMode, boolean leftEditable, boolean rightEditable) { + this.mergeMode = mergeMode; this.leftEditable = leftEditable; this.rightEditable = rightEditable; } @@ -49,34 +49,25 @@ public class DiffMergeDataAdapter extends AdapterImpl implements IDiffMergeData /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#hasBeenMergedToLeft() - */ - public boolean hasBeenMergedToLeft() { - return !leftToRight; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#hasBeenMergedToRight() + * @see org.eclipse.emf.compare.internal.merge.IMergeData#getMergeMode() */ - public boolean hasBeenMergedToRight() { - return leftToRight; + public MergeMode getMergeMode() { + return mergeMode; } /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#setMergedTo(boolean) + * @see org.eclipse.emf.compare.internal.merge.IMergeData#getMergeTarget() */ - public void setMergedTo(boolean lToR) { - this.leftToRight = lToR; + public DifferenceSource getMergeTarget() { + return mergeMode.getMergeTarget(leftEditable, rightEditable); } /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#isLeftEditable() + * @see org.eclipse.emf.compare.internal.merge.IMergeData#isLeftEditable() */ public boolean isLeftEditable() { return leftEditable; @@ -85,16 +76,21 @@ public class DiffMergeDataAdapter extends AdapterImpl implements IDiffMergeData /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#isRightEditable() + * @see org.eclipse.emf.compare.internal.merge.IMergeData#isRightEditable() */ public boolean isRightEditable() { return rightEditable; } + @Override + public boolean isAdapterForType(Object type) { + return type == IMergeData.class; + } + /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#setLeftEditable(boolean) + * @see org.eclipse.emf.compare.internal.merge.IMergeData#setLeftEditable(boolean) */ public void setLeftEditable(boolean leftEditable) { this.leftEditable = leftEditable; @@ -103,27 +99,18 @@ public class DiffMergeDataAdapter extends AdapterImpl implements IDiffMergeData /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#setRightEditable(boolean) + * @see org.eclipse.emf.compare.internal.merge.IMergeData#setRightEditable(boolean) */ public void setRightEditable(boolean rightEditable) { this.rightEditable = rightEditable; } - @Override - public boolean isAdapterForType(Object type) { - return type == IDiffMergeData.class; - } - /** * {@inheritDoc} * - * @see org.eclipse.emf.compare.internal.merge.IDiffMergeData#mergedTo() + * @see org.eclipse.emf.compare.internal.merge.IMergeData#setMergeMode(org.eclipse.emf.compare.internal.merge.MergeMode) */ - public DifferenceSource mergedTo() { - if (leftToRight) { - return DifferenceSource.RIGHT; - } else { - return DifferenceSource.LEFT; - } + public void setMergeMode(MergeMode mergeMode) { + this.mergeMode = mergeMode; } } diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java new file mode 100644 index 000000000..ebb5b96b1 --- /dev/null +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java @@ -0,0 +1,174 @@ +/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.internal.merge;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+
+/**
+ * Enumeration of all way of merging differences.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public enum MergeMode {
+ /** Merge from left to right. */
+ LEFT_TO_RIGHT,
+
+ /** Merge form right to left. */
+ RIGHT_TO_LEFT,
+
+ /** Accept the diff to merge. */
+ ACCEPT,
+
+ /** Reject the diff to merge. */
+ REJECT;
+
+ /**
+ * Returns the inverse of this enum.
+ *
+ * @return the inverse of this enum.
+ */
+ public MergeMode inverse() {
+ final MergeMode ret;
+ switch (this) {
+ case LEFT_TO_RIGHT:
+ ret = MergeMode.RIGHT_TO_LEFT;
+ break;
+ case RIGHT_TO_LEFT:
+ ret = MergeMode.LEFT_TO_RIGHT;
+ break;
+ case ACCEPT:
+ ret = MergeMode.REJECT;
+ break;
+ case REJECT:
+ ret = MergeMode.ACCEPT;
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+ return ret;
+ }
+
+ /**
+ * Returns the target of the merge with the given condition about the left and right sides.
+ *
+ * @param isLeftEditable
+ * is the left side editable.
+ * @param isRightEditable
+ * is the right side editable.
+ * @return the target of the merge with the given condition about the left and right sides.
+ */
+ public DifferenceSource getMergeTarget(boolean isLeftEditable, boolean isRightEditable) {
+ final DifferenceSource ret;
+ switch (this) {
+ case LEFT_TO_RIGHT:
+ ret = DifferenceSource.RIGHT;
+ break;
+ case RIGHT_TO_LEFT:
+ ret = DifferenceSource.LEFT;
+ break;
+ case ACCEPT:
+ if (isLeftEditable) {
+ ret = DifferenceSource.LEFT;
+ } else if (isRightEditable) {
+ ret = DifferenceSource.RIGHT;
+ } else {
+ throw new IllegalStateException();
+ }
+ break;
+ case REJECT:
+ if (isLeftEditable) {
+ ret = DifferenceSource.RIGHT;
+ } else if (isRightEditable) {
+ ret = DifferenceSource.LEFT;
+ } else {
+ throw new IllegalStateException();
+ }
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+ return ret;
+ }
+
+ /**
+ * Returns if this mode will lead to merge to left to right depending whether left and/or right are
+ * editable.
+ *
+ * @param isLeftEditable
+ * is left side of the comparison editable.
+ * @param isRightEditable
+ * is right side of the comparison editable.
+ * @return if this mode will lead to merge to left to right depending whether left and/or right are
+ * editable.
+ */
+ public boolean isLeftToRight(boolean isLeftEditable, boolean isRightEditable) {
+ return getMergeTarget(isLeftEditable, isRightEditable) == DifferenceSource.RIGHT;
+ }
+
+ /**
+ * Returns the required action to be done to the given difference in this mode.
+ *
+ * @param difference
+ * the difference to analyze.
+ * @param isLeftEditable
+ * is left side of the comparison editable.
+ * @param isRightEditable
+ * is right side of the comparison editable.
+ * @return the required action to be done to the given difference in this mode.
+ */
+ public MergeOperation getMergeAction(Diff difference, boolean isLeftEditable, boolean isRightEditable) {
+ final MergeOperation ret;
+ switch (this) {
+ case LEFT_TO_RIGHT:
+ case RIGHT_TO_LEFT:
+ ret = MergeOperation.MERGE;
+ break;
+ case ACCEPT:
+ if (isLeftEditable) {
+ if (difference.getSource() == DifferenceSource.LEFT) {
+ ret = MergeOperation.MARK_AS_MERGE;
+ } else {
+ ret = MergeOperation.MERGE;
+ }
+ } else if (isRightEditable) {
+ if (difference.getSource() == DifferenceSource.LEFT) {
+ ret = MergeOperation.MERGE;
+ } else {
+ ret = MergeOperation.MARK_AS_MERGE;
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ break;
+ case REJECT:
+ if (isLeftEditable) {
+ if (difference.getSource() == DifferenceSource.LEFT) {
+ ret = MergeOperation.MARK_AS_MERGE;
+ } else {
+ ret = MergeOperation.MERGE;
+ }
+ } else if (isRightEditable) {
+ if (difference.getSource() == DifferenceSource.LEFT) {
+ ret = MergeOperation.MERGE;
+ } else {
+ ret = MergeOperation.MARK_AS_MERGE;
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+ return ret;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeOperation.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeOperation.java new file mode 100644 index 000000000..8b4f30859 --- /dev/null +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeOperation.java @@ -0,0 +1,25 @@ +/*******************************************************************************
+ * Copyright (c) 2013 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.internal.merge;
+
+
+/**
+ * Enumeration of all possible merge operations on differences.
+ *
+ * @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
+ */
+public enum MergeOperation {
+ /** Only mark the diff as merged without copying anything. */
+ MARK_AS_MERGE,
+
+ /** Do a regular merge with copy. */
+ MERGE;
+}
|