在Eclipse rcp程序启动时,打开自定义的EditorPart的方法

    在Eclipse rcp启动时,对于系统默认启动的Perspective,可以通过增加各种viewpart,在系统启动时,打开自定义的view。但是在createInitialLayout(ILayout layout)方法中,利用layout无法传入自定义的editorpart,替换系统默认的"org.eclipse.ui.editorss”editor,于是如何打开自定义的editorpart成了一个问题。

    在分析打开自定义的editorpart的方法调用时:PlatformUI.getWrokbench().getActiveWorkbenchWindow().getActivePage().openEditor(,EditorInput,EditorID,true),问题的关键是获得IWorkBenchPage对象。为了获得active 的page,通过对Eclipse UI结构的分析,可知当workbenchWindow打开后,则可以或得activepage,所以,可以通过重载ApplicationWorkbenchWindowAdivor的postWidowOpen方法,在其中打开editorpart,即可,我的代码如下:

  public void postWindowOpen() {
  // TODO Auto-generated method stub
  super.postWindowOpen();

  IWorkbench bench = PlatformUI.getWorkbench();
  String defaultPerspectiveID = bench.getPerspectiveRegistry()
    .getDefaultPerspective();

  if (defaultPerspectiveID.equals(MyPerspective.PERSPECTIVE_ID)) {
   File file = new File("");
   String path = file.getAbsolutePath();

   if (path != null) {
    IEditorInput input = new DiagramEditorInput(new Path(path));
    IWorkbenchPage page = PlatformUI.getWorkbench()
      .getActiveWorkbenchWindow().getActivePage();
    try {
     page.openEditor(input, DiagramEditor.ID, true);
    } catch (PartInitException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
  }

 }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值