Skip to main content
summaryrefslogtreecommitdiffstats
blob: ddb0173402bdf622d5c44a2e56b973ddffd7ebf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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;
	}
}

Back to the top