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

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/CompareMessages.java (+1 lines)
Lines 118-123 Link Here
118
	public static String CompareWithOther_error_empty;
118
	public static String CompareWithOther_error_empty;
119
	public static String CompareWithOther_clear;
119
	public static String CompareWithOther_clear;
120
	public static String CompareWithOther_warning_two_way;
120
	public static String CompareWithOther_warning_two_way;
121
	public static String CompareWithOther_info;
121
122
122
	static {
123
	static {
123
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
124
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java (-4 / +5 lines)
Lines 166-172 Link Here
166
			createContents(parent);
166
			createContents(parent);
167
		}
167
		}
168
168
169
		public InternalSection() {
169
		private InternalSection() {
170
			// not to instantiate
170
			// not to instantiate
171
		}
171
		}
172
172
Lines 398-403 Link Here
398
		super.createButtonsForButtonBar(parent);
398
		super.createButtonsForButtonBar(parent);
399
		okButton = getButton(IDialogConstants.OK_ID);
399
		okButton = getButton(IDialogConstants.OK_ID);
400
		updateErrorInfo();
400
		updateErrorInfo();
401
		setMessage(CompareMessages.CompareWithOther_info);
401
	}
402
	}
402
403
403
	private void setSelection(ISelection selection) {
404
	private void setSelection(ISelection selection) {
Lines 419-425 Link Here
419
		}
420
		}
420
	}
421
	}
421
422
422
	private boolean comparePossible() {
423
	private boolean isComparePossible() {
423
		IResource[] resources;
424
		IResource[] resources;
424
		if (ancestorPanel.getResource() == null) {
425
		if (ancestorPanel.getResource() == null) {
425
			resources = new IResource[] { leftPanel.getResource(),
426
			resources = new IResource[] { leftPanel.getResource(),
Lines 445-457 Link Here
445
					&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$
446
					&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$
446
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
447
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
447
						IMessageProvider.WARNING);
448
						IMessageProvider.WARNING);
448
			} else if (!comparePossible()) {
449
			} else if (!isComparePossible()) {
449
				setMessage(
450
				setMessage(
450
						CompareMessages.CompareWithOther_error_not_comparable,
451
						CompareMessages.CompareWithOther_error_not_comparable,
451
						IMessageProvider.ERROR);
452
						IMessageProvider.ERROR);
452
				okButton.setEnabled(false);
453
				okButton.setEnabled(false);
453
			} else {
454
			} else {
454
				setMessage(null);
455
				setMessage(CompareMessages.CompareWithOther_info);
455
				okButton.setEnabled(true);
456
				okButton.setEnabled(true);
456
			}
457
			}
457
		}
458
		}
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java (-35 / +13 lines)
Lines 10-60 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
11
package org.eclipse.compare.internal;
12
12
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.compare.CompareConfiguration;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.dialogs.IDialogConstants;
16
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
15
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.ui.IObjectActionDelegate;
20
import org.eclipse.ui.IWorkbenchPart;
21
import org.eclipse.ui.PlatformUI;
22
16
23
/**
17
/**
24
 * The "Compare with other resource" action
18
 * The "Compare with other resource" action
25
 * 
19
 *
26
 * @since 3.4
20
 * @since 3.4
27
 */
21
 */
28
public class CompareWithOtherResourceAction implements IObjectActionDelegate {
22
public class CompareWithOtherResourceAction extends CompareAction {
29
30
	private Shell shell;
31
	private ISelection fSelection;
32
	private IWorkbenchPart fWorkbenchPart;
33
34
	public CompareWithOtherResourceAction() {
35
		shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
36
	}
37
23
38
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
24
	public void run(ISelection selection) {
39
		fWorkbenchPart = targetPart;
25
		selectAncestor = false;
26
		super.run(selection);
40
	}
27
	}
41
28
42
	public void run(IAction action) {
29
	protected boolean isEnabled(ISelection selection) {
43
		CompareWithOtherResourceDialog dialog = new CompareWithOtherResourceDialog(shell, fSelection);
30
		if (fInput == null) {
44
		int returnCode = dialog.open();
31
			CompareConfiguration cc= new CompareConfiguration();
45
32
			cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(false));
46
		if (returnCode == IDialogConstants.OK_ID) {
33
			fInput= new ResourceCompareInput(cc);
47
			IResource[] resources = dialog.getResult();
48
			StructuredSelection ss = new StructuredSelection(resources);
49
			CompareAction ca = new CompareAction();
50
			ca.setActivePart(null, fWorkbenchPart);
51
			if (ca.isEnabled(ss))
52
				ca.run(ss);
53
		}
34
		}
54
	}
35
		return true;
55
56
	public void selectionChanged(IAction action, ISelection selection) {
57
		fSelection = selection;
58
	}
36
	}
