How to create a custom 'new class wizard' for Eclipse?

Rakesh Juyal picture Rakesh Juyal · Oct 6, 2010 · Viewed 8.9k times · Source

I would like to create a functionality ( for myself ), wherein on clicking a button ( or say firing any event or anything that can trigger my program ), a popup will be displayed which will ask the name of the Class, objects it have and few more thing. Then on pressing OK, it will create a java file with skeleton of predefined methods, inherit known interface and ...

So, basically how to do that? Do i need to create a plugin for eclipse or there is something else in eclipse for it.

PS Please change the title. I am unable to think of any better one.

Answer

Barthelemy picture Barthelemy · Oct 6, 2010

As others said, you want to create a wizard, then you want to augment the New Class Wizard, which is doing something similar to what you want (but the default wizard don't allow you to to add fields and custom methods).

To create a wizard, you can use the "New File Wizard" extension template: Create a plug-in, then, go to the extensions tab, select Add..., and select the "Extension Wizards" tab. That will get you started on Eclipse wizards.

Once you've learned the basics of creating Wizards and pages, then, include the org.eclipse.jdt.ui and org.eclipse.jdt.core in your plug-in dependencies. Open the following type (Ctrl-Shift-T): "NewClassWizardPage". This is the page that is displayed when you select New > Class in the Package Explorer.

You can probably either copy this page and the parent pages to help you get started or just extend it (in my experience, internal Eclipse wizards such as this one are difficult to extend because they have lots of fields and methods that are package/private, so I usually end up copying the code as a starting point... don't forget to keep the license though!).