Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » [JSDT] Opening a javascript file that is outside the workspace
[JSDT] Opening a javascript file that is outside the workspace [message #225771] Mon, 29 December 2008 10:41 Go to next message
Eclipse User
Originally posted by: eclipse.ehrnhoefer.net

In a previous thread I wondered about how to programmatically open the
JSDT in my own RCP application (without the whole webtools).

I finally managed that, adding a whole bunch of plugins (especially
org.eclipse.core.filebuffers, .variables, and io.views.properties.tabbed
were hard to find, cause the PDE did not tell me I need them).

So the snippet I came up with is:

----%<----%<----%<----%<
IWorkspace ws = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root= ws.getRoot();
IPath tmp = new Path(sourcefile.getAbsolutePath());
IFile file = root.getFile(tmp );
if (file != null)
{
IJavaScriptUnit jsUnit = JavaScriptCore.createCompilationUnitFrom(
file );
try
{
JavaScriptUI.openInEditor( jsUnit );
}
catch (PartInitException e)
{
System.out.println(e.getMessage());
}
catch (JavaScriptModelException e)
{
System.out.println(e.getMessage());
}
}
----%<----%<----%<----%<

Problem here is, that the IFile contains something like
"L/myPath/myFile.js". No idea what the L means, but trying to open it
results in an IllegalArgumentException.

In the newsgroups I found somebody with a similar problem, regarding the
Java editor. The solution that worked for him in the end was rewriting the
IEditorInput for his own needs, which should be easy.
Although in the JS editor's case: there is no (public) EditorInput, there
is only the IJavaScriptUnit.

But to create a IJavaScriptUnit, I need an IFile, and for that I think the
file needs to be in the workspace? Problem is, in our current design, we
do not use the concept of workspaces at all, so the root is "\" and no
projects are in the workspace.


Does anybody have an idea how to solve this (without big redesigning),
even a quick&dirty fix would be good for now?

Thanks a lot
Thomas
Re: [JSDT] Opening a javascript file that is outside the workspace [message #226067 is a reply to message #225771] Tue, 06 January 2009 17:21 Go to previous message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2133
Registered: July 2009
Senior Member
Thomas Ehrnhoefer wrote:
> In a previous thread I wondered about how to programmatically open the
> JSDT in my own RCP application (without the whole webtools).

Yes, IFiles only exist in the workspace and the JavaScript support
is largely built around use of the workspace. You can still open
external files in the editor, but you'll probably want to use
org.eclipse.ui.ide.IDE.openEditorOnFileStore(IWorkbenchPage,
IFileStore), with a filestore from
org.eclipse.core.filesystem.EFS.getLocalFileSystem().fromLoc alFile(java.io.File))
..

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:Running a web app directly from the project directory
Next Topic:Problem with JUnit testing on XML Editor Plugin
Goto Forum:
  


Current Time: Sun Apr 20 18:03:22 EDT 2014

Powered by FUDForum. Page generated in 0.01657 seconds