现在的位置: 首页 > 综合 > 正文

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

2013年08月30日 ⁄ 综合 ⁄ 共 1050字 ⁄ 字号 评论关闭

我们知道,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

抱歉!评论已关闭.