Saturday, July 23, 2016

Creating a new Eclipse Project Wizard: Eclipse Plugin development


These are Eclipse customization technique, to add our own projects to the Eclipse plugin.

Project Wizard is the one used to create a new project in Eclipse. All the project that are plugged in with Eclipse will list down at this project Wizard. If you want to create a Java project you can choose ‘Java Project’ and it will load libraries and folder structure for that are requires for that Java project.
Similarly you can create a new your own plugin project (Integration of a new tool to Eclipse, parsing of files etc) and integrate with Eclipse. If you want to add a new our own project in to the Eclipse, the first step to add a new project Wizard.

project Wizard Window:
If you want to create a project, you can go to Eclipse project wizard (File-> New-> Other)


Then the project Wizard Window will be displayed with all the project list that are plugin to that Eclipse version.

If you create a new Eclipse Project Wizard, then that also will list down in the above list.

Steps for creating the new plugin-project in eclipse


First, you need to create new plug-in project by choosing the template as custom plug-in wizard (New File Wizard).

  1. Choose File > New > Project to select a project wizard.
  2. Under Plug-in Development, select Plug-in Project, as shown below.
  3. Click Next to advance to the next step.
  1. Add a project name (TestWizard). Click Next.
  1.  After you have filled in the information as shown below, click Next.
  1. Choose Custom plug-in wizard. Click Next.
  1. In the Template Selection window, click Deselect All to unselect all the options. Then, choose New File Wizard, as shown below. Click Next
  1. The Eclipse wizard prompts you for some information about the new wizard you're creating. Make sure you update the package name, ideally to the same name that you used for the Activator (testwizard). Update the Wizard Category Name to the name of the folder for the new wizard. The Wizard Class Name is a Java class name for the class that inherits from Wizard and implements the INewWizard interface. The Wizard Page Class Name extends the WizardPage class.
  1. Click Finish. Eclipse adds your new project with the necessary classes and libraries.
Folder structure of the wizard project

It will automatically create NewWizard and NewWizardPage and Plugin.xml.

1.      Go to Plugin.xml , extension tab, there you will be able to view the new wizard that we added.

If required, we can change the category name and wizard name here.

New Wizard Class structure



If you click on the class link (class*) it will go to the default class  TestNewWizard’.

(addPages, performFinish, doFinish, openContentStream, throwCoreException,init are the method inside this class)

We can add new pages to the testNewWizard.java

addPages -  The addPages() method adds pages to the wizard.

We can create our own wizard pages or use existing in wizard pages and add that pages to the wizard using the addpage (wizardpage) method.


private WizardNewProjectCreationPage  wizardPage;
public void addPages() {
wizardPage = new WizardNewProjectCreationPage("NewTestProject");
        wizardPage.setDescription("Create a new Test Project.");
        wizardPage.setTitle("New Test Project");
        addPage(wizardPage);
}
Here we want to create project creation wizard, we can use the already existing wizard ‘WizardNewProjectCreationPage’ that is coming with org.eclipse.ui.dialogs package.


Testing the New Wizard



To launch your plug-in project, right-click on the Plugin.xaml, and select Run As > Eclipse Application as shown in below Figure. A new instance of Eclipse starts up.

  1. In that new Eclipse got to the Choose File > New > Others to select a project wizard.
  2. Where you will be able to view the your Wizard Test Wizards(Category name in extension tab of pulgin.xml) and Test Wizard(Wizard name in extension tab of pulgin.xml),   (Note: If you change this name in extension tab it will reflect here)

When you select TestWizard, the ‘Next’ icon will be enabled and you will be able to go to the new project wizard selection page as shown below:

Here you will be able to give name of your new Test Project. Then finish button will be enabled.

No comments:

Post a Comment