RCP实用技巧

来源:互联网 发布:php网页游戏源代码 编辑:程序博客网 时间:2024/05/29 19:06

RCP实用技巧

关键字: rcp实用技巧

1.最大化窗口:
ApplicationWorkbenchWindowAdvisor中,书写如下方法:

Java代码

  1. public void postWindowCreate() {   
  2.     super.postWindowCreate();   
  3.     getWindowConfigurer().getWindow().getShell().setMaximized(true);   
  4.        
  5. }  

Java代码

  1. public void postWindowCreate() {   
  2.     super.postWindowCreate();   
  3.     getWindowConfigurer().getWindow().getShell().setMaximized(true);   
  4.        
  5. }  

  public void postWindowCreate() {

   super.postWindowCreate();

   getWindowConfigurer().getWindow().getShell().setMaximized(true);

  

  }


2.
设置viewtab显示风格:
ApplicationWorkbenchAdvisor中添加如下代码

Java代码

  1. @Override  
  2.     public void initialize(IWorkbenchConfigurer configurer) {   
  3.         // TODO Auto-generated method stub   
  4.         super.initialize(configurer);   
  5.         PlatformUI.getPreferenceStore().setValue(   
  6.                 IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,   
  7.                 false);   
  8.     }  

Java代码

  1. @Override  
  2.     public void initialize(IWorkbenchConfigurer configurer) {   
  3.         // TODO Auto-generated method stub   
  4.         super.initialize(configurer);   
  5.         PlatformUI.getPreferenceStore().setValue(   
  6.                 IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,   
  7.                 false);   
  8.     }  

@Override

  public void initialize(IWorkbenchConfigurer configurer) {

   // TODO Auto-generated method stub

   super.initialize(configurer);

   PlatformUI.getPreferenceStore().setValue(

        IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,

      false);

  }


3.
设置view的显示要求(可移动?关闭?最大化?最小化?)
一种方式是通过org.eclipse.ui.perspectiveExtensions配置view来方便的设置各个属性,我有专门的一篇文章介绍。另一种方式是在perspectivecreateInitialLayout方法中,采用如下语句配置:

Java代码

  1. layout.getViewLayout(View1.ID).setCloseable(false);   
  2. //设置View1的关闭按钮不可见   
  3. layout.getViewLayout(View1).setMoveable(false)   
  4. //设置View1的不可移动   
  5. layout.setFixed(true);   
  6. //设置该perspective中的所有view,其大小不可变动,无最大最小按钮  

Java代码

  1. layout.getViewLayout(View1.ID).setCloseable(false);   
  2. //设置View1的关闭按钮不可见   
  3. layout.getViewLayout(View1).setMoveable(false)   
  4. //设置View1的不可移动   
  5. layout.setFixed(true);   
  6. //设置该perspective中的所有view,其大小不可变动,无最大最小按钮  

layout.getViewLayout(View1.ID).setCloseable(false);

//设置View1的关闭按钮不可见

layout.getViewLayout(View1).setMoveable(false)

//设置View1的不可移动

layout.setFixed(true);

//设置该perspective中的所有view,其大小不可变动,无最大最小按钮


4.
在其他view中获取某个view的引用

Java代码

  1. PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("viewId");  

Java代码

  1. PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("viewId");  

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("viewId");



5.
关闭一个当前的perspective打开一个新的perspective

Java代码

  1. IWorkbench w=PlatformUI.getWorkbench();   
  2.   
  3. ActionFactory.IWorkbenchAction closePerspectiveAction   
  4. = ActionFactory.CLOSE_PERSPECTIVE.create(w.getActiveWorkbenchWindow());   
  5. closePerspectiveAction.run();   
  6.   
  7. try ...{   
  8. PlatformUI.getWorkbench().showPerspective("com.ibm.demo.saic.ui.views.NextPerspective",   
  9. w.getActiveWorkbenchWindow());   
  10. catch (WorkbenchException e) ...{   
  11. e.printStackTrace();   
  12. }  

Java代码

  1. IWorkbench w=PlatformUI.getWorkbench();   
  2.   
  3. ActionFactory.IWorkbenchAction closePerspectiveAction   
  4. = ActionFactory.CLOSE_PERSPECTIVE.create(w.getActiveWorkbenchWindow());   
  5. closePerspectiveAction.run();   
  6.   
  7. try ...{   
  8. PlatformUI.getWorkbench().showPerspective("com.ibm.demo.saic.ui.views.NextPerspective",   
  9. w.getActiveWorkbenchWindow());   
  10. } catch (WorkbenchException e) ...{   
  11. e.printStackTrace();   
  12. }  

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

}


