Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Creating files based on templates
Creating files based on templates [message #1169555] Mon, 04 November 2013 03:42 Go to next message
Eli B is currently offline Eli BFriend
Messages: 4
Registered: November 2013
Junior Member
So I'm a Java developer, taking a stab at developing an eclipse plugin for the first time. I have a basic new project wizard running. Now say I want it to generate a couple files for me on performFinish with some default text, can someone point in the right direction for how to do that? I can't imagine the right approach would be to store the text in a file and use the File API to read it in, is it?
Re: Creating files based on templates [message #1171732 is a reply to message #1169555] Tue, 05 November 2013 12:46 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

You could also have your plugin defining a preference with the default
value for the template text and create an IFile containing that text on
performFinish. That has the advantage that by providing the preferences
UI, you'll leave the opportunity to your user to override the default text.
--
Mickael Istria
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Re: Creating files based on templates [message #1172137 is a reply to message #1171732] Tue, 05 November 2013 18:29 Go to previous messageGo to next message
Eli B is currently offline Eli BFriend
Messages: 4
Registered: November 2013
Junior Member
I'm not sure that's quite what I'm after, yet. Maybe it will help if I'm more specific. This plug-in is for a Domain Specific Language. So, on performFinish for the new project wizard, amongst other things, I want it to create a file with a sample DSL app in it with say 10 lines of code. Where do I store this 10 lines of code?

I'd imagine that it should go in some kind of separate template file, say dslHelloWorld.template. But, how do I bundle this with my plug-in so that the custom new project wizard knows about it and can put this template file in with the new project?
Re: Creating files based on templates [message #1173625 is a reply to message #1172137] Wed, 06 November 2013 16:53 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

On 11/05/2013 07:29 PM, Ilya B wrote:
> Where do I store this 10 lines of code?

Where you want: as a static string, as a resource file in the bundle, as
a preference value, somewhere over HTTP... It really depends on your
constraints/wishes.

> I'd imagine that it should go in some kind of separate template file,
> say dslHelloWorld.template. But, how do I bundle this with my plug-in so
> that the custom new project wizard knows about it and can put this
> template file in with the new project?

Anyway, you'll need to write the code that create the IFile with the
given content in the performFinish method. There is no automatic
behaviour to create a file at the end of a wizard.
When it comes to getting content, assuming you've created this file as a
resource in your bundle, the right way to do it is to use
getClass().getResourceAsStream("/myTemplateFile") if the resource is
available in your classloader.

HTH
--
Mickael Istria
My job: http://www.jboss.org/tools
My blog: http://mickaelistria.wordpress.com
My Tweets: http://twitter.com/mickaelistria
Re: Creating files based on templates [message #1173655 is a reply to message #1173625] Wed, 06 November 2013 17:17 Go to previous messageGo to next message
Eli B is currently offline Eli BFriend
Messages: 4
Registered: November 2013
Junior Member
> as a resource file in the bundle

This is the part I don't understand. How do I bundle resource files with my plugin?
Re: Creating files based on templates [message #1180559 is a reply to message #1169555] Mon, 11 November 2013 03:02 Go to previous message
Eli B is currently offline Eli BFriend
Messages: 4
Registered: November 2013
Junior Member
Am I overthinking this? Do I simply include a file with the plug-in project and read from it to accomplish the goal of having a template?
Previous Topic: required Bundle org.eclipse.help.appserver could not be found
Next Topic:Cannot resolve target platform due to javax.crypto
Goto Forum:
  


Current Time: Fri Apr 19 00:39:42 GMT 2024

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

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

Back to the top