Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » why "FileEditorInput" not found?
why "FileEditorInput" not found? [message #526793] Mon, 12 April 2010 22:40 Go to next message
Yuzhang Han is currently offline Yuzhang HanFriend
Messages: 19
Registered: September 2009
Junior Member
Hi everybody,
I'm trying to open the default editor for a certain file programmatically (not a fresh issue) and stunned by a problem which is never encountered in any old posts related to this issue: the "FileEditorInput" class is not found. Is any one so kind to tell me where it went wrong? Perhaps which plugins I still lack? Many thanks...


My code is pasted as follows. FIY, I'm using Eclipse 3.5.2 - Modelling, and additionally installed feature org.eclilpse.platform v3.5.2 from "software update".

File file = new File(filename);
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IWorkbenchPage page = window.getActivePage();
		IEditorDescriptor desc = PlatformUI.getWorkbench().
		        getEditorRegistry().getDefaultEditor(file.getName());
		try {
			page.openEditor(new FileEditorInput(file), desc.getId()); //if I replaced "FileEditorInput" instance with "NullEditorInput", it would work correctly: an editor opened saying there is an exception because of the lack of an input file
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

[Updated on: Mon, 12 April 2010 22:45]

Report message to a moderator

Re: why "FileEditorInput" not found? [message #526851 is a reply to message #526793] Tue, 13 April 2010 09:24 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 13/04/10 4:10 AM, Yuzhang Han wrote:
> Hi everybody,
> I'm trying to open the default editor for a certain file
> programmatically (not a fresh issue) and stunned by a problem which is
> never encountered in any old posts related to this issue: the
> "FileEditorInput" class is not found. Is any one so kind to tell me
> where it went wrong? Perhaps which plugins I still lack?

You need o.e.ui.ide in your dependencies

- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: why "FileEditorInput" not found? [message #526867 is a reply to message #526793] Tue, 13 April 2010 11:10 Go to previous message
Yuzhang Han is currently offline Yuzhang HanFriend
Messages: 19
Registered: September 2009
Junior Member
Thanks very much, it got solved following your words. Pasted below is a working and simpler version, all aiming at programmatically opening an external file with type-default editor. (Originally found in eclipse.org - FAQ)
//precondition is org.eclipse.ui.ide plugin should be in dependencies
import java.io.File;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
... ...
... ...
private void openExternalFile(String filename) {
		
		File fileToOpen = new File(filename);
		 
		if (fileToOpen.exists() && fileToOpen.isFile()) {
		    IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
		    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		 
		    try {
		        IDE.openEditorOnFileStore( page, fileStore );
		    } catch ( PartInitException e ) {
		    	e.printStackTrace();
		    }
		} else {
			System.err.println("File " + filename + " does not exist.");
		}
	}
Previous Topic:Runtime.getRuntime().exec() returns exit code 127 on Ubuntu Linux
Next Topic:[UA] Help Runtime Testing
Goto Forum:
  


Current Time: Tue Apr 16 19:32:27 GMT 2024

Powered by FUDForum. Page generated in 1.44297 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top