Posted in
Tips
Have you seen the "Open Associated Perspective" dialog when you create a new Java Project from a Resource Perspective or Debug Perspective? Wonder how to associate a perspective to your own wizard? This tip explains it.
We normally extend the org.eclipse.ui.newWizards - wizard extension point for the creation of new elements including a new project. It has an optional attribute called finalPerspective - the perspective that will get activated when the wizard is finished. This happens only if the wizard is a new project wizard. So how do we make our other wizards to switch to some predefined perspective? Three simple steps:
- The obvious step. add the finalPerspective attribute to the definition of our wizard element in the extension.
- Make the Wizard class implement the interface IExecutableExtension. This interface has only one method setInitializationData. Implement the method in the class and assign the parameter IConfigurationElement to a field in the method.
- In the performFinish method of the Wizard, call BasicNewProjectResourceWizard.updatePerspective method.
You are done :-) If you don't want this perspective switch happening, when some another perspective is active, you can specify that perspective in the preferredPerspectives attribute. If the switching perspective doesn't happen, probably you have turned it off. In the preferences page, look at the option the option General->Perspectives->Open the associated perspective. I've added the Resource perspective as the final perspective for sample New File Wizard created by Eclipse.
| < Prev | Next > | |
|---|---|---|


