7

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.

helios
  • 13,574
  • 2
  • 45
  • 55
Rakesh Juyal
  • 35,919
  • 68
  • 173
  • 214
  • The normal new Class wizard can take the name of the class, superclass, and interfaces (and will generate method stubs for methods that need implementation). As for giving it fields, I don't see how this will be different from just writing them in the source; you still have to give the access modifier, type and name for each one. And for methods you still need to give the return type, name and each parameter (type + name). As for getters/setters you can generate them afterwards with the Generate getters and setters option. So you still write the same amount of text, only now it's in the wizard – Andrei Fierbinteanu Oct 06 '10 at 10:11

3 Answers3

6

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

Barthelemy
  • 8,277
  • 6
  • 33
  • 36
  • 1
    Do you know how I could just extend an existing wizard? E.g. I want to add a page to the wizard that is used for the creation of C/C++ projects. – Stefan Falk Feb 07 '14 at 23:54
2

You more or less want to add your own wizzard to the 'new class' dialog .. right?

This was the first site I found when typing "creating your own new wizzard eclipse" in Google: http://www.eclipse.org/articles/article.php?file=Article-JFaceWizards/index.html

LittleFunnyMan
  • 325
  • 3
  • 11
  • 1
    I don't think this is a correct answer. OP wants to have a new wizard creation for creating new (probably specific) class. So the solution should at least extends the available new class wizard. – nanda Oct 06 '10 at 10:14
  • 1
    @nanda I agree. This link is just about creating a wizard (first part of the question), not about creating a java source file (second part of the question). – Barthelemy Oct 06 '10 at 13:14
0

I may be mis-understanding the question, but it sounds like you are re-implementing the New Class Wizard that exists already.

It lets you name the class, the containing package. Can assign a superclass and/or interface and can also choose if you want to include the contructors for the superclass.

A new .java file is created with all known methods from declared interfaces and also any abstract methods from the superclass.

Edt: Title was changed whilst I was writing this reply to "How to creat a customer 'new class wizard; for Eclipse". It makes my answer slightly redundant but I'm not seeing any new functionality being added in the question.

Kevin D
  • 3,564
  • 1
  • 21
  • 38