Home » Eclipse Projects » Eclipse Platform » Can't create an IFile within my plugin directory?
Can't create an IFile within my plugin directory? [message #545482] |
Wed, 07 July 2010 20:06  |
Eclipse User |
|
|
|
Here's my code (more or less), running in Eclipse 3.5.
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IPath pluginStatePath = MyPlugin.getDefault().getStateLocation();
IPath tempPath = pluginStatePath.append("tempFile" + count++ ).addFileExtension( someExtension );
IFile tempFile = root.getFile(tempPath);
tempFile.create(...);
Now, when you call getStateLocation(), Eclipse is kind enough to create the folder for you (with mkdirs()). It exists. I stepped through the code to create the folder, and watched it appear in my Explorer window (I'm using windows 7).
But when I try to call tempFile.create(...), it always throws a CoreException stating that the parent folder doesn't exist.
"But it's already there!" I cry, and go stepping through more eclipse code. I end up in Workspace.getResourceInfo(), where "tree.includes(path)" fails, aint never heard of no .metadata folder.
Peachy.
So how do I convince IWorkspace to create an IFile for me?
Or, stepping back for a moment, how do I create a temporary IFile that I can use to show in an editor?
(whoops! Earthquake! Many miles away, shook us for 30-60 seconds... nothing fell.)
Good ol SoCal.
|
|
|
Re: Can't create an IFile within my plugin directory? [message #545501 is a reply to message #545482] |
Thu, 08 July 2010 01:33   |
Eclipse User |
|
|
|
Mark Storer wrote:
> Here's my code (more or less), running in Eclipse 3.5.
>
>
> IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
> IPath pluginStatePath = MyPlugin.getDefault().getStateLocation();
>
> IPath tempPath = pluginStatePath.append("tempFile" + count++
> ).addFileExtension( someExtension );
>
> IFile tempFile = root.getFile(tempPath);
>
> tempFile.create(...);
>
>
> Now, when you call getStateLocation(), Eclipse is kind enough to
> create the folder for you (with mkdirs()). It exists. I stepped
> through the code to create the folder, and watched it appear in my
> Explorer window (I'm using windows 7).
>
> But when I try to call tempFile.create(...), it always throws a
> CoreException stating that the parent folder doesn't exist.
>
> "But it's already there!" I cry, and go stepping through more eclipse
> code. I end up in Workspace.getResourceInfo(), where
> "tree.includes(path)" fails, aint never heard of no .metadata folder.
>
> Peachy.
>
> So how do I convince IWorkspace to create an IFile for me?
>
> Or, stepping back for a moment, how do I create a temporary IFile that
> I can use to show in an editor?
Why create an IFile and not a simple java.io.File?
Dani
>
> (whoops!
> http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/ci 10736069.php#details
> Many miles away, shook us for 30-60 seconds... nothing fell.)
>
> Good ol SoCal.
|
|
| | |
Re: Can't create an IFile within my plugin directory? [message #545954 is a reply to message #545781] |
Fri, 09 July 2010 13:10   |
Eclipse User |
|
|
|
Sadly, that won't work either. IDE.openEditor*'s all create and open a top-level editor.
I'm building a FormEditor-based editor, and want a JS editor within it (along with some custom form pages we've whipped up and an XML viewer) as a tab.
My addPage code looks like this:
EditorDescriptor desc = (EditorDescriptor) IDE
.getEditorDescriptor("foo.js");
if (desc != null) {
jsEditor = desc.createEditor();
addPage(SCRIPT_PAGE_IDX, jsEditor, jsInput);
} // else log an error
EditorDescriptor is the internal class (yeah, yeah) that implements IEditorDescriptor. Using it lets me whip up the same editor (createEditor()) that IDE would have built for the same extension, only in a tab. And I have to use IEditorInput because that's all addPage will take.
In theory, if our users don't have the JSDT installed, the could end up with a regular text editor, which is fine with me. In practice, our plugin requires that the JSDT be installed.
(and what's the difference between theory and practice? In theory, there's no difference between theory and practice)
|
|
|
Re: Can't create an IFile within my plugin directory? [message #546037 is a reply to message #545954] |
Sat, 10 July 2010 03:59   |
Eclipse User |
|
|
|
Mark Storer wrote:
> Sadly, that won't work either. IDE.openEditor*'s all create and open
> a top-level editor.
By all means, then look at the code there to figure out how the file
from the OS is opened. It's really not that hard ;-)
Dani
>
> I'm building a FormEditor-based editor, and want a JS editor within it
> (along with some custom form pages we've whipped up and an XML viewer)
> as a tab.
>
> My addPage code looks like this:
>
> EditorDescriptor desc = (EditorDescriptor) IDE
> .getEditorDescriptor("foo.js");
> if (desc != null) {
> jsEditor = desc.createEditor();
>
> addPage(SCRIPT_PAGE_IDX, jsEditor, jsInput);
> } // else log an error
>
>
> EditorDescriptor is the internal class (yeah, yeah) that implements
> IEditorDescriptor. Using it lets me whip up the same editor
> (createEditor()) that IDE would have built for the same extension,
> only in a tab. And I have to use IEditorInput because that's all
> addPage will take.
>
> In theory, if our users don't have the JSDT installed, the could end
> up with a regular text editor, which is fine with me. In practice,
> our plugin requires that the JSDT be installed.
>
> (and what's the difference between theory and practice? In theory,
> there's no difference between theory and practice)
|
|
| | |
Re: Can't create an IFile within my plugin directory? [message #548096 is a reply to message #547893] |
Tue, 20 July 2010 12:10  |
Eclipse User |
|
|
|
My initial understanding was that IPath and IResource were interchangeable, which lead to my confusion... on account of them being interchangeable only some of the time.
Having progressed a bit further up the learning curve I now Get It that IPaths are paths that can be relative or absolute. IResources are a ResourcesPlugin thing, and thus part of the IDE which may not be available for some apps... whereas IPath is a RT/Core/whatever-it-is thing, and thus Always There. And while there are various mechanisms to go back and forth, IResources are always associated with projects, with the exception of the workspace, which is just there to hang projects off of.
So just a bit of confusion on my part. Still bugs me... but clearly not A Bug.
|
|
|
Goto Forum:
Current Time: Tue Jul 22 18:28:06 EDT 2025
Powered by FUDForum. Page generated in 0.04327 seconds
|