Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7f8838521ae70679d7bf00a5b2f78d1fbb3507aa (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
/*******************************************************************************
 * Copyright (c) 2010 IBM Corporation and others.
 * 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:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.patch;

import org.eclipse.compare.internal.patch.HunkDiffNode;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.internal.ui.mapping.ResourceMarkAsMergedHandler;
import org.eclipse.team.internal.ui.mapping.ResourceMergeHandler;
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;

public class ApplyPatchSynchronizationActionProvider extends
		SynchronizationActionProvider {

	public ApplyPatchSynchronizationActionProvider() {
		super();
	}

	@Override
	protected void initialize() {
		super.initialize();
		final ISynchronizePageConfiguration configuration = getSynchronizePageConfiguration();
		// Use custom handlers, disabled for hunks.
		registerHandler(MERGE_ACTION_ID, new ResourceMergeHandler(
				configuration, false) {
			@Override
			public void updateEnablement(IStructuredSelection selection) {
				super.updateEnablement(selection);
				// disable merge for hunks
				Object[] elements = getOperation().getElements();
				for (int i = 0; i < elements.length; i++) {
					if (elements[i] instanceof HunkDiffNode) {
						setEnabled(false);
						return;
					}
				}
			}
		});
		registerHandler(MARK_AS_MERGE_ACTION_ID,
				new ResourceMarkAsMergedHandler(configuration) {
			@Override
			public void updateEnablement(IStructuredSelection selection) {
				super.updateEnablement(selection);
				// disable mark as merged for hunks
				Object[] elements = getOperation().getElements();
				for (int i = 0; i < elements.length; i++) {
					if (elements[i] instanceof HunkDiffNode) {
						setEnabled(false);
						return;
					}
				}
			}
		});
		// 'Overwrite' action is not shown, see
		// ApplyPatchModelSynchronizeParticipant.ApplyPatchModelSynchronizeParticipantActionGroup.addToContextMenu(String,
		// Action, IMenuManager)
	}
}

Back to the top