Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Creating a custom class with a pre decided template(Eclipse Plugin Developement)
Creating a custom class with a pre decided template [message #1001470] Wed, 16 January 2013 19:26 Go to next message
Rajeev Mishra is currently offline Rajeev Mishra
Messages: 1
Registered: January 2013
Junior Member
Hi All,
I want to develop a new java file creation wizard which will create a new java file in the workspace using a predeclared template.

Please guide me.
Any code snippet or similar thread link will be most useful for me.

Thanks and regards
Re: Creating a custom class with a pre decided template [message #1001622 is a reply to message #1001470] Thu, 17 January 2013 04:22 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane Begaudeau
Messages: 406
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

Creating a brand new plug-in for that may be overkill. The Eclipse Java Development Tools already let you change the code generated while creating a new class. I've explained more about this on my blog (section 3.10) as part of a collection of articles on the JDT. You just need to configure the code templates for a new file in the properties of your project. You can then define, for example, a copyright header that should be generated on top of all your Java files. This template will be used for ll newly created classes in the project.

https://lh3.googleusercontent.com/-wdMRBn4HFcY/UM3eXAqvccI/AAAAAAAAKXc/GlWB4Cq5lIw/s826/Eclipse+JDT+-+Templates+01+Thumbnail.png

Now if you really want to create a wizard, you should have a look at Lars' tutorial.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: +stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com | Eclipse Java Development Tools Tips and Tricks



[Updated on: Thu, 17 January 2013 04:24]

Report message to a moderator

Re: Creating a custom class with a pre decided template [message #1017310 is a reply to message #1001622] Mon, 11 March 2013 14:59 Go to previous messageGo to next message
Tomas Bilka is currently offline Tomas Bilka
Messages: 1
Registered: March 2013
Junior Member
It would be nice to have a possibility to configure different Java class templates for certain "types" of classes.

F.e. when I create a new class that extends another specific class, i want to populate this new class with specific code template.

I would then hit "Create new class", then pop-up opens, I enter whch class i want to extend, new class is created with populated code template.

Or even better a possibility to define a new "Create My Specific Class" key shortcut. After hitting the key, the class would be created automatically.

Re: Creating a custom class with a pre decided template [message #1017464 is a reply to message #1017310] Mon, 11 March 2013 21:54 Go to previous message
David Wegener is currently offline David Wegener
Messages: 1341
Registered: July 2009
Senior Member
Have you looked at the Java->Editor->Templates feature? This allows you to define code snippets that will can be inserted using content assist (Ctrl-Space). Type the name of the template in your source file and hit Ctrl-Space. You will be given the template as an option. You can define variables that correspond to class name, method name, etc. This would allow you to create a class and then use content assist to fill in the details specific to the class.
Previous Topic:Initializing project state error
Next Topic:Failed to load JNI library
Goto Forum:
  


Current Time: Sun Sep 21 06:16:36 GMT 2014

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

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