Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9a4792ee58686e29a57e315b42f60a6aa71e2e74 (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
/*******************************************************************************
 * Copyright (c) 2006 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.examples.filesystem.ui;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.ui.ISaveableWorkbenchPart;
import org.eclipse.team.ui.SaveablePartDialog;

/**
 * A dialog that can be used to merge conflicting model elements without 
 * using the Synchronization framework. This is experimental.
 * See {@link NonSyncModelMergeOperation}
 * for a description of this work flow and its shortcomings.
 */
public class NonSyncMergeDialog extends SaveablePartDialog {

	public static void openFor(NonSyncModelMergeOperation operation) {
		NonSyncModelMergePage page = new NonSyncModelMergePage((IMergeContext) operation.getContext());
		NonSyncMergePart part = new NonSyncMergePart(operation.getShell(), new CompareConfiguration(), page);
		NonSyncMergeDialog dialog = new NonSyncMergeDialog(operation.getShell(), part);
		dialog.open();
	}
	
	public NonSyncMergeDialog(Shell shell, ISaveableWorkbenchPart input) {
		super(shell, input);
	}
	
	protected void buttonPressed(int buttonId) {
		if (buttonId == OK) {
			NonSyncMergePart part = (NonSyncMergePart)getInput();
			IMergeContext context = part.getContext();
			if (hasUnmergedChanges(context)) {
				if (!MessageDialog.openQuestion(getShell(), "Unmerged Changes", "There are still unmerged changes. Are you sure you want to close the dialog?"))
					return;
			}
		}
		super.buttonPressed(buttonId);
	}

	private boolean hasUnmergedChanges(IMergeContext context) {
		return context.getDiffTree().hasMatchingDiffs(
				ResourcesPlugin.getWorkspace().getRoot().getFullPath(), 
				new FastDiffFilter() {
					public boolean select(IDiff diff) {
						if (diff instanceof IThreeWayDiff) {
							IThreeWayDiff twd = (IThreeWayDiff) diff;
							return twd.getDirection() == IThreeWayDiff.INCOMING || twd.getDirection() == IThreeWayDiff.CONFLICTING;
						}
						return false;
					}
				});
	}

}

Back to the top