bug 239959: Adding content to "Compare with other resource" dialog by drag&dropping, patch #7
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java
index 839f003..01cd006 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareAction.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 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
@@ -8,17 +8,17 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource
+ *     Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959
  *******************************************************************************/
 package org.eclipse.compare.internal;
 
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareUI;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
-
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.CompareUI;
 
 
 /*
@@ -26,16 +26,16 @@
  */
 public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
 
-	private ResourceCompareInput fInput;
-	private IWorkbenchPage fWorkbenchPage;
-
+	protected ResourceCompareInput fInput;
+	protected IWorkbenchPage fWorkbenchPage;
+	protected boolean showSelectAncestorDialog = true;
 
 	public void run(ISelection selection) {
 		if (fInput != null) {
 			// Pass the shell so setSelection can prompt the user for which
 			// resource should be the ancestor
 			boolean ok = fInput.setSelection(selection,
-				fWorkbenchPage.getWorkbenchWindow().getShell());
+					fWorkbenchPage.getWorkbenchWindow().getShell(), showSelectAncestorDialog);
 			if (!ok) return;
 			fInput.initializeCompareConfiguration();
 			CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
index 919b64c..1a8ea13 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 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
@@ -8,6 +8,7 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource
+ *     Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959
  *******************************************************************************/
 package org.eclipse.compare.internal;
 
@@ -118,6 +119,7 @@
 	public static String CompareWithOther_error_empty;
 	public static String CompareWithOther_clear;
 	public static String CompareWithOther_warning_two_way;
+	public static String CompareWithOther_info;
 
 	static {
 		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
index 28804f0..ee8570e 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2007 IBM Corporation and others.
+# Copyright (c) 2000, 2008 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
@@ -8,6 +8,7 @@
 # Contributors:
 #     IBM Corporation - initial API and implementation
 #     Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource
+#     Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959
 ###############################################################################
 
 ComparePlugin_internal_error= Internal Error
@@ -128,5 +129,6 @@
 CompareWithOther_dialogMessage=Select resources to compare
 CompareWithOther_error_not_comparable=Selected resources are not comparable.
 CompareWithOther_error_empty=Both left and right panel must contain a valid path.
-CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed. 
-CompareWithOther_clear=Clear
\ No newline at end of file
+CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed.
+CompareWithOther_clear=Clear
+CompareWithOther_info=Drag files from a view or between dialog's fields.
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java
index 6782156..e0c74cf 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java
@@ -10,51 +10,26 @@
  *******************************************************************************/
 package org.eclipse.compare.internal;
 
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
 
 /**
  * The "Compare with other resource" action
  * 
  * @since 3.4
  */
-public class CompareWithOtherResourceAction implements IObjectActionDelegate {
+public class CompareWithOtherResourceAction extends CompareAction {
 
-	private Shell shell;
-	private ISelection fSelection;
-	private IWorkbenchPart fWorkbenchPart;
-
-	public CompareWithOtherResourceAction() {
-		shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+	public void run(ISelection selection) {
+		// Show CompareWithOtherResourceDialog which return resources to compare
+		// and ancestor if specified. Don't need to display the other dialog
+		showSelectAncestorDialog = false;
+		super.run(selection);
 	}
 
-	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
-		fWorkbenchPart = targetPart;
-	}
-
-	public void run(IAction action) {
-		CompareWithOtherResourceDialog dialog = new CompareWithOtherResourceDialog(shell, fSelection);
-		int returnCode = dialog.open();
-
-		if (returnCode == IDialogConstants.OK_ID) {
-			IResource[] resources = dialog.getResult();
-			StructuredSelection ss = new StructuredSelection(resources);
-			CompareAction ca = new CompareAction();
-			ca.setActivePart(null, fWorkbenchPart);
-			if (ca.isEnabled(ss))
-				ca.run(ss);
-		}
-	}
-
-	public void selectionChanged(IAction action, ISelection selection) {
-		fSelection = selection;
+	protected boolean isEnabled(ISelection selection) {
+		// ignore returned value
+		super.isEnabled(selection);
+		return true;
 	}
 
 }
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
index b404395..cdfea56 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
@@ -49,7 +49,7 @@
 
 /**
  * This is a dialog that can invoke the compare editor on chosen files.
- *
+ * 
  * @since 3.4
  */
 public class CompareWithOtherResourceDialog extends TitleAreaDialog {
@@ -166,7 +166,7 @@
 			createContents(parent);
 		}
 
-		public InternalSection() {
+		private InternalSection() {
 			// not to instantiate
 		}
 
@@ -337,7 +337,7 @@
 
 	/**
 	 * Creates the dialog.
-	 *
+	 * 
 	 * @param shell
 	 *            a shell
 	 * @param selection
@@ -353,7 +353,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 *
+	 * 
 	 * @see
 	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
 	 * .Composite)
@@ -389,7 +389,7 @@
 
 	/*
 	 * (non-Javadoc)
-	 *
+	 * 
 	 * @see
 	 * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
 	 * .swt.widgets.Composite)
@@ -398,6 +398,7 @@
 		super.createButtonsForButtonBar(parent);
 		okButton = getButton(IDialogConstants.OK_ID);
 		updateErrorInfo();
+		setMessage(CompareMessages.CompareWithOther_info);
 	}
 
 	private void setSelection(ISelection selection) {
@@ -419,7 +420,7 @@
 		}
 	}
 
-	private boolean comparePossible() {
+	private boolean isComparePossible() {
 		IResource[] resources;
 		if (ancestorPanel.getResource() == null) {
 			resources = new IResource[] { leftPanel.getResource(),
@@ -445,13 +446,13 @@
 					&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$
 				setMessage(CompareMessages.CompareWithOther_warning_two_way,
 						IMessageProvider.WARNING);
-			} else if (!comparePossible()) {
+			} else if (!isComparePossible()) {
 				setMessage(
 						CompareMessages.CompareWithOther_error_not_comparable,
 						IMessageProvider.ERROR);
 				okButton.setEnabled(false);
 			} else {
-				setMessage(null);
+				setMessage(CompareMessages.CompareWithOther_info);
 				okButton.setEnabled(true);
 			}
 		}
@@ -462,7 +463,7 @@
 	 * the ancestor panel, table has only two elements -- resources chosen in
 	 * left and right panel. In the other case table contains all three
 	 * resources.
-	 *
+	 * 
 	 * @return table with selected resources
 	 */
 	public IResource[] getResult() {
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
index fcacd04..1ab061f 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ResourceCompareInput.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 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
@@ -8,6 +8,7 @@
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *     Matt McCutchen (hashproduct+eclipse@gmail.com) - Bug 35390 Three-way compare cannot select (mis-selects) )ancestor resource
+ *     Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - Bug 239959
  *******************************************************************************/
 package org.eclipse.compare.internal;
 
@@ -196,12 +197,16 @@
 			}
 		};
 	}
-
 	// If the compare is three-way, this method asks the user which resource
-	// to use as the ancestor.  Returns false if the user cancels the prompt,
+	// to use as the ancestor. Depending on the value of
+	// showSelectAncestorDialog flag it uses different dialogs to get the
+	// feedback from the user. Returns false if the user cancels the prompt,
 	// true otherwise.
-	boolean setSelection(ISelection s, Shell shell) {
-		
+	boolean setSelection(ISelection s, Shell shell, boolean showSelectAncestorDialog) {
+
+		if (!showSelectAncestorDialog)
+			return showCompareWithOtherResourceDialog(shell, s);
+
 		IResource[] selection= Utilities.getResources(s);
 
 		fThreeWay= selection.length == 3;
@@ -223,12 +228,43 @@
 			fLeftResource= selection[0];
 			fRightResource= selection[1];
 		}
-
 		fLeft= getStructure(fLeftResource);
 		fRight= getStructure(fRightResource);
 		return true;
 	}
-	
+
+	private boolean showCompareWithOtherResourceDialog(Shell shell, ISelection s) {
+		CompareWithOtherResourceDialog dialog = new CompareWithOtherResourceDialog(shell, s);
+		if (dialog.open() != IDialogConstants.OK_ID)
+			return false;
+		IResource[] selection = dialog.getResult();
+		if (!checkSelection(selection))
+			return false;
+
+		fThreeWay = selection.length == 3;
+		if (fThreeWay) {
+			fAncestorResource = selection[0];
+			fAncestor = getStructure(fAncestorResource);
+			fLeftResource = selection[1];
+			fRightResource = selection[2];
+		} else {
+			fAncestorResource = null;
+			fAncestor = null;
+			fLeftResource = selection[0];
+			fRightResource = selection[1];
+		}
+		fLeft= getStructure(fLeftResource);
+		fRight= getStructure(fRightResource);
+		return true;
+	}
+
+	private boolean checkSelection(IResource[] resources) {
+		for (int i = 0; i < resources.length; i++)
+			if (resources[i] == null)
+				return false;
+		return true;
+	}
+
 	/*
 	 * Returns true if compare can be executed for the given selection.
 	 */