Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 895
Rakesh Juyal Avatar asked Oct 06 '10 09:10

Rakesh Juyal


People also ask

How do I create a new class in Eclipse?

The easiest way to do this is to right-click on a project in the Package Explorer and select New > Class. This will bring up a totally sweet class creation window. If you know what packages are and how to use them, you can specify what package your new class will fall into.

Where is wizard in Eclipse?

To open a wizard, use the WizardDialog class from the org. eclipse. jface. wizard package.


1 Answers

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!).

like image 170
Barthelemy Avatar answered Nov 14 '22 22:11

Barthelemy