RCp的view

在学习过程中也总结一下,方便自己今后的查阅,也给广大需要rcp的同仁们提供点帮助。

1.最大化窗口:

在ApplicationWorkbenchWindowAdvisor中,书写如下方法:

Java代码

 

public void postWindowCreate() {   
    super.postWindowCreate();   
    getWindowConfigurer().getWindow().getShell().setMaximized(true);   
       
}  
 

public void postWindowCreate() { super.postWindowCreate(); getWindowConfigurer().getWindow().getShell().setMaximized(true); }

2.设置view的tab显示风格:

在ApplicationWorkbenchAdvisor中添加如下代码

Java代码

 

@Override  
    public void initialize(IWorkbenchConfigurer configurer) {   
        // TODO Auto-generated method stub   
        super.initialize(configurer);   
        PlatformUI.getPreferenceStore().setValue(   
                IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,   
                false);   
    }  
 

@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来方便的设置各个属性,我有专门的一篇文章介绍。另一种方式是在perspective的createInitialLayout方法中,采用如下语句配置:

Java代码

 

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

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

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

Java代码

 

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

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

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

Java代码

 

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

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代码

 

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

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) 在ApplicationActionBarAdvisor的MakeActions中添加:

Java代码

 

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

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

(2) 在ApplicationActionBarAdvisor的fillMenuBar中添加:

Java代码

 

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

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——表示是否在editor和view上显示传统的tab style

  SHOW_PROGRESS_ON_STARTUP——是否在启动时显示progress

  SHOW_TEXT_ON_PERSPECTIVE_BAR——是否在PerspectiveBar上显示文字

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yefei679/archive/2009/03/08/3968829.aspx

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值