Bug 97990 CVS should update editor determination for remote files
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
index ba4876a..8ffc092 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
@@ -11,6 +11,8 @@
 
 package org.eclipse.team.internal.ccvs.ui;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.*;
@@ -18,6 +20,7 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceStatus;
 import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.jface.dialogs.*;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.preference.IPreferenceStore;
@@ -650,4 +653,49 @@
 	public CVSOutputConsole getConsole() {
 		return console;
 	}
+    
+    public void openEditor(ICVSRemoteFile file, IProgressMonitor monitor) throws InvocationTargetException {
+        IWorkbench workbench = getWorkbench();
+        IEditorRegistry registry = workbench.getEditorRegistry();
+        IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
+        String filename = file.getName();
+        InputStream contents = null;
+        try {
+            contents = file.getContents(monitor);
+        } catch (TeamException e) {
+            CVSUIPlugin.log(new CVSStatus(IStatus.ERROR, NLS.bind("An error occurred fetching the contents of file {0}", new String[] { file.getRepositoryRelativePath()}, e))); //$NON-NLS-1$
+
+        }
+        IContentType type = null;
+        if (contents != null) {
+            try {
+                type = Platform.getContentTypeManager().findContentTypeFor(contents, filename);
+            } catch (IOException e) {
+                CVSUIPlugin.log(new CVSStatus(IStatus.ERROR, NLS.bind("An error occurred reading the contents of file {0}", new String[] { file.getRepositoryRelativePath()}, e))); //$NON-NLS-1$
+            }
+        }
+        if (type == null) {
+            type = Platform.getContentTypeManager().findContentTypeFor(filename);
+        }
+        IEditorDescriptor descriptor = registry.getDefaultEditor(filename, type);
+        String id;
+        if (descriptor == null) {
+            id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
+        } else {
+            id = descriptor.getId();
+        }
+        try {
+            try {
+                page.openEditor(new RemoteFileEditorInput(file, monitor), id);
+            } catch (PartInitException e) {
+                if (id.equals("org.eclipse.ui.DefaultTextEditor")) { //$NON-NLS-1$
+                    throw e;
+                } else {
+                    page.openEditor(new RemoteFileEditorInput(file, monitor), "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
+                }
+            }
+        } catch (PartInitException e) {
+            throw new InvocationTargetException(e);
+        }
+    }
 }
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenLogEntryAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenLogEntryAction.java
index 14746e6..0b61f90 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenLogEntryAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenLogEntryAction.java
@@ -22,8 +22,8 @@
 import org.eclipse.team.core.TeamException;
 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
 import org.eclipse.team.internal.ccvs.core.ILogEntry;
-import org.eclipse.team.internal.ccvs.ui.*;
-import org.eclipse.ui.*;
+import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
+import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
 
 public class OpenLogEntryAction extends CVSAction {
 	/**
@@ -63,36 +63,13 @@
 	public void execute(IAction action) throws InterruptedException, InvocationTargetException {
 		run(new IRunnableWithProgress() {
 			public void run(IProgressMonitor monitor) throws InvocationTargetException {
-				IWorkbench workbench = CVSUIPlugin.getPlugin().getWorkbench();
-				IEditorRegistry registry = workbench.getEditorRegistry();
-				IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
 				final ILogEntry[] entries = getSelectedLogEntries();
 				for (int i = 0; i < entries.length; i++) {
 					if (entries[i].isDeletion()) {
 						MessageDialog.openError(getShell(), CVSUIMessages.OpenLogEntryAction_deletedTitle, CVSUIMessages.OpenLogEntryAction_deleted); //$NON-NLS-1$ //$NON-NLS-2$
 					} else {
 						ICVSRemoteFile file = entries[i].getRemoteFile();
-						String filename = file.getName();
-						IEditorDescriptor descriptor = registry.getDefaultEditor(filename);
-						String id;
-						if (descriptor == null) {
-							id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
-						} else {
-							id = descriptor.getId();
-						}
-						try {
-							try {
-								page.openEditor(new RemoteFileEditorInput(file, monitor), id);
-							} catch (PartInitException e) {
-								if (id.equals("org.eclipse.ui.DefaultTextEditor")) { //$NON-NLS-1$
-									throw e;
-								} else {
-									page.openEditor(new RemoteFileEditorInput(file, monitor), "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
-								}
-							}
-						} catch (PartInitException e) {
-							throw new InvocationTargetException(e);
-						}
+                        CVSUIPlugin.getPlugin().openEditor(file, monitor);
 					}
 				}
 			}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenRemoteFileAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenRemoteFileAction.java
index 25cc3a5..53b944e 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenRemoteFileAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/OpenRemoteFileAction.java
@@ -22,8 +22,6 @@
 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
 import org.eclipse.team.internal.ccvs.core.ILogEntry;
 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
-import org.eclipse.team.internal.ccvs.ui.RemoteFileEditorInput;
-import org.eclipse.ui.*;
 
 public class OpenRemoteFileAction extends CVSAction {
 	/**
@@ -67,33 +65,10 @@
 	public void execute(IAction action) throws InterruptedException, InvocationTargetException {
 		run(new IRunnableWithProgress() {
 			public void run(IProgressMonitor monitor) throws InvocationTargetException {
-				IWorkbench workbench = CVSUIPlugin.getPlugin().getWorkbench();
-				IEditorRegistry registry = workbench.getEditorRegistry();
-				IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
 				ICVSRemoteFile[] files = getSelectedRemoteFiles();
 				for (int i = 0; i < files.length; i++) {
 					ICVSRemoteFile file = files[i];
-					String filename = file.getName();
-					IEditorDescriptor descriptor = registry.getDefaultEditor(filename);
-					String id;
-					if (descriptor == null) {
-						id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
-					} else {
-						id = descriptor.getId();
-					}
-					try {
-						try {
-							page.openEditor(new RemoteFileEditorInput(files[i], monitor), id);
-						} catch (PartInitException e) {
-							if (id.equals("org.eclipse.ui.DefaultTextEditor")) { //$NON-NLS-1$
-								throw e;
-							} else {
-								page.openEditor(new RemoteFileEditorInput(files[i], monitor), "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
-							}
-						}
-					} catch (PartInitException e) {
-						throw new InvocationTargetException(e);
-					}
+					CVSUIPlugin.getPlugin().openEditor(file, monitor);
 				}
 			}
 		}, false, PROGRESS_BUSYCURSOR); //$NON-NLS-1$