View | Details | Raw Unified | Return to bug 300237 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelCompareEditorInput.java (-3 / +17 lines)
Lines 20-27 Link Here
20
import org.eclipse.jface.action.*;
20
import org.eclipse.jface.action.*;
21
import org.eclipse.jface.viewers.*;
21
import org.eclipse.jface.viewers.*;
22
import org.eclipse.team.internal.ui.*;
22
import org.eclipse.team.internal.ui.*;
23
import org.eclipse.team.internal.ui.mapping.ModelCompareEditorInput;
23
import org.eclipse.team.internal.ui.mapping.*;
24
import org.eclipse.team.internal.ui.mapping.ResourceMergeHandler;
25
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
24
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
26
import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
25
import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
27
import org.eclipse.ui.IWorkbenchActionConstants;
26
import org.eclipse.ui.IWorkbenchActionConstants;
Lines 38-44 Link Here
38
37
39
	protected void handleMenuAboutToShow(IMenuManager manager) {
38
	protected void handleMenuAboutToShow(IMenuManager manager) {
40
		StructuredSelection selection = new StructuredSelection(((IResourceProvider)getCompareInput()).getResource());
39
		StructuredSelection selection = new StructuredSelection(((IResourceProvider)getCompareInput()).getResource());
41
40
		final ResourceMarkAsMergedHandler markAsMergedHandler = new ResourceMarkAsMergedHandler(getSynchronizeConfiguration());
41
		markAsMergedHandler.updateEnablement(selection);
42
		Action markAsMergedAction = new Action(TeamUIMessages.ModelCompareEditorInput_0) {
43
			public void run() {
44
				try {
45
					markAsMergedHandler.execute(new ExecutionEvent());
46
				} catch (ExecutionException e) {
47
					TeamUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
48
				}
49
			}
50
			
51
		};
52
		Utils.initAction(markAsMergedAction, "action.markAsMerged."); //$NON-NLS-1$
53
		markAsMergedAction.setEnabled(markAsMergedAction.isEnabled());
54
		
42
		final ResourceMergeHandler mergeHandler = new ResourceMergeHandler(getSynchronizeConfiguration(), false);
55
		final ResourceMergeHandler mergeHandler = new ResourceMergeHandler(getSynchronizeConfiguration(), false);
43
		mergeHandler.updateEnablement(selection);
56
		mergeHandler.updateEnablement(selection);
44
		Action mergeAction = new Action(TeamUIMessages.ModelCompareEditorInput_1) {
57
		Action mergeAction = new Action(TeamUIMessages.ModelCompareEditorInput_1) {
Lines 54-59 Link Here
54
		mergeAction.setEnabled(mergeAction.isEnabled());
67
		mergeAction.setEnabled(mergeAction.isEnabled());
55
68
56
		manager.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, new Separator("merge")); //$NON-NLS-1$
69
		manager.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS, new Separator("merge")); //$NON-NLS-1$
70
		manager.insertAfter("merge", markAsMergedAction); //$NON-NLS-1$
57
		manager.insertAfter("merge", mergeAction); //$NON-NLS-1$
71
		manager.insertAfter("merge", mergeAction); //$NON-NLS-1$
58
	}
72
	}
59
73
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java (-3 lines)
Lines 63-71 Link Here
63
			if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) {
63
			if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) {
64
				// omit this action
64
				// omit this action
65
				return;
65
				return;
66
			} else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) {
67
				// omit this action
68
				return;
69
			}
66
			}
70
			super.addToContextMenu(mergeActionId, action, manager);
67
			super.addToContextMenu(mergeActionId, action, manager);
71
		}
