动态改变 Eclipse RCP 应用程序的标题

我们知道,Title 是在 ApplicationWorkbenchWindowAdvisor 里面通过

public void preWindowOpen()
{  
     IWorkbenchWindowConfigurer configurer = getWindowConfigurer();  
     configurer.setInitialSize(new Point(600, 500));  
     configurer.setShowCoolBar(false);  
     configurer.setShowStatusLine(true);  
     configurer.setShowProgressIndicator(true);  
     configurer.setTitle(xxx);  
 }


来实现的,那么如何在运行时动态的更改它呢?

最开始一直在想如何获得IWorkbenchWindowConfigurer,但是一点头绪都没有,后来到RCP新闻组里面问了一下,两个人给了回复,不过都不怎么满意,但其中一个给了我启示,他信中写道:

I've used the following technique:
public static void changeAppTitle(String newTitle) {  
        Display display = Display.getDefault();  
        if (display != null) {  
                // Look at all the shells and pick the first one  
                // that is a workbench window.  
                Shell shells[] = display.getShells();  
                for (int i = 0; i < shells.length; i++) {  
                        Object data = shells[i].getData();  
                        // Check whether this shell points to the
                        // Application main window's shell 
                        if (data instanceof IWorkbenchWindow) {  
                                shells[i].setText(newTitle);  
                                break;  
                        }  
                }  
        }  
}


 

既然可以通过IWorkbenchWindow的Shell来设置标题,那么一切就好解决了。

在ActionBarAdvisor中初始化Action时,把WorkbenchWindow作为参数传入构造器中,然后在Action中就可以使用window.getShell().setText()了 :)

 

备注:本文转载自:http://www.iteye.com/topic/40853

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值