Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » how to get IFolder of this plugin?
how to get IFolder of this plugin? [message #305030] Wed, 21 June 2006 17:06 Go to next message
Eclipse User
Originally posted by: romich_n.mail.ru

How can I get the IFolder of the plugin that is currently running (my
plugin)?
Basically what I want to do is access several files and folders in
Templates folder under my plugin and copy them over to the new project.

Thanks
Re: how to get IFolder of this plugin? [message #305033 is a reply to message #305030] Wed, 21 June 2006 17:37 Go to previous messageGo to next message
Eclipse User
Originally posted by: automatic.javalobby.org

Plugins don't have IFolders; only projects in the workspace do. You should access resources via the Bundle.getEntry(/path/to/resource) or Class.getResourceAsStream(/path/to/resource) -- preferably the latter, if you're just coping the data out as a template, becuase then it's a fairly simple read/write copy, and secondly it's more efficient than the Bundle.getEntry() way in the scenario where the plugin is packed.

Alex.
Re: how to get IFolder of this plugin? [message #305035 is a reply to message #305033] Wed, 21 June 2006 18:05 Go to previous messageGo to next message
Eclipse User
Originally posted by: romich_n.mail.ru

will any of the above allow me to navigate folder structure inside the
plugin?
Lets say I have a folder Templates in my plugin and in this folder I have
some folder structure. Is it posible to duplicate this folder structure in
the new project?

Thanks again
Re: how to get IFolder of this plugin? [message #305038 is a reply to message #305035] Wed, 21 June 2006 20:02 Go to previous messageGo to next message
Eclipse User
Originally posted by: automatic.javalobby.org

You could probably enumerate through the entries via Bundle.getEntry. You can't do the same with Class.getResource() though as you'll need to know the name of the resource you're looking up. But as long as you know how to read the folder structure, then you can easily process it. For example, you could have the folder structure in a plain text file and use that to create directories, or (even better) compress your templates into a Zip file (say template.zip) and then use the Java APIs to extract the contents of that Zip file into your new project location.

Alex.
Re: how to get IFolder of this plugin? [message #305039 is a reply to message #305038] Wed, 21 June 2006 20:50 Go to previous messageGo to next message
Eclipse User
Originally posted by: romich_n.mail.ru

Thank, I think I'll stick to the folder structure in the text file, seems
simple enough.
Thanks again
Roman
Re: how to get IFolder of this plugin? [message #305041 is a reply to message #305039] Wed, 21 June 2006 21:33 Go to previous message
Eclipse User
Originally posted by: automatic.javalobby.org

If you change your mind, then this should do the trick for a zip/jar file:

zis = new ZipInputStream(MyPlugin.class.getResourceAsStream("template.zip"));
while(zis.available() > 0) {
  entry = zis.getNextEntry();
  if (entry.isDirectory()) 
    // make directory
  else {
    size = entry.getSize();
    buffer = new byte[size];
    zis.read(buffer,0,size)
  }
}


http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipInp utStream.html

Not that difficult to get going, but I may have made a few mistakes in my pseudo code above.

Alex.
Previous Topic:Universal Welcome
Next Topic:What happens when user do a left-mouse click on Text Editor
Goto Forum:
  


Current Time: Tue Sep 16 03:04:44 GMT 2014

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

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