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] |
Thu, 08 July 2010 00:06 |
|
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.
--Mark Storer
Senior Software Engineer
Autonomy Cardiff
import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;
Google Code Search
|
|
|
Re: Can't create an IFile within my plugin directory? [message #545501 is a reply to message #545482] |
Thu, 08 July 2010 05:33 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
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 #545714 is a reply to message #545482] |
Thu, 08 July 2010 17:52 |
|
Why an IFile?
I'm going to open it in an editor, and I'm not sure at the time which one will be used. I'm using a FileEditorInput which gets passed to IDE.getEditorDescriptor. I cast that descriptor to internal.EditorDescriptor (I know, I know), and I call it's createEdtior() from there. This creates whichever editor for my file (a .js in this particular case) Eclipse would normally create, one that I can use as a tab in my FormEditor-derived class.
That and one would think that myWorkspaceRoot.getFile(...).create(...) would work for some reasonable-seeming set of parameters, particularly on an IPath handed to me by an Eclipse call.
PS: Eclipse Dev Types: createEditor is really handy for building editors to be used in tabs. I'd like to see it moved to the public interface so I can get rid of this nagging "you're using an internal class" warning.
Hmm... perhaps a FileStoreEditorInput? I'm still pretty new to Eclipse plugin programming. To be honest, what I REALLY want is something like a ByteArrayEditorInput. Hopefully they added one in 3.6... I haven't had the chance to check yet...
Doesn't look that way.
Hmm... IStorage looks trivial to implement for a byte array. IStorageEditorInput.
Now we're talking... I don't see a way to write to an IStorage, so some editors might choke... one way to find out.
--Mark Storer
Senior Software Engineer
Autonomy Cardiff
import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;
Google Code Search
|
|
| |
Re: Can't create an IFile within my plugin directory? [message #545954 is a reply to message #545781] |
Fri, 09 July 2010 17:10 |
|
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)
--Mark Storer
Senior Software Engineer
Autonomy Cardiff
import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;
Google Code Search
|
|
|
Re: Can't create an IFile within my plugin directory? [message #546037 is a reply to message #545954] |
Sat, 10 July 2010 07:59 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
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 #546457 is a reply to message #546037] |
Mon, 12 July 2010 21:08 |
|
I think I figured out the problem.
IPath pluginStatePath = MyPlugin.getDefault().getStateLocation();
This returns an ABSOLUTE path. Resource.getResourceInfo() is expecting to be a relative path at that point.
So it looks for "/Users/mark storer/workspace/.metadata" under the workspace folder, and fails just as you'd expect.
I fixed a similar problem moments ago thusly:
IPath myPath = new Path(myPathStr);
myPath= myPath.makeRelativeTo(ResourcesPlugin.getWorkspace().getRoot().getLocation());
Nope... Eclipse doesn't load a phony IProject for ".metadata"... at least not in 3.5. Odd, it does load a ".project" under each project. Humph.
--Mark Storer
Senior Software Engineer
Autonomy Cardiff
import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;
Google Code Search
|
|
| |
Re: Can't create an IFile within my plugin directory? [message #548096 is a reply to message #547893] |
Tue, 20 July 2010 16:10 |
|
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.
--Mark Storer
Senior Software Engineer
Autonomy Cardiff
import legalese.disclaimer;
Disclaimer<Cardiff> disCard = null;
Google Code Search
|
|
|
Goto Forum:
Current Time: Thu Apr 25 17:45:45 GMT 2024
Powered by FUDForum. Page generated in 0.03427 seconds
|