Implementing a Project Creation Wizard
The basic project creation flow can be easily integrated to your plug-in by extending the AbstractWSO2ProjectCreationWizard
class. This will give you the basic project creation flow and you can customize this by editing the project_wizard.xml
file (omit unnecessary fields e.g. if you do not need the package name of a project to be given by the user, you can remove these items from your project_wizard.xml
file). You need to write your own validator class for your wizards by specifying the mandatory fields in the wizard and this class should be referred to in your project_wizard.xml
file. A sample project_wizard.xml
file is shown below along with the related UI wizard dialog boxes.
<wizard> <projectOptions title="Mediator Artifact Creation Wizard" description="Select how you would like to create your new project" error="Please select a method to create the project" > <option id="new.mediator" default="true">Create New Mediator</option> <option id="import.mediator">Import From Workspace</option> </projectOptions> <projectOptionSettings> <settings optionId="new.mediator" title="Mediator Artifact" description="Create a new Mediator Artifact" error="Please give a name to create the mediator"> <data modelProperty="project.name" type="string" fieldController="org.wso2.developerstudio.eclipse.artifact.mediator.validators.MediatorFieldsController">Project Name </data> <data modelProperty="mediatorClass.package.name" type="string" fieldController="org.wso2.developerstudio.eclipse.artifact.mediator.validators.MediatorFieldsController" group="testid">Package Name</data> <data modelProperty="mediatorClass.name" type="string" fieldController="org.wso2.developerstudio.eclipse.artifact.mediator.validators.MediatorFieldsController" group="testid">Class Name</data> <group id="testid"></group> <projectNatures> <nature>org.eclipse.jdt.core.javanature</nature> </projectNatures> </settings> <settings optionId="import.mediator" title="Mediator Artifact" description="Create a Mediator Artifact using a existing Mediator file" error="Please select the project"> <data modelProperty="import.project.list" type="list" fieldController="org.wso2.developerstudio.eclipse.artifact.mediator.validators.MediatorFieldsController" controlData="select=single;class=org.wso2.developerstudio.eclipse.artifact.mediator.utils.ProjectData">Mediator Project</data> <projectNatures> <nature>org.eclipse.jdt.core.javanature</nature> </projectNatures> </settings> </projectOptionSettings> </wizard>
 |  |  |
For this sample project creation wizard, the validation class is defined as org.wso2.developerstudio.eclipse.artifact.mediator.validators.MediatorFieldsController
 and that class involves all the field validations for the particular wizard.
The parameters taken from this wizard are saved in the project model. For each new project creation wizard, you need to have a project model with the parameters that need to be saved. A sample project model class is as follows:
public class CustomMediatorModel extends ProjectDataModel { private String mediatorClass; private String mediatorClassPackage; private IProject mediatorProject; public Object getModelPropertyValue(String key) { Object modelPropertyValue = super.getModelPropertyValue(key); if((modelPropertyValue == null)&&("mediatorClass.name".equals(key))){ modelPropertyValue = this.getMediatorClassName(); } if((modelPropertyValue == null)&&("mediatorClass.package.name".equals(key))){ modelPropertyValue = this.getMediatorClassPackageName(); } if((modelPropertyValue == null)&&("import.project.list".equals(key))){ modelPropertyValue = this.getMediatorProject(); } return modelPropertyValue; } public boolean setModelPropertyValue(String key, Object data) throws ObserverFailedException { boolean isUiControlUpdated = super.setModelPropertyValue(key, data); if ("mediatorClass.name".equals(key)) { this.setMediatorClassName(data.toString()); } if("mediatorClass.package.name".equals(key)){ this.setMediatorClassPackageName(data.toString()); } if("import.project.list".equals(key)){ this.setMediatorProject((IProject)data); } return isUiControlUpdated; } public void setMediatorClassName(String mediatorClass) { this.mediatorClass=mediatorClass; } public String getMediatorClassName(){ return mediatorClass; } public void setMediatorClassPackageName(String mediatorClassPackage) throws ObserverFailedException { this.mediatorClassPackage = mediatorClassPackage; super.setGroupId(mediatorClassPackage); } public String getMediatorClassPackageName() { return mediatorClassPackage; } public void setMediatorProject(IProject mediatorProject) { this.mediatorProject = mediatorProject; try { if (mediatorProject != null) this.setProjectName(mediatorProject.getName()); } catch (ObserverFailedException e) { //ignore. } } public IProject getMediatorProject() { return mediatorProject; } }
CustomMediatorCreationWizard
is the class that involves all the logic for the wizard flow. This class extends the AbstractWSO2ProjectCreationWizard
class which provides the basic wizard flow for a new artifact project creation for WSO2. The performFinish
method in this class contains all the backend logic (creating the custom mediator java project in the user workspace)Â that needs to happen upon user execution of the Finish button of the wizard flow. This involves creating pom.xml
files, project classes and adding required dependencies to the project.