Eclipse RCP开发剪辑之perspective

来源:互联网 发布:有什么情侣装淘宝店 编辑:程序博客网 时间:2024/04/29 03:58
 一、使用扩展点定义透视图和里面的view有两种方式处理,分别是:

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,并打开一个新的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();
}
上面是调用的系统的action,具体实现如下:
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();
}
原创粉丝点击