Building an Eclipse Plug-in Project Wizard

I found this really great article at Hidden Clause called Writing an Eclipse Plug-in (Part 2): Creating a custom project in Eclipse – Adding to the New Project Wizard.  My only problem with it is that I am using a newer version of Eclipse, and I really needed screenshots to understand what it was talking about.  So, here’s my experience at walking through that tutorial…

Getting Setup

First, I created my own separate Workspace for this task.  I’ll probably delete it later, and my hope is to create an Android Kitchen project, but we’ll see how that goes.

So, I entered my path for the new Workspace in the first dialog:

To check the version of Eclipse, I went to Help > About Eclipse.  I can see that I have version 4.2:

Just for reference, I checked the version of Java that I had installed:


skp@chestnut:~$ java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Also, just for reference, I looked in Window Preferences to see that I had the Oracle Java 7 configured as the JRE to use:

Creating the Project

So, to begin, I need a new project.  File > New Project will do the trick:

I chose Plug-in Project.

I just gave the project a name.

I accepted the defaults on the second screen:

I unchecked the option to use a template on the second page of the wizard.

When I hit finish, it offered to open the Plug-in Perspective:

The only Java class that it created was the Activator:

Fix

I ran across this error while trying to add the Wizard.  On the top it said:

No schema found for the ‘org.eclipse.ui.newWizards’ extension point

When I tried to add the category, it wasn’t an option:

The fix was to install the SDK.  I went to Help > Install New Software:

After that, the message was gone, and I could add the new wizard.

Adding the Project Wizard

In the Project properties, I went to the Extensions tab:

Then, I hit “Add” and chose the newWizards option:

Then, I right clicked on the new extension, and chose to add a new category:

Next, I filled in the ID and Name properties:

 

Then, I right clicked again on the new wizard extension and added a wizard:

Then, I set the following properties:

  • id: skpPluginProject.wizard.new.custom
  • name: Custom Project
  • class: skppluginproject.wizards.CustomProjectNewWizard
  • category: skpPluginProject.category.wizards

Then, don’t forget to save.

Adding a dependency

You will need to add a dependency in order to use the WizardNewProjectCreationPage class.  So, we’ll go ahead and add that now. Click on the dependencies tab at the bottom:

Click add and select the org.eclipse.ui.ide plugin:

Now, it should show up in the list.  Don’t forget to save.

Creating the Wizard Class

Go back to the extensions tab and click the label for the Class:

This opens the New Class Wizard, and it had everything filled in.  So, I could just click finish.

Then, it created the new class:

First Test

According to the article, we are ready to give it a whirl.  Select Run As > Eclipse application:

So, this launched a new instance of Eclipse that was pretty much blank:

Then, select File > New > Other

My new “Custom Project” was in the list:

It doesn’t do anything after this.  So, we’ll have to close the Eclipse, and we’ll add the next step.

Adding the Page

Now it’s time to add a page.  First step is to declare a variable for the page.  I copied this code:

private WizardNewProjectCreationPage _pageOne;

If you notice the red line, it’s because the class was not imported.  Hitting Ctrl+Shift+O will fix that problem. Next, I copied the addPages() method and added it to my class:


@Override
 public void addPages() {
 super.addPages();

 _pageOne = new WizardNewProjectCreationPage("From Scratch Project Wizard");
 _pageOne.setTitle("From Scratch Project");
 _pageOne.setDescription("Creating something from scratch");

 addPage(_pageOne);
 }

I updated the performFinish() method to return true:

Then, I changed the constructor to call the setWindowTitle() function.

Testing a Second Time

Now, I ran the plug-in again.  In the new instance of Eclipse, I hit Ctrl+N, and chose the Custom Wizard:

Now, when I click Next, it gives me the new Project page.

But, when I click Finish, it still doesn’t do anything.

Creating a Navigator

Next, I tried to follow-on and create a navigator.  I want back to the project’s properties and clicked Add on the extensions tab.  This time, I went to the Extension Wizards tab and chose Common Navigator View.

I just used the same View ID and name as Hidden Clause:

I hit yes on the Save dialog:

Making it a New Project Extension

I found that I could set the Project property for the extension to true.  Then, it would show the Wizard in the New Project list.

Now, I can do New > Project…

… and, it shows in the list:

Conclusion

This answered many of my questions, but it still doesn’t actually create the project.  I need to dig through some of the other posts and figure that out.  I’ll save that for a follow up or part 2.

Resources

Leave a Comment

Your email address will not be published. Required fields are marked *