Eclipse RCP开发剪辑之perspective

 一、使用扩展点定义透视图和里面的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();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值