/*******************************************************************************
 * Copyright (C) 2009, Stefan Lay <stefan.lay@sap.com>
 *
 * 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
 *******************************************************************************/
package org.eclipse.egit.ui.internal.actions;

import java.io.IOException;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.CompareUtils;
import org.eclipse.egit.ui.internal.dialogs.CompareTreeView;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

/**
 * Compares the working tree content of a file with the version of the file in
 * the HEAD commit.
 */
public class CompareWithHeadActionHandler extends RepositoryActionHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
		final Repository repository = getRepository(true, event);
		// assert all resources map to the same repository
		if (repository == null)
			return null;
		final IResource[] resources = getSelectedResources(event);

		if (resources.length == 1 && resources[0] instanceof IFile) {
			final IFile file = (IFile) resources[0];
			CompareUtils.compareHeadWithWorkspace(repository, file);
			return null;

		} else {
			CompareTreeView view;
			try {
				view = (CompareTreeView) PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getActivePage().showView(
								CompareTreeView.ID);
				try {
					view.setInput(resources, repository.resolve(Constants.HEAD)
							.name());
				} catch (IOException e) {
					Activator.handleError(e.getMessage(), e, true);
					return null;
				}
			} catch (PartInitException e) {
				Activator.handleError(e.getMessage(), e, true);
				return null;
			}
			return null;
		}
	}

	@Override
	public boolean isEnabled() {
		return getRepository() != null;
	}
}

@@ -536,16 +536,96 @@
 ption;%0A%0A
+import org.eclipse.compare.CompareUI;%0Aimport org.eclipse.compare.ITypedElement;%0A
 import o
@@ -661,24 +661,24 @@
 utionEvent;%0A
-
 import org.e
@@ -804,16 +804,72 @@
 source;%0A
+import org.eclipse.egit.core.project.RepositoryMapping;%0A
 import o
@@ -948,16 +948,87 @@
 eUtils;%0A
+import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;%0A
 import o
@@ -1119,16 +1119,49 @@
 stants;%0A
+import org.eclipse.jgit.lib.Ref;%0A
 import o
@@ -1192,16 +1192,167 @@
 sitory;%0A
+import org.eclipse.jgit.revwalk.RevCommit;%0Aimport org.eclipse.jgit.revwalk.RevWalk;%0Aimport org.eclipse.team.ui.synchronize.SaveableCompareEditorInput;%0A
 import o
@@ -1971,17 +1971,21 @@
 l IFile 
-f
+baseF
 ile = (I
@@ -2011,62 +2011,733 @@
 %0A%09%09%09
-CompareUtils.compareHeadWithWorkspace(repository, file
+final String gitPath = RepositoryMapping.getMapping(%0A%09%09%09%09%09baseFile.getProject()).getRepoRelativePath(baseFile);%0A%09%09%09final ITypedElement base = SaveableCompareEditorInput%0A%09%09%09%09%09.createFileElement(baseFile);%0A%0A%09%09%09ITypedElement next;%0A%09%09%09try %7B%0A%09%09%09%09Ref head = repository.getRef(Constants.HEAD);%0A%09%09%09%09RevWalk rw = new RevWalk(repository);%0A%09%09%09%09RevCommit commit = rw.parseCommit(head.getObjectId());%0A%0A%09%09%09%09next = CompareUtils.getFileRevisionTypedElement(gitPath,%0A%09%09%09%09%09%09commit, repository);%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09Activator.handleError(e.getMessage(), e, true);%0A%09%09%09%09return null;%0A%09%09%09%7D%0A%0A%09%09%09final GitCompareFileRevisionEditorInput in = new GitCompareFileRevisionEditorInput(%0A%09%09%09%09%09base, next, null);%0A%09%09%09CompareUI.openCompareEditor(in
 );%0A%09

Revert "Use CompareUtils.compareHeadWithWorkspace"