`
dearwolf
  • 浏览: 339855 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

rcp 
阅读更多
我们知道,Title是在ApplicationWorkbenchWindowAdvisor里面通过

 
  1. public void preWindowOpen() {  
  2.      IWorkbenchWindowConfigurer configurer = getWindowConfigurer();  
  3.      configurer.setInitialSize(new Point(600500));  
  4.      configurer.setShowCoolBar(false);  
  5.      configurer.setShowStatusLine(true);  
  6.      configurer.setShowProgressIndicator(true);  
  7.      configurer.setTitle(xxx);  
  8.  }  

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

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

 
  1. public static void changeAppTitle(String newTitle) {  
  2.         Display display = Display.getDefault();  
  3.         if (display != null) {  
  4.                 // Look at all the shells and pick the first one  
  5.                 // that is a workbench window.  
  6.                 Shell shells[] = display.getShells();  
  7.                 for (int i = 0; i < shells.length; i++) {  
  8.                         Object data = shells[i].getData();  
  9.                         // Check whether this shell points to the
  10. // Application main window's shell 
  11.                         if (data instanceof IWorkbenchWindow) {  
  12.                                 shells[i].setText(newTitle);  
  13.                                 break;  
  14.                         }  
  15.                 }  
  16.         }  
  17. }  


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

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

相关推荐

Global site tag (gtag.js) - Google Analytics