1 11 package org.eclipse.ui.actions; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.jface.util.OpenStrategy; 15 import org.eclipse.ui.IEditorDescriptor; 16 import org.eclipse.ui.IWorkbenchPage; 17 import org.eclipse.ui.PartInitException; 18 import org.eclipse.ui.PlatformUI; 19 import org.eclipse.ui.ide.IDE; 20 import org.eclipse.ui.internal.ide.DialogUtil; 21 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 22 import org.eclipse.ui.internal.ide.IIDEHelpContextIds; 23 import org.eclipse.ui.part.FileEditorInput; 24 25 36 public class OpenFileAction extends OpenSystemEditorAction { 37 38 41 public static final String ID = PlatformUI.PLUGIN_ID + ".OpenFileAction"; 43 46 private IEditorDescriptor editorDescriptor; 47 48 54 public OpenFileAction(IWorkbenchPage page) { 55 this(page, null); 56 } 57 58 65 public OpenFileAction(IWorkbenchPage page, IEditorDescriptor descriptor) { 66 super(page); 67 setText(descriptor == null ? IDEWorkbenchMessages.OpenFileAction_text : descriptor.getLabel()); 68 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 69 IIDEHelpContextIds.OPEN_FILE_ACTION); 70 setToolTipText(IDEWorkbenchMessages.OpenFileAction_toolTip); 71 setId(ID); 72 this.editorDescriptor = descriptor; 73 } 74 75 82 boolean ensureFileLocal(final IFile file) { 83 return true; 87 } 88 89 94 void openFile(IFile file) { 95 try { 96 boolean activate = OpenStrategy.activateOnOpen(); 97 if (editorDescriptor == null) { 98 IDE.openEditor(getWorkbenchPage(), file, activate); 99 } else { 100 if (ensureFileLocal(file)) { 101 getWorkbenchPage().openEditor(new FileEditorInput(file), 102 editorDescriptor.getId(), activate); 103 } 104 } 105 } catch (PartInitException e) { 106 DialogUtil.openError(getWorkbenchPage().getWorkbenchWindow() 107 .getShell(), IDEWorkbenchMessages.OpenFileAction_openFileShellTitle, 108 e.getMessage(), e); 109 } 110 } 111 112 } 113 | Popular Tags |