1 11 package org.eclipse.team.internal.ui.history; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 16 import org.eclipse.core.resources.IFileState; 17 import org.eclipse.core.runtime.Platform; 18 import org.eclipse.core.runtime.content.IContentType; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.team.internal.ui.TeamUIMessages; 22 import org.eclipse.team.internal.ui.TeamUIPlugin; 23 import org.eclipse.ui.*; 24 import org.eclipse.ui.actions.BaseSelectionListenerAction; 25 26 public class OpenLocalFileAction extends BaseSelectionListenerAction { 27 28 protected OpenLocalFileAction(String text) { 29 super(text); 30 } 31 32 public void run() { 33 try { 34 IStructuredSelection structSel = getStructuredSelection(); 35 36 Object [] objArray = structSel.toArray(); 37 38 for (int i = 0; i < objArray.length; i++) { 39 IFileState state = (IFileState) objArray[i]; 40 if (!state.exists()) { 41 MessageDialog.openError(TeamUIPlugin.getActivePage().getActivePart().getSite().getShell(), TeamUIMessages.OpenRevisionAction_DeletedRevisionTitle, TeamUIMessages.OpenRevisionAction_DeletedRevisionMessage); 42 } else { 43 String id = getEditorID(state.getName(), state.getContents()); 44 IWorkbenchPage page = TeamUIPlugin.getActivePage(); 45 if (page != null) { 46 page.openEditor(new FileRevisionEditorInput(state), id); 47 } 48 } 49 50 } 51 52 } catch (Exception e) { 53 54 } 55 } 56 57 String getEditorID(String fileName, InputStream contents) { 58 IWorkbench workbench = TeamUIPlugin.getPlugin().getWorkbench(); 59 IEditorRegistry registry = workbench.getEditorRegistry(); 60 61 IContentType type = null; 62 if (contents != null) { 63 try { 64 type = Platform.getContentTypeManager().findContentTypeFor(contents, fileName); 65 } catch (IOException e) { 66 67 } 68 } 69 if (type == null) { 70 type = Platform.getContentTypeManager().findContentTypeFor(fileName); 71 } 72 IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type); 73 String id; 74 if (descriptor == null) { 75 id = "org.eclipse.ui.DefaultTextEditor"; } else { 77 id = descriptor.getId(); 78 } 79 80 return id; 81 } 82 83 } 84 | Popular Tags |