68
		}
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSubscriberMergeContext.java (-13 / +25 lines)
Lines 18-23 Link Here
18
import org.eclipse.core.runtime.jobs.ISchedulingRule;
18
import org.eclipse.core.runtime.jobs.ISchedulingRule;
19
import org.eclipse.team.core.diff.IDiff;
19
import org.eclipse.team.core.diff.IDiff;
20
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
20
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
21
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
21
import org.eclipse.team.core.subscribers.Subscriber;
22
import org.eclipse.team.core.subscribers.Subscriber;
22
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
23
import org.eclipse.team.core.subscribers.SubscriberMergeContext;
23
24
Lines 44-64 Link Here
44
45
45
	public void markAsMerged(IDiff node, boolean inSyncHint,
46
	public void markAsMerged(IDiff node, boolean inSyncHint,
46
			IProgressMonitor monitor) throws CoreException {
47
			IProgressMonitor monitor) throws CoreException {
47
		IResource resource = getDiffTree().getResource(node);
48
		ResourceDiffTree tree = (ResourceDiffTree)getDiffTree();
48
		WorkspacePatcher patcher = ((ApplyPatchSubscriber) getSubscriber())
49
		IResource resource = tree.getResource(node);
49
				.getPatcher();
50
		WorkspacePatcher patcher = ((ApplyPatchSubscriber) getSubscriber()).getPatcher();
50
		Object object = PatchModelProvider.getPatchObject(resource, patcher);
51
		Object object = PatchModelProvider.getPatchObject(resource, patcher);
51
		if (object instanceof FilePatch2) {
52
		try {
52
			FilePatch2 filePatch = (FilePatch2) object;
53
			tree.beginInput();
53
			FileDiffResult fileDiffResult = patcher.getDiffResult(filePatch);
54
			if (object instanceof FilePatch2) {
54
			HunkResult[] hunkResults = fileDiffResult.getHunkResults();
55
				FilePatch2 filePatch = (FilePatch2) object;
55
			for (int i = 0; i < hunkResults.length; i++) {
56
				FileDiffResult fileDiffResult = patcher.getDiffResult(filePatch);
56
				// disable hunks that were merged
57
				HunkResult[] hunkResults = fileDiffResult.getHunkResults();
57
				if (hunkResults[i].isOK())
58
				for (int i = 0; i < hunkResults.length; i++) {
58
					patcher.setEnabled(hunkResults[i].getHunk(), false);
59
					if (inSyncHint) {
60
						// disable hunks that were merged
61
						if (hunkResults[i].isOK())
62
							patcher.setEnabled(hunkResults[i].getHunk(), false);
63
					} else {
64
						patcher.setManuallyMerged(hunkResults[i].getHunk(), true);
65
					}
66
				}
67
			} else {
68
				patcher.setEnabled(object, false);
69
				// TODO: mark as merged
59
			}
70
			}
60
		} else {
71
			tree.remove(resource);
61
			patcher.setEnabled(object, false);
72
		} finally {
73
			tree.endInput(monitor);
62
		}
74
		}
63
	}
75
	}
64
76
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchSynchronizationActionProvider.java (-2 / +5 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.team.internal.ui.mapping.ResourceMarkAsMergedHandler;
13
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
14
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
14
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
15
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
15
16
Lines 23-32 Link Here
23
	protected void initialize() {
24
	protected void initialize() {
24
		super.initialize();
25
		super.initialize();
25
		final ISynchronizePageConfiguration configuration = getSynchronizePageConfiguration();
26
		final ISynchronizePageConfiguration configuration = getSynchronizePageConfiguration();
26
		// We provide custom handler that is disabled for hunks.
27
		// Provide custom handler, disabled for hunks.
27
		registerHandler(MERGE_ACTION_ID, new ApplyPatchMergeActionHandler(
28
		registerHandler(MERGE_ACTION_ID, new ApplyPatchMergeActionHandler(
28
				configuration, false));
29
				configuration, false));
29
		// 'Overwrite' and 'Mark as merged' actions are not shown, see
30
		registerHandler(MARK_AS_MERGE_ACTION_ID,
31
				new ResourceMarkAsMergedHandler(configuration));
32
		// 'Overwrite' action is not shown, see
30
		// ApplyPatchModelSynchronizeParticipant.ApplyPatchModelSynchronizeParticipantActionGroup.addToContextMenu(String,
33
		// ApplyPatchModelSynchronizeParticipant.ApplyPatchModelSynchronizeParticipantActionGroup.addToContextMenu(String,
31
		// Action, IMenuManager)
34
		// Action, IMenuManager)
32
	}
35
	}
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ExcludedPatchDiffNodesFilter.java (-38 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
13
import org.eclipse.compare.internal.patch.PatchDiffNode;
14
import org.eclipse.jface.viewers.Viewer;
15
import org.eclipse.jface.viewers.ViewerFilter;
16
17
public class ExcludedPatchDiffNodesFilter extends ViewerFilter {
18
19
	private static ViewerFilter filter;
20
21
	public static ViewerFilter getInstance() {
22
		if (filter == null)
23
			filter = new ExcludedPatchDiffNodesFilter();
24
		return filter;
25
	}
26
27
	public ExcludedPatchDiffNodesFilter() {
28
		super();
29
	}
30
31
	public boolean select(Viewer viewer, Object parentElement, Object element) {
32
		if (element instanceof PatchDiffNode) {
33
			PatchDiffNode node = (PatchDiffNode) element;
34
			return node.isEnabled();
35
		}
36
		return true;
37
	}
38
}
(-)src/org/eclipse/team/internal/ui/synchronize/patch/PatchSyncContentProvider.java (-12 / +47 lines)
Lines 10-27 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.compare.internal.patch.HunkDiffNode;
13
import org.eclipse.compare.internal.patch.*;
14
import org.eclipse.compare.internal.patch.PatchDiffNode;
15
import org.eclipse.compare.structuremergeviewer.IDiffElement;
14
import org.eclipse.compare.structuremergeviewer.IDiffElement;
16
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.mapping.*;
16
import org.eclipse.core.resources.mapping.*;
18
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.jface.util.PropertyChangeEvent;
19
import org.eclipse.jface.util.PropertyChangeEvent;
21
import org.eclipse.jface.viewers.ITreeContentProvider;
20
import org.eclipse.jface.viewers.*;
22
import org.eclipse.jface.viewers.Viewer;
23
import org.eclipse.team.core.mapping.ISynchronizationContext;
21
import org.eclipse.team.core.mapping.ISynchronizationContext;
24
import org.eclipse.team.core.mapping.ISynchronizationScope;
22
import org.eclipse.team.core.mapping.ISynchronizationScope;
23
import org.eclipse.team.core.subscribers.Subscriber;
25
import org.eclipse.team.internal.ui.TeamUIPlugin;
24
import org.eclipse.team.internal.ui.TeamUIPlugin;
26
import org.eclipse.team.internal.ui.mapping.SynchronizationResourceMappingContext;
25
import org.eclipse.team.internal.ui.mapping.SynchronizationResourceMappingContext;
27
import org.eclipse.team.ui.mapping.SynchronizationContentProvider;
26
import org.eclipse.team.ui.mapping.SynchronizationContentProvider;
Lines 54-67 Link Here
54
	}
53
	}
