Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler')
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectAllChanges.java252
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectChange.java181
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedAllTo.java70
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java84
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptAllChanges.java42
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptChange.java41
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownHandler.java109
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownLeftToRight.java53
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownRightToLeft.java51
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java28
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java28
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java29
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java30
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectAllChanges.java42
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectChange.java41
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectNextDiff.java44
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectPreviousDiff.java44
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java50
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java60
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/LeftToRightSidePropertyTester.java48
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java48
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/ModelSaveablePropertyTester.java (renamed from plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/ModelSaveablePropertyTester.java)7
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/RightToLeftSidePropertyTester.java48
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/util/EMFCompareUIHandlerUtil.java194
24 files changed, 1621 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectAllChanges.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectAllChanges.java
new file mode 100644
index 000000000..6ad6ac943
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectAllChanges.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * 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.handler;
+
+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.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+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.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+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.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Abstract handler 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 AbstractAcceptRejectAllChanges extends AbstractHandler {
+
+ /** The compare configuration object used to get the compare model. */
+ protected CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ boolean rightEditableOnly = !configuration.isLeftEditable() && configuration.isRightEditable();
+ boolean leftEditableOnly = configuration.isLeftEditable() && !configuration.isRightEditable();
+ if (leftEditableOnly) {
+ manageChanges(false);
+ } else if (rightEditableOnly) {
+ manageChanges(true);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 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 = (Comparison)configuration.getProperty(EMFCompareConstants.COMPARE_RESULT);
+ 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 = (ICompareEditingDomain)configuration
+ .getProperty(EMFCompareConstants.EDITING_DOMAIN);
+
+ AcceptRejectAllChangesCompoundCommand compoundCommand = new AcceptRejectAllChangesCompoundCommand(
+ leftToRight);
+
+ for (Diff diff : differences) {
+ if (DifferenceState.UNRESOLVED == diff.getState()) {
+ if (isCopyDiffCase(diff, leftToRight)) {
+ EMFCompareUIHandlerUtil.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 = (ICompareEditingDomain)configuration
+ .getProperty(EMFCompareConstants.EDITING_DOMAIN);
+ 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() {
+ EMFCompareUIHandlerUtil.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/handler/AbstractAcceptRejectChange.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectChange.java
new file mode 100644
index 000000000..317da68e6
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractAcceptRejectChange.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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.handler;
+
+import com.google.common.collect.ImmutableSet;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+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.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+import org.eclipse.emf.compare.internal.utils.DiffUtil;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.emf.ecore.change.util.ChangeRecorder;
+import org.eclipse.emf.edit.command.ChangeCommand;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Abstract handler 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 AbstractAcceptRejectChange extends AbstractHandler {
+
+ /** The compare configuration object used to get the compare model. */
+ private CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ Object diffNode = ((CompareEditorInput)editorInput).getSelectedEdition();
+ if (diffNode instanceof Adapter) {
+ Notifier diff = ((Adapter)diffNode).getTarget();
+ if (diff instanceof Diff) {
+ boolean rightEditableOnly = !configuration.isLeftEditable()
+ && configuration.isRightEditable();
+ boolean leftEditableOnly = configuration.isLeftEditable()
+ && !configuration.isRightEditable();
+ if (leftEditableOnly) {
+ if (isCopyDiffCase((Diff)diff, false)) {
+ EMFCompareUIHandlerUtil.copyDiff((Diff)diff, false, configuration);
+ } else {
+ changeStateFromUnresolvedToMerged((Diff)diff, true);
+ }
+ } else if (rightEditableOnly) {
+ if (isCopyDiffCase((Diff)diff, true)) {
+ EMFCompareUIHandlerUtil.copyDiff((Diff)diff, true, configuration);
+ } else {
+ changeStateFromUnresolvedToMerged((Diff)diff, false);
+ }
+ }
+ // Select next diff
+ EMFCompareUIHandlerUtil.navigate(true, configuration);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 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 = (ICompareEditingDomain)configuration
+ .getProperty(EMFCompareConstants.EDITING_DOMAIN);
+ Command changeStateCommand = new AcceptRejectChangeCommand(compareEditingDomain
+ .getChangeRecorder(), diffToChangeState, leftToRight, configuration);
+ compareEditingDomain.getCommandStack().execute(changeStateCommand);
+ }
+ }
+
+ /**
+ * 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, difference.getSource())).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, difference.getSource())) {
+ EMFCompareUIHandlerUtil.setMergeDataForDiff(require, leftToRight, configuration
+ .isLeftEditable(), configuration.isRightEditable());
+ require.setState(DifferenceState.MERGED);
+ }
+ EMFCompareUIHandlerUtil.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/handler/AbstractMergedAllTo.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedAllTo.java
new file mode 100644
index 000000000..0cc28123a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedAllTo.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Abstract Handler 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 AbstractMergedAllTo extends AbstractHandler {
+
+ /** The compare configuration object used to get the compare model. */
+ private CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ setConfiguration(((CompareEditorInput)editorInput).getCompareConfiguration());
+ copyAllDiffs();
+ }
+ return null;
+ }
+
+ /**
+ * Copy all non-conflicting differences.
+ */
+ protected abstract void copyAllDiffs();
+
+ /**
+ * Get the compare configuration object.
+ *
+ * @return the configuration
+ */
+ public CompareConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * Set the compare configuration object.
+ *
+ * @param configuration
+ * the configuration to set
+ */
+ public void setConfiguration(CompareConfiguration configuration) {
+ this.configuration = configuration;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java
new file mode 100644
index 000000000..ddb017340
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AbstractMergedTo.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+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.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Abstract Handler 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 AbstractMergedTo extends AbstractHandler {
+
+ /** The compare configuration object used to get the compare model. */
+ private CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ setConfiguration(((CompareEditorInput)editorInput).getCompareConfiguration());
+ Object diffNode = ((CompareEditorInput)editorInput).getSelectedEdition();
+ if (diffNode instanceof Adapter) {
+ Notifier diff = ((Adapter)diffNode).getTarget();
+ if (diff instanceof Diff) {
+ copyDiff((Diff)diff);
+ // Select next diff
+ EMFCompareUIHandlerUtil.navigate(true, configuration);
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Copy the diff.
+ *
+ * @param diff
+ * the given diff.
+ */
+ protected abstract void copyDiff(Diff diff);
+
+ /**
+ * Get the compare configuration object.
+ *
+ * @return the configuration
+ */
+ public CompareConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * Set the compare configuration object.
+ *
+ * @param configuration
+ * the configuration to set
+ */
+ public void setConfiguration(CompareConfiguration configuration) {
+ this.configuration = configuration;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptAllChanges.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptAllChanges.java
new file mode 100644
index 000000000..2929d5702
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptAllChanges.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.handler;
+
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+
+/**
+ * Handler 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 AcceptAllChanges extends AbstractAcceptRejectAllChanges {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractAcceptRejectAllChanges#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/handler/AcceptChange.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptChange.java
new file mode 100644
index 000000000..89967207a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/AcceptChange.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.handler;
+
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+
+/**
+ * Handler 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 AcceptChange extends AbstractAcceptRejectChange {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractAcceptRejectChange#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/handler/DropDownHandler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownHandler.java
new file mode 100644
index 000000000..3d9494106
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownHandler.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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.handler;
+
+import java.util.Map;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.internal.CompareEditor;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.commands.IElementUpdater;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.menus.UIElement;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * Handler that manages the click on the dropdown menu of the toolbar of the structure merge viewer.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ */
+public class DropDownHandler extends AbstractHandler implements IElementUpdater {
+
+ /** The compare configuration object. */
+ private CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ Object trigger = event.getTrigger();
+ if (trigger instanceof Event) {
+ Event eventWidget = (Event)event.getTrigger();
+ Widget widget = eventWidget.widget;
+ if (widget instanceof ToolItem) {
+ ToolItem toolItem = (ToolItem)widget;
+ configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ Boolean mergeWay = (Boolean)configuration.getProperty(EMFCompareConstants.MERGE_WAY);
+ if (mergeWay == null || mergeWay.booleanValue()) {
+ configuration.setProperty(EMFCompareConstants.MERGE_WAY, new Boolean(false));
+ toolItem.setImage(EMFCompareIDEUIPlugin
+ .getImage("icons/full/toolb16/right_to_left.gif")); //$NON-NLS-1$
+ } else {
+ configuration.setProperty(EMFCompareConstants.MERGE_WAY, new Boolean(true));
+ toolItem.setImage(EMFCompareIDEUIPlugin
+ .getImage("icons/full/toolb16/left_to_right.gif")); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.ui.commands.IElementUpdater#updateElement(UIElement, Map)
+ */
+ public void updateElement(UIElement element, Map parameters) {
+ if (configuration == null) {
+ Object value = parameters.get("org.eclipse.ui.IWorkbenchWindow"); //$NON-NLS-1$
+ if (value instanceof IWorkbenchWindow) {
+ IWorkbenchPage pa = ((IWorkbenchWindow)value).getActivePage();
+ IEditorPart editor = pa.getActiveEditor();
+ if (editor instanceof CompareEditor) {
+ IEditorInput editorInput = editor.getEditorInput();
+ if (editorInput instanceof CompareEditorInput) {
+ configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ }
+ }
+ }
+ }
+ if (configuration != null) {
+ Boolean mergeWay = (Boolean)configuration.getProperty(EMFCompareConstants.MERGE_WAY);
+ if (mergeWay == null || mergeWay.booleanValue()) {
+ element.setIcon(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
+ "icons/full/toolb16/left_to_right.gif")); //$NON-NLS-1$
+ } else {
+ element.setIcon(AbstractUIPlugin.imageDescriptorFromPlugin(EMFCompareIDEUIPlugin.PLUGIN_ID,
+ "icons/full/toolb16/right_to_left.gif")); //$NON-NLS-1$
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownLeftToRight.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownLeftToRight.java
new file mode 100644
index 000000000..beeca1c86
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownLeftToRight.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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.handler;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler that manages the click on the menu item left to right in the dropdown menu of the toolbar of the
+ * structure merge viewer.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ */
+public class DropDownLeftToRight extends AbstractHandler {
+
+ /** The compare configuration object. */
+ private CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ configuration.setProperty(EMFCompareConstants.MERGE_WAY, new Boolean(true));
+ }
+
+ ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(
+ ICommandService.class);
+ commandService.refreshElements("org.eclipse.emf.compare.ide.ui.dropdown", null); //$NON-NLS-1$
+
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownRightToLeft.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownRightToLeft.java
new file mode 100644
index 000000000..3daff914f
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/DropDownRightToLeft.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 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.handler;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler that manages the click on the menu item right to left in the dropdown menu of the toolbar of the
+ * structure merge viewer.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ */
+public class DropDownRightToLeft extends AbstractHandler {
+
+ /** The compare configuration object. */
+ private CompareConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ configuration.setProperty(EMFCompareConstants.MERGE_WAY, new Boolean(false));
+ }
+ ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(
+ ICommandService.class);
+ commandService.refreshElements("org.eclipse.emf.compare.ide.ui.dropdown", null); //$NON-NLS-1$
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java
new file mode 100644
index 000000000..543f4c945
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToLeft.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+
+/**
+ * Handler 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 MergedAllToLeft extends AbstractMergedAllTo {
+
+ @Override
+ protected void copyAllDiffs() {
+ EMFCompareUIHandlerUtil.copyAllDiffs(false, getConfiguration());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java
new file mode 100644
index 000000000..eab8d32f0
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedAllToRight.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+
+/**
+ * Handler 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 MergedAllToRight extends AbstractMergedAllTo {
+
+ @Override
+ protected void copyAllDiffs() {
+ EMFCompareUIHandlerUtil.copyAllDiffs(true, getConfiguration());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java
new file mode 100644
index 000000000..dde61ec92
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToLeft.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+
+/**
+ * Handler 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 MergedToLeft extends AbstractMergedTo {
+
+ @Override
+ protected void copyDiff(Diff diff) {
+ EMFCompareUIHandlerUtil.copyDiff(diff, false, getConfiguration());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java
new file mode 100644
index 000000000..5e754f386
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/MergedToRight.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+
+/**
+ * Handler 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 MergedToRight extends AbstractMergedTo {
+
+ @Override
+ protected void copyDiff(Diff diff) {
+ EMFCompareUIHandlerUtil.copyDiff(diff, true, getConfiguration());
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectAllChanges.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectAllChanges.java
new file mode 100644
index 000000000..1e9cd62a9
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectAllChanges.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.handler;
+
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+
+/**
+ * Handler 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 RejectAllChanges extends AbstractAcceptRejectAllChanges {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractAcceptRejectAllChanges#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/handler/RejectChange.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectChange.java
new file mode 100644
index 000000000..996a129bd
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/RejectChange.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.handler;
+
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
+
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+
+/**
+ * Handler that manages a reject 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 RejectChange extends AbstractAcceptRejectChange {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractAcceptRejectChange#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/handler/SelectNextDiff.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectNextDiff.java
new file mode 100644
index 000000000..e2e6bb163
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectNextDiff.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler that manages the select next diff button.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ */
+public class SelectNextDiff extends AbstractHandler {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ // Select next diff
+ EMFCompareUIHandlerUtil.navigate(true, configuration);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectPreviousDiff.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectPreviousDiff.java
new file mode 100644
index 000000000..5ecd4e10d
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/SelectPreviousDiff.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.handler;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.util.EMFCompareUIHandlerUtil;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Handler that manages the select previous diff button.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ */
+public class SelectPreviousDiff extends AbstractHandler {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Object editorInput = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)editorInput).getCompareConfiguration();
+ // Select next diff
+ EMFCompareUIHandlerUtil.navigate(false, configuration);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java
new file mode 100644
index 000000000..a79978c13
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/AcceptRejectChangePropertyTester.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.handler.propertytester;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * A property tester linked with
+ * {@link org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractMergedTo}. It returns
+ * true when only one model side is editable.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class AcceptRejectChangePropertyTester extends PropertyTester {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String,
+ * java.lang.Object[], java.lang.Object)
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof IEditorPart) {
+ IEditorInput i = ((IEditorPart)receiver).getEditorInput();
+ if (i instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)i).getCompareConfiguration();
+ if (configuration.isLeftEditable() && !configuration.isRightEditable()) {
+ return true;
+ } else if (!configuration.isLeftEditable() && configuration.isRightEditable()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java
new file mode 100644
index 000000000..ebad5be65
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/DiffSelectedPropertyTester.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.handler.propertytester;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.expressions.PropertyTester;
+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.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * A property tester that checks if a diff is selected in the compare editor.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class DiffSelectedPropertyTester extends PropertyTester {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String,
+ * java.lang.Object[], java.lang.Object)
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof IEditorPart) {
+ IEditorInput i = ((IEditorPart)receiver).getEditorInput();
+ if (i instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)i).getCompareConfiguration();
+ ISelection selection = (ISelection)configuration
+ .getProperty(EMFCompareConstants.SMV_SELECTION);
+ if (selection instanceof IStructuredSelection) {
+ Object element = ((IStructuredSelection)selection).getFirstElement();
+ if (element instanceof Adapter) {
+ Notifier diffNode = ((Adapter)element).getTarget();
+ if (diffNode instanceof Diff) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/LeftToRightSidePropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/LeftToRightSidePropertyTester.java
new file mode 100644
index 000000000..780860517
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/LeftToRightSidePropertyTester.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.handler.propertytester;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * A property tester that check the way of merge.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class LeftToRightSidePropertyTester extends PropertyTester {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String,
+ * java.lang.Object[], java.lang.Object)
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof IEditorPart) {
+ IEditorInput i = ((IEditorPart)receiver).getEditorInput();
+ if (i instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)i).getCompareConfiguration();
+ Boolean leftToRight = (Boolean)configuration.getProperty(EMFCompareConstants.MERGE_WAY);
+ if (leftToRight == null || leftToRight.booleanValue()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java
new file mode 100644
index 000000000..75447c35f
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/MergedToPropertyTester.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.handler.propertytester;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * A property tester linked with
+ * {@link org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.handler.AbstractMergedTo}. It returns
+ * true when both model sides are editable.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class MergedToPropertyTester extends PropertyTester {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String,
+ * java.lang.Object[], java.lang.Object)
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof IEditorPart) {
+ IEditorInput i = ((IEditorPart)receiver).getEditorInput();
+ if (i instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)i).getCompareConfiguration();
+ if (configuration.isLeftEditable() && configuration.isRightEditable()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/ModelSaveablePropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/ModelSaveablePropertyTester.java
index 3b409db57..ea6890f04 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/ModelSaveablePropertyTester.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/ModelSaveablePropertyTester.java
@@ -8,7 +8,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
-package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler;
+package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.propertytester;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
@@ -17,8 +17,9 @@ import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
/**
- * A property tester linked with {@link SaveComparisonModel}. It tests the editable property of both model
- * sides.
+ * A property tester linked with
+ * {@link org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.handler.SaveComparisonModel}. It tests
+ * the editable property of both model sides.
*
* @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
* @since 3.0
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/RightToLeftSidePropertyTester.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/RightToLeftSidePropertyTester.java
new file mode 100644
index 000000000..92310abc7
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/propertytester/RightToLeftSidePropertyTester.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.handler.propertytester;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareConstants;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * A property tester that check the way of merge.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public class RightToLeftSidePropertyTester extends PropertyTester {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.core.expressions.PropertyTester#test(java.lang.Object, java.lang.String,
+ * java.lang.Object[], java.lang.Object)
+ */
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof IEditorPart) {
+ IEditorInput i = ((IEditorPart)receiver).getEditorInput();
+ if (i instanceof CompareEditorInput) {
+ CompareConfiguration configuration = ((CompareEditorInput)i).getCompareConfiguration();
+ Boolean leftToRight = (Boolean)configuration.getProperty(EMFCompareConstants.MERGE_WAY);
+ if (leftToRight != null && !leftToRight.booleanValue()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/util/EMFCompareUIHandlerUtil.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/util/EMFCompareUIHandlerUtil.java
new file mode 100644
index 000000000..59e1b6bb9
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/handler/util/EMFCompareUIHandlerUtil.java
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * 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.handler.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.Collection;
+import java.util.List;
+
+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.Diff;
+import org.eclipse.emf.compare.DifferenceSource;
+import org.eclipse.emf.compare.DifferenceState;
+import org.eclipse.emf.compare.domain.ICompareEditingDomain;
+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.EMFCompareConstants;
+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 RCP UI handlers.
+ *
+ * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a>
+ * @since 3.0
+ */
+public final class EMFCompareUIHandlerUtil {
+
+ /**
+ * Utility classes don't need a default constructor.
+ */
+ private EMFCompareUIHandlerUtil() {
+ // Hides default constructor.
+ }
+
+ /**
+ * 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(CompareConfiguration configuration) {
+ Object property = configuration.getProperty(EMFCompareConstants.SELECTED_FILTERS);
+ final Collection<IDifferenceFilter> selectedFilters;
+ if (property != null) {
+ selectedFilters = (Collection<IDifferenceFilter>)property;
+ 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, CompareConfiguration configuration) {
+ if (diffToCopy != null) {
+ List<Diff> diffsToCopy = new ArrayList<Diff>();
+ diffsToCopy.add(diffToCopy);
+ for (Diff require : DiffUtil.getRequires(diffToCopy, leftToRight, diffToCopy.getSource())) {
+ EMFCompareUIHandlerUtil.setMergeDataForDiff(require, leftToRight, configuration
+ .isLeftEditable(), configuration.isRightEditable());
+ }
+ if (EMFCompareUIHandlerUtil.isCascadingDifferencesFilterActive(configuration)) {
+ addAll(diffsToCopy, org.eclipse.emf.compare.utils.DiffUtil.getSubDiffs(leftToRight).apply(
+ diffToCopy));
+ }
+ for (Diff diff : diffsToCopy) {
+ EMFCompareUIHandlerUtil.setMergeDataForDiff(diff, leftToRight,
+ configuration.isLeftEditable(), configuration.isRightEditable());
+ }
+ ICompareEditingDomain editingDomain = (ICompareEditingDomain)configuration
+ .getProperty(EMFCompareConstants.EDITING_DOMAIN);
+ Command copyCommand = editingDomain.createCopyCommand(diffsToCopy, leftToRight,
+ EMFCompareRCPPlugin.getDefault().getMergerRegistry());
+ editingDomain.getCommandStack().execute(copyCommand);
+ }
+ }
+
+ /**
+ * Copy all non-conflicting changes.
+ *
+ * @param leftToRight
+ * the way of merge.
+ * @param configuration
+ * the compare configuration object.
+ */
+ public static void copyAllDiffs(final boolean leftToRight, CompareConfiguration configuration) {
+ final List<Diff> differences;
+ Comparison comparison = (Comparison)configuration.getProperty(EMFCompareConstants.COMPARE_RESULT);
+ 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) {
+ EMFCompareUIHandlerUtil.setMergeDataForDiff(diff, leftToRight,
+ configuration.isLeftEditable(), configuration.isRightEditable());
+ }
+ ICompareEditingDomain editingDomain = (ICompareEditingDomain)configuration
+ .getProperty(EMFCompareConstants.EDITING_DOMAIN);
+ 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.
+ *
+ * @param next
+ * <code>true</code> if we are to open the next structure viewer's diff, <code>false</code> if
+ * we should go to the previous instead.
+ * @param configuration
+ * the compare configuration object.
+ */
+ public static void navigate(boolean next, CompareConfiguration configuration) {
+ final ICompareNavigator navigator = configuration.getContainer().getNavigator();
+ if (navigator instanceof CompareNavigator && ((CompareNavigator)navigator).hasChange(next)) {
+ 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));
+ }
+ }
+}

Back to the top