動態改變 Eclipse RCP 應用程式的標題

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.