1. 在plugin.xml 中添加扩展点
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="com.abc.xx.perspective.FavoritesPerspectiveFactory"
icon="icons/newN.ico"
id="com.abc.MyPerspective"
name="MyPerspective">
</perspective>
</extension>
2. 创建自已定义的工程时刷新透视图:
在performFinish()方法中添加:
updatePerspective();
BasicNewProjectResourceWizard.selectAndReveal(project, workbench.getActiveWorkbenchWindow());
updatePerspective()方法:
protected void updatePerspective() {
IWorkbenchPage iworkbenchPage=workbench.getActiveWorkbenchWindow().getActivePage();
workbench=PlatformUI.getWorkbench();
IPerspectiveDescriptor perspective = workbench.getPerspectiveRegistry().findPerspectiveWithId("com.abc.MyPerspective"); //perspective 的id
iworkbenchPage.setPerspective(perspective);
}
}
或者,在plugin.xml中的创建工程向导的时候添加"finalPerspective”字段,
<wizard
category="NGCWizard"
class="com.hp.KBwizards.NewKBProjectWizard"
finalPerspective="com.hp.ngc.NgcPerspective"
icon="icons/project_wizard.gif"
id="com.hp.KBwizards.NewProjectWizard"
name="%new.project.name"
project="true">
<description>
%new.project.desc
</description>
</wizard>
则在创建工程的wizard类中,perfomFinish()方法中即可使用
BasicNewProjectResourceWizard.updatePerspective(config);
来初始化透视图