`

在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();
    }
   }
  }

 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics