Snippet: Open Editor a Local File in Eclipse

Here is codes to open editor a local file in Eclipse:

IFileStore fileStore = EFS.getLocalFileSystem()
.getStore(new Path(file.getParent()));
fileStore= fileStore.getChild(file.getName());
if (!fileStore.fetchInfo().isDirectory()
&& fileStore.fetchInfo().exists()) {
IWorkbenchWindow fWindow = Java2ScriptUIPlugin.getDefault()
.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = fWindow.getActivePage();
try {
IDE.openEditorOnFileStore(page, fileStore);
} catch (PartInitException e) {
String msg = NLS.bind(IDEWorkbenchMessages
.OpenLocalFileAction_message_errorOnOpen,
fileStore.getName());
IDEWorkbenchPlugin.log(msg,e.getStatus());
MessageDialog.openError(fWindow.getShell(),
IDEWorkbenchMessages.OpenLocalFileAction_title, msg);
}
}

For more, please read org.eclipse.ui.internal.ide.actions.OpenLocalFileAction in org.eclipse.ui.ide_….jar

This entry was posted in Eclipse, Snippet. Bookmark the permalink.

Comments are closed.