1、使用org.eclipse.ui.perspectives 扩展点定义透视图的相关信息,使用org.eclipse.ui.views定义view的相关信息。定义完成,在一个实现了 IPerspectiveFactory接口的类里添加view,在添加的时候定义view的布局,如下:
point="org.eclipse.ui.perspectives">
class="com.ibm.demo.saic.MainPerspective"
id="com.ibm.demo.saic.MainPerspective"
name="MainPerspective"/>

point="org.eclipse.ui.views">
class="com.ibm.demo.saic.ui.views.TreeView"
id="com.ibm.demo.saic.ui.views.TreeView"
name="TreeView"/>
class="com.ibm.demo.saic.ui.views.WelcomeView"
id="com.ibm.demo.saic.ui.views.WelcomeView"
name="WelcomeView"/>
public class MainPerspective implements IPerspectiveFactory {
public static String ID="com.ibm.demo.saic.MainPerspective";
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
layout.addView(TreeView.ID, IPageLayout.TOP,
0.25f, layout.getEditorArea());
layout.setEditorAreaVisible(false);
/*layout.addView(LoginView.ID,IPageLayout.LEFT,
1f,layout.getEditorArea());*/
layout.addView(WelcomeView.ID,IPageLayout.LEFT,
1f,layout.getEditorArea());
IViewLayout vl=layout.getViewLayout(WelcomeView.ID);
//设置View不可关闭
layout.getViewLayout(WelcomeView.ID).setCloseable(false);
//设置View不可移动
layout.getViewLayout(WelcomeView.ID).setMoveable(false);
}
}
2, 使用org.eclipse.ui.perspectiveExtensions扩展点,向某个perspective里添加view,并设置布局。(说明:需要先定义好perspective和view)
point="org.eclipse.ui.perspectiveExtensions">
closeable="false"
id="com.ibm.demo.saic.ui.views.LoginView"
moveable="false"
ratio="1f"
relationship="left"
relative="org.eclipse.ui.editorss"
visible="true"/>
public class LoginPerspective implements IPerspectiveFactory {
public static String ID="com.ibm.demo.saic.LoginPerspective";
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
}
}
关闭当前perspective,并打开一个新的perspective:
IWorkbench w=PlatformUI.getWorkbench();
ActionFactory.IWorkbenchAction closePerspectiveAction
= ActionFactory.CLOSE_PERSPECTIVE.create(w.getActiveWorkbenchWindow());
closePerspectiveAction.run();
try {
PlatformUI.getWorkbench().showPerspective("com.ibm.demo.saic.ui.views.NextPerspective", w.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
IWorkbench w=PlatformUI.getWorkbench();
IPerspectiveRegistry pr=w.getPerspectiveRegistry() ;
IPerspectiveDescriptor persdes=pr.findPerspectiveWithId("perspectiveID");
WorkbenchPage p=(WorkbenchPage)w.getActiveWorkbenchWindow().getActivePage();
Perspective persp = p.getActivePerspective();
p.closePerspective(persdes,false,false);
try {
w.showPerspective("nextperspectiveID", w.getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
}
Eclipse透视图定制
本文介绍两种在Eclipse中定义透视图和视图的方法:一是通过扩展点定义,二是使用扩展点向现有透视图添加视图。同时,还提供了关闭当前透视图并打开新透视图的具体实现。

3326

被折叠的 条评论
为什么被折叠?