55
54
56
	protected Object getModelRoot() {
55
	protected Object getModelRoot() {
56
		return PatchModelProvider.getPatchWorkspace(getSubscriber());
57
	}
58
	
59
	private Subscriber getSubscriber() {
57
		if (getContext() instanceof ApplyPatchSubscriberMergeContext) {
60
		if (getContext() instanceof ApplyPatchSubscriberMergeContext) {
58
			ApplyPatchSubscriberMergeContext context = (ApplyPatchSubscriberMergeContext) getContext();
61
			ApplyPatchSubscriberMergeContext context = (ApplyPatchSubscriberMergeContext) getContext();
59
			return PatchModelProvider.getPatchWorkspace(context.getSubscriber());
62
			return context.getSubscriber();
60
		}
63
		}
61
		// TODO: assertion?
62
		return null;
64
		return null;
63
	}
65
	}
64
66
	
65
	/*
67
	/*
66
	 * Copied from
68
	 * Copied from
67
	 * org.eclipse.team.examples.model.ui.mapping.ModelSyncContentProvider
69
	 * org.eclipse.team.examples.model.ui.mapping.ModelSyncContentProvider
Lines 94-100 Link Here
94
		}
96
		}
95
		return false;
97
		return false;
96
	}
98
	}
99
	
100
	private class ExcludedPatchDiffNodesFilter extends ViewerFilter {
97
101
102
		public boolean select(Viewer viewer, Object parentElement, Object element) {
103
			if (element instanceof PatchDiffNode) {
104
				PatchDiffNode node = (PatchDiffNode) element;
105
				if (!node.isEnabled())
106
					return false;
107
				if (node instanceof PatchFileDiffNode) {
108
					// when at least one hunk is manually merged, hide the node
109
					PatchFileDiffNode file = (PatchFileDiffNode) node;
110
					IDiffElement[] children = file.getChildren();
111
					for (int i = 0; i < children.length; i++) {
112
						if (children[i] instanceof HunkDiffNode) {
113
							HunkDiffNode hunk = (HunkDiffNode) children[i];
114
							WorkspacePatcher patcher = ((ApplyPatchSubscriber)PatchSyncContentProvider.this.getSubscriber()).getPatcher();
115
							if (patcher.isManuallyMerged(hunk.getHunkResult().getHunk()))
116
								return false;
117
						}
118
					}
119
				}
120
			}
121
			return true;
122
		}
123
	}
124
	
125
	private ViewerFilter filter;
126
	
127
	public ViewerFilter getInstance() {
128
		if (filter == null)
129
			filter = new ExcludedPatchDiffNodesFilter();
130
		return filter;
131
	}
132
	
98
	public void propertyChange(PropertyChangeEvent event) {
133
	public void propertyChange(PropertyChangeEvent event) {
99
		super.propertyChange(event);
134
		super.propertyChange(event);
100
		if (event.getProperty().equals(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER)) {
135
		if (event.getProperty().equals(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER)) {
Lines 115-134 Link Here
115
		}
150
		}
116
	}
151
	}
117
152
118
	private static void addFilter(Viewer v) {
153
	private void addFilter(Viewer v) {
119
		if (v != null && v instanceof CommonViewer) {
154
		if (v != null && v instanceof CommonViewer) {
120
			CommonViewer cv = (CommonViewer) v;
155
			CommonViewer cv = (CommonViewer) v;
121
			cv.addFilter(ExcludedPatchDiffNodesFilter.getInstance());
156
			cv.addFilter(getInstance());
122
		}
157
		}
123
	}
158
	}
124
159
125
	private static void removeFilter(Viewer v) {
160
	private void removeFilter(Viewer v) {
126
		if (v != null && v instanceof CommonViewer) {
161
		if (v != null && v instanceof CommonViewer) {
127
			CommonViewer cv = (CommonViewer) v;
162
			CommonViewer cv = (CommonViewer) v;
128
			cv.removeFilter(ExcludedPatchDiffNodesFilter.getInstance());
163
			cv.removeFilter(getInstance());
129
		}
164
		}
130
	}
165
	}
131
166
	
132
	public boolean hasChildren(final Object element) {
167
	public boolean hasChildren(final Object element) {
133
		if (element instanceof HunkDiffNode)
168
		if (element instanceof HunkDiffNode)
134
			return false;
169
			return false;

Return to bug 300237