59
37
60
}
38
}
(-)compare/org/eclipse/compare/internal/CompareMessages.properties (-2 / +3 lines)
Lines 128-132 Link Here
128
CompareWithOther_dialogMessage=Select resources to compare
128
CompareWithOther_dialogMessage=Select resources to compare
129
CompareWithOther_error_not_comparable=Selected resources are not comparable.
129
CompareWithOther_error_not_comparable=Selected resources are not comparable.
130
CompareWithOther_error_empty=Both left and right panel must contain a valid path.
130
CompareWithOther_error_empty=Both left and right panel must contain a valid path.
131
CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed. 
131
CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed.
132
CompareWithOther_clear=Clear
132
CompareWithOther_clear=Clear
133
CompareWithOther_info=Drag files from Package Explorer or from another field within the dialog.
(-)compare/org/eclipse/compare/internal/CompareAction.java (-5 / +6 lines)
Lines 26-41 Link Here
26
 */
26
 */
27
public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
27
public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
28
28
29
	private ResourceCompareInput fInput;
29
	protected ResourceCompareInput fInput;
30
	private IWorkbenchPage fWorkbenchPage;
30
	protected IWorkbenchPage fWorkbenchPage;
31
31
	protected boolean selectAncestor = true;
32
32
33
	public void run(ISelection selection) {
33
	public void run(ISelection selection) {
34
		boolean ok;
34
		if (fInput != null) {
35
		if (fInput != null) {
35
			// Pass the shell so setSelection can prompt the user for which
36
			// Pass the shell so setSelection can prompt the user for which
36
			// resource should be the ancestor
37
			// resource should be the ancestor
37
			boolean ok = fInput.setSelection(selection,
38
			ok = fInput.setSelection(selection,
38
				fWorkbenchPage.getWorkbenchWindow().getShell());
39
					fWorkbenchPage.getWorkbenchWindow().getShell(), selectAncestor);
39
			if (!ok) return;
40
			if (!ok) return;
40
			fInput.initializeCompareConfiguration();
41
			fInput.initializeCompareConfiguration();
41
			CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
42
			CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
(-)compare/org/eclipse/compare/internal/ResourceCompareInput.java (-3 / +37 lines)
Lines 200-207 Link Here
200
	// If the compare is three-way, this method asks the user which resource
200
	// If the compare is three-way, this method asks the user which resource
201
	// to use as the ancestor.  Returns false if the user cancels the prompt,
201
	// to use as the ancestor.  Returns false if the user cancels the prompt,
202
	// true otherwise.
202
	// true otherwise.
203
	boolean setSelection(ISelection s, Shell shell) {
203
	boolean setSelection(ISelection s, Shell shell, boolean selectAncestor) {
204
		
204
205
		if (!selectAncestor)
206
			return showDialog(shell, s);
207
205
		IResource[] selection= Utilities.getResources(s);
208
		IResource[] selection= Utilities.getResources(s);
206
209
207
		fThreeWay= selection.length == 3;
210
		fThreeWay= selection.length == 3;
Lines 223-234 Link Here
223
			fLeftResource= selection[0];
226
			fLeftResource= selection[0];
224
			fRightResource= selection[1];
227
			fRightResource= selection[1];
225
		}
228
		}
229
		fLeft= getStructure(fLeftResource);
230
		fRight= getStructure(fRightResource);
231
		return true;
232
	}
233
234
	private boolean showDialog(Shell shell, ISelection s) {
235
		CompareWithOtherResourceDialog dialog = new CompareWithOtherResourceDialog(shell, s);
236
		if (dialog.open() != IDialogConstants.OK_ID)
237
			return false;
238
		IResource[] selection = dialog.getResult();
239
		if (!resourcesOK(selection))
240
			return false;
226
241
242
		fThreeWay = selection.length == 3;
243
		if (fThreeWay) {
244
			fAncestorResource = selection[0];
245
			fAncestor = getStructure(fAncestorResource);
246
			fLeftResource = selection[1];
247
			fRightResource = selection[2];
248
		} else {
249
			fAncestorResource = null;
250
			fAncestor = null;
251
			fLeftResource = selection[0];
252
			fRightResource = selection[1];
253
		}
227
		fLeft= getStructure(fLeftResource);
254
		fLeft= getStructure(fLeftResource);
228
		fRight= getStructure(fRightResource);
255
		fRight= getStructure(fRightResource);
229
		return true;
256
		return true;
230
	}
257
	}
231
	
258
259
	private boolean resourcesOK(IResource[] resources) {
260
		for (int i = 0; i < resources.length; i++)
261
			if (resources[i] == null)
262
				return false;
263
		return true;
264
	}
265
232
	/*
266
	/*
233
	 * Returns true if compare can be executed for the given selection.
267
	 * Returns true if compare can be executed for the given selection.
234
	 */
268
	 */

Return to bug 239959