您现在的位置是:首页 >

perspective记忆 Eclipse中perspective的两种使用方法详解

火烧 2022-11-25 15:22:47 1061
Ecli e中 er ective的两种使用方法详解   这里要介绍的是如何给你的RCP程序或Ecli e插件定义透视图 并向透视图中添加视图及对各视图间的摆放位置给出定义 好 进入正题 给我们的插件

Eclipse中perspective的两种使用方法详解  

  这里要介绍的是如何给你的RCP程序或Eclipse插件定义透视图 并向透视图中添加视图及对各视图间的摆放位置给出定义 好 进入正题 给我们的插件定义一个透视图先:定义透视图的方法相信很多人都比较清楚 要扩展 eclipse ui perspectives扩展点 好 直接在我们的plugin xml文件中加入下面一句代码就ok了

   ﹤extension point= eclipse ui perspectives >      

  ﹤perspective

  class= re ui perspective Perspective

  icon= icons/amc_perspect gif

  id= re ui perspective Perspective

  name= %perspective amc >

  ﹤/perspective>

  ﹤/extension>

perspective记忆 Eclipse中perspective的两种使用方法详解
 

  上面的代码中 表明我们的透视图id为 talend amc plugin Perspective 好 记住这个id 下面我们就要向这个透视图中来添加我们的view(视图)了 有两种方法都可以实现视图的添加 一种是通过代码直接添加 另外一种方法则是直接就在plugin xml里进行配置

  通过代码向已知透视图中添加视图并布局 上面的代码中已指出该perspective所对应的类为 talend amc plugin Perspective 该类需要实现IPerspectiveFactory接口 并实现它的createInitialLayout(IPageLayout layout) 方法 createInitialLayout(IPageLayout layout) 方法就能够实现对perspective中view的布局 详细代码如下

   package re ui perspective;

  import eclipse ui IFolderLayout;

  import eclipse ui IPageLayout;

  import eclipse ui IPerspectiveFactory; 

  import re ui views detaillog DetailLogsView;  import re ui views jobinfo JobInformationView; import re ui views statinfo DetailStatsView; import re ui views statinfo SimpleStatsView;

  /** *//**  * The class define for the test blog perspective ﹤br/>  *   * $Id: Perspective java v / / : : pub Exp $  *   */ public class Perspective implements IPerspectiveFactory {           public static final String ID = re ui perspective Perspective ; //$NON NLS $          public void createInitialLayout(IPageLayout layout) {           //这里不需要显示editor 故而设置为不可见         layout setEditorAreaVisible(false);         String editorArea = layout getEditorArea();          //下面给出的是各view的位置布局定义 这些代码都可以直接在plugin xml进行配置 可以达到相同效果         layout addView(JobInformationView ID IPageLayout LEFT f editorArea);         layout addView(DetailLogsView ID IPageLayout BOTTOM f editorArea);                  String logInfoFolderID = position statlog ;         IFolderLayout bottomFolder = layout createFolder(logInfoFolderID IPageLayout BOTTOM f                  JobInformationView ID);         bottomFolder addView(SimpleStatsView ID);         bottomFolder addView(DetailStatsView ID);         layout getViewLayout(JobInformationView ID) setCloseable(false);         layout getViewLayout(SimpleStatsView ID) setCloseable(false);         layout getViewLayout(DetailStatsView ID) setCloseable(false);     }  }

  这里只是在代码中直接使用view id 如果真要让这些id所对应的view显示出来 当然还需要你在自己的插件中给出这些view id的定义

  在plugin xml中直接添加视图并配置布局

  Eclipse 为各个view在透视图的布局也提供了专用的扩展点 它就是 eclipse ui perspectiveExtensions 利用这个扩展点 我们甚至不需要对 talend amc plugin Perspective类进行任何修改 就可以按我们的要求向perspective中添加新的视图(view) 比如要达到上面同效果的视图布局 可向plugin xml中添加以下配置代码

   ﹤extension point= eclipse ui perspectiveExtensions >

  ﹤perspectiveExtension    

  targetID= re ui perspective Perspective >            

  ﹤view

  id= re ui views jobinfo JobInformationView

  relative= eclipse ui editorss             

  relationship= left             

  ratio=             

  closeable= false />

  ﹤view

  id= re ui views detaillog DetailLogsView

  relative= eclipse ui editorss

  relationship= bottom

  ratio= />

  ﹤view

  id= re ui views statinfo SimpleStatsView

  relative= re ui views jobinfo JobInformationView

  relationship= bottom

  ratio=

  closeable= false />

  ﹤view

  id= re ui views statinfo DetailStatsView

  relative= re ui views statinfo SimpleStatsView

  relationship= stack

  closeable= false />

  ﹤/perspectiveExtension>

  ﹤/extension>

  运行后 各view间的布局关系如下图所示

  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码