Fixed bug 186993: [History View] Show In > History does not work from
Java editor
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/EditionHistoryPage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/EditionHistoryPage.java
index 42d3d86..8146966 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/EditionHistoryPage.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/EditionHistoryPage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 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
@@ -39,9 +39,11 @@
  */
 public class EditionHistoryPage extends LocalHistoryPage {
 	
-	private final IFile file;
-	private final Object element;
-	private final LocalResourceTypedElement localFileElement;
+	private IFile file;
+
+	private Object element;
+
+	private LocalResourceTypedElement localFileElement;
 	private IStructureCreator structureCreator;
 	private Map editions = new HashMap();
 	private ITypedElement localEdition;
@@ -160,6 +162,10 @@
 	
 	public EditionHistoryPage(IFile file, Object element) {
 		super(ON | ALWAYS);
+		setInput(file, element);
+	}
+
+	void setInput(IFile file, Object element) {
 		Assert.isNotNull(file);
 		Assert.isNotNull(element);
 		this.file = file;
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/GenericHistoryView.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/GenericHistoryView.java
index 51f0020..1a21095 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/GenericHistoryView.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/GenericHistoryView.java
@@ -551,7 +551,15 @@
 			if (part instanceof HistoryPageSourceWorkbenchPart) {
 				HistoryPageSourceWorkbenchPart p = (HistoryPageSourceWorkbenchPart)part;
 				IHistoryPage historyPage = (IHistoryPage) rec.page;
-				historyPage.setInput(p.getObject());
+				Object newInput= p.getObject();
+				if (!historyPage.isValidInput(newInput)) {
+					if (historyPage instanceof EditionHistoryPage)
+						((EditionHistoryPage)historyPage).setInput(((ElementLocalHistoryPageSource)p.getSource()).internalGetFile(newInput), newInput);
+					else
+						return null; // Create a new page
+				} else
+					historyPage.setInput(newInput);
+
 				((HistoryPage)historyPage).setHistoryView(this);
 				setContentDescription(historyPage.getName());
 			}
@@ -672,6 +680,7 @@
 		if (page != null) {
 			initPage(page);
 			IHistoryPage historyPage = (IHistoryPage) page;
+			historyPage.addPropertyChangeListener(this);
 			historyPage.setSite(new WorkbenchHistoryPageSite(this, page.getSite()));
 			page.createControl(getPageBook());
 			historyPage.setInput(p.getObject());
@@ -684,6 +693,8 @@
 
 	protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
 		IPage page = pageRecord.page;
+		if (page instanceof IHistoryPage)
+			((IHistoryPage)page).removePropertyChangeListener(this);
 		page.dispose();
 		pageRecord.dispose();
 	}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/ElementLocalHistoryPageSource.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/ElementLocalHistoryPageSource.java
index fc76197..0ed7040 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/ElementLocalHistoryPageSource.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/ElementLocalHistoryPageSource.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2012 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
@@ -62,5 +62,17 @@
 	 * @return the file that contains the given element of <code>null</code>
 	 */
 	protected abstract IFile getFile(Object element);
+
+	/**
+	 * Return the file that contains the given element of <code>null</code> if this page source can
+	 * not show history for the given element.
+	 * 
+	 * @param element the element
+	 * @return the file that contains the given element of <code>null</code>
+	 * @noreference This method is not intended to be referenced by clients.
+	 */
+	final public IFile internalGetFile(Object element) {
+		return getFile(element);
+	}
 	
 }