6.
如果想让两个view占据一个位置(如IPageLayout.TOP,在createInitialLayout用如下方法:

Java代码

  1. IFolderLayout folder = layout.createFolder("folderID", IPageLayout.TOP,   
  2.     0.5f, IPageLayout.ID_EDITOR_AREA);   
  3.   folder.addPlaceholder(View1.ID + ":*");   
  4.   folder.addView(View1.ID);   
  5.   folder.addPlaceholder(View2.ID + ":*");   
  6.   folder.addView(View2.ID);  

Java代码

  1. IFolderLayout folder = layout.createFolder("folderID", IPageLayout.TOP,   
  2.     0.5f, IPageLayout.ID_EDITOR_AREA);   
  3.   folder.addPlaceholder(View1.ID + ":*");   
  4.   folder.addView(View1.ID);   
  5.   folder.addPlaceholder(View2.ID + ":*");   
  6.   folder.addView(View2.ID);  

IFolderLayout folder = layout.createFolder("folderID", IPageLayout.TOP,

    0.5f, IPageLayout.ID_EDITOR_AREA);

  folder.addPlaceholder(View1.ID + ":*");

  folder.addView(View1.ID);

  folder.addPlaceholder(View2.ID + ":*");

  folder.addView(View2.ID);


7.
在目录中添加保存透视图、打开透视图对话框的方法
(1)
ApplicationActionBarAdvisorMakeActions中添加:

Java代码

  1. register(ActionFactory.SAVE_PERSPECTIVE.create(window));    
  2. register(ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(window));  

Java代码

  1. register(ActionFactory.SAVE_PERSPECTIVE.create(window));    
  2. register(ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(window));  

register(ActionFactory.SAVE_PERSPECTIVE.create(window));

register(ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(window));


(2)
ApplicationActionBarAdvisorfillMenuBar中添加:

Java代码

  1. MenuManager fileMenu = new MenuManager("&File",   
  2.         IWorkbenchActionConstants.M_FILE);   
  3. menuBar.add(fileMenu);   
  4. fileMenu.add(getAction(ActionFactory.SAVE_PERSPECTIVE.getId()));   
  5. fileMenu.add(getAction(ActionFactory.OPEN_PERSPECTIVE_DIALOG.getId()));  

Java代码

  1. MenuManager fileMenu = new MenuManager("&File",   
  2.         IWorkbenchActionConstants.M_FILE);   
  3. menuBar.add(fileMenu);   
  4. fileMenu.add(getAction(ActionFactory.SAVE_PERSPECTIVE.getId()));   
  5. fileMenu.add(getAction(ActionFactory.OPEN_PERSPECTIVE_DIALOG.getId()));  

   MenuManager fileMenu = new MenuManager("&File",

      IWorkbenchActionConstants.M_FILE);

   menuBar.add(fileMenu);

   fileMenu.add(getAction(ActionFactory.SAVE_PERSPECTIVE.getId()));

   fileMenu.add(getAction(ActionFactory.OPEN_PERSPECTIVE_DIALOG.getId()));


这样既可完成。
8.
关于perspective(转载http://dearwolf.javaeye.com/blog/40879)
IWorkbenchPreferenceConstants中有很多常量,用来配置preference settings,诸如:
  OPEN_NEW_PERSPECTIVE——
打开新视图的方式
  DOCK_PERSPECTIVE_BAR——
锁定PerspectiveBar的位置
  INITIAL_FAST_VIEW_BAR_LOCATION——
表示fast view bar在一个fresh workspace中锁定的  位置,This preference is meaningless after a workspace has been setup, since the fast view bar state is then persisted in the workbench
  SHOW_TRADITIONAL_STYLE_TABS——
表示是否在editorview上显示传统的tab style
  SHOW_PROGRESS_ON_STARTUP——
是否在启动时显示progress
  SHOW_TEXT_ON_PERSPECTIVE_BAR——
是否在PerspectiveBar上显示文字
9.
给一个perspective添加上两个相同的view

Java代码

  1. layout.addView(YourView.ID + ":1", IPageLayout.LEFT,0.65f,layout.getEditorArea());   
  2.            
  3. layout.addView(YourView.ID + ":2", IPageLayout.BOTTOM, 0.50f,YourView.ID + ":1");   

Java代码

  1. layout.addView(YourView.ID + ":1", IPageLayout.LEFT,0.65f,layout.getEditorArea());   
  2.            
  3. layout.addView(YourView.ID + ":2", IPageLayout.BOTTOM, 0.50f,YourView.ID + ":1");   

 

原创粉丝点击