Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

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 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
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 Go to previous messageGo to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

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 #545781 is a reply to message #545714] Fri, 09 July 2010 06:36 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Mark Storer wrote:
> 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.
Just use org.eclipse.ui.ide.IDE.openEditorOnFileStore(IWorkbenchPage,
IFileStore) where the file store points to the temp file.

Dani
Re: Can't create an IFile within my plugin directory? [message #545954 is a reply to message #545781] Fri, 09 July 2010 17:10 Go to previous messageGo to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

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 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
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 Go to previous messageGo to next message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

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 #547893 is a reply to message #546457] Tue, 20 July 2010 06:27 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
"Mark Storer" <mstorer3772@gmail.com> wrote in message
news:i1g08n$nfs$1@build.eclipse.org...
>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.


Not every file or directory is an IResource; only those that are contained
within projects. In particular, files within the plugins directory are not
IResources, they're just files.

..project is the name of the file (in each project) that stores the project
configuration. It's a text file; you can open it up if you view the project
in the Navigator view, which shows an unfiltered filesystem view of the
project.
Re: Can't create an IFile within my plugin directory? [message #548096 is a reply to message #547893] Tue, 20 July 2010 16:10 Go to previous message
Mark Storer is currently offline Mark StorerFriend
Messages: 46
Registered: May 2010
Location: Vista, CA
Member

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
Previous Topic:core tools does not work with eclipse 3.6
Next Topic:Where do all those "trace" check boxes come from when debugging a plugin?
Goto Forum:
  


Current Time: Tue Apr 23 15:59:30 GMT 2024

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

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

Back to the top