<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    邋遢居

    我的Java天堂

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      61 Posts :: 2 Stories :: 90 Comments :: 0 Trackbacks

    大家肯定都知道在Eclipse中獲得當前活動的workbenchWindow可以采用如下的方式來完成。

    PlatformUI.getWorkbench().getActiveWorkbenchWindow()

    Plugin類中) getDefault().getWorkbench().getActiveWorkbenchWindow() 。一般情況下這兩個方式能夠很好的工作。但是突然有一天發現他不能工作了。郁悶我都不行了。察看了一下變量如下圖display.jpg

    這個activatedWindow明明有啊,怎么就取不到呢。

    打開代碼一看,看到 org.eclipse.ui.internal.Workbench 類中的 getActiveWorkbenchWindow 方法。

    public ?IWorkbenchWindow?getActiveWorkbenchWindow()?{
    ????????
    // ?Return?null?if?called?from?a?non-UI?thread.
    ????????
    // ?This?is?not?spec'ed?behaviour?and?is?misleading,?however?this?is?how
    ????????
    // ?it
    ????????
    // ?worked?in?2.1?and?we?cannot?change?it?now.
    ????????
    // ?For?more?details,?see?[Bug?57384]?[RCP]?Main?window?not?active?on
    ????????
    // ?startup
    ???????? if ?(Display.getCurrent()? == ? null )?{
    ????????????
    return ? null ;
    ????????}

    ????????
    // ?Look?at?the?current?shell?and?up?its?parent
    ????????
    // ?hierarchy?for?a?workbench?window.
    ????????Control?shell? = ?display.getActiveShell();
    ????????
    while ?(shell? != ? null )?{
    ????????????Object?data?
    = ?shell.getData();
    ????????????
    if ?(data? instanceof ?IWorkbenchWindow)?{
    ????????????????
    return ?(IWorkbenchWindow)?data;
    ????????????}
    ????????????shell?
    = ?shell.getParent();
    ????????}

    ????????
    // ?Look?for?the?window?that?was?last?known?being
    ????????
    // ?the?active?one
    ????????WorkbenchWindow?win? = ?getActivatedWindow();
    ????????
    if ?(win? != ? null )?{
    ????????????
    return ?win;
    ????????}

    ????????
    // ?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();
    ????????????
    if ?(data? instanceof ?IWorkbenchWindow)?{
    ????????????????
    return ?(IWorkbenchWindow)?data;
    ????????????}
    ????????}

    ????????
    // ?Can't?find?anything!
    ???????? return ? null ;
    ????}

    程序跑到 Display.getCurrent() 這一絕句就給我掉鏈子(返回了一個 null )。就是他,就是他了!到網上 google 了一下。看看在什么狀況下他會返回一個 null. http://wiki.eclipse.org/index.php/FAQ_How_do_I_get_a_Display_instance%3F 找到了。

    他說, Display 永遠和創建他的線程聯系在一起,并且一個線程擁有一個活動的 Display 。在創立 Display 的線程中可可以通過 Display.getCurrent() 獲得當前活動的 Display 。如果出了這個線程就看不到這個 Display 了。如果有的線程不擁有 Display ,那它的 Display.getCurrent() 就只能得到 null 了。

    回頭看了一下我的代碼,我是在新建的線程中啟動了調用了這個方法。難怪他不給面子呢!


    參考文獻:

    http://wiki.eclipse.org/index.php/FAQ_How_do_I_get_a_Display_instance%3F

    http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Display.html

    posted on 2006-12-04 15:01 Jet Geng 閱讀(2669) 評論(0)  編輯  收藏 所屬分類: Eclipse
    主站蜘蛛池模板: 久久国产乱子精品免费女| 亚洲国产成人久久综合| 中文毛片无遮挡高清免费| 亚洲第一成人影院| 永久免费观看黄网站| 四虎影在线永久免费四虎地址8848aa | 成人无码WWW免费视频| 国产综合亚洲专区在线| 中文字幕免费视频精品一| 中国亚洲女人69内射少妇| 成人A毛片免费观看网站| 亚洲综合伊人久久大杳蕉| 两个人看的www高清免费视频 | 国产精品亚洲精品爽爽| 四虎永久精品免费观看| 一级做a爰片久久毛片免费陪| 免费一级毛片不卡不收费| 麻豆69堂免费视频| 亚洲五月综合缴情在线观看| 国产麻豆一精品一AV一免费| 久久久亚洲AV波多野结衣| 卡1卡2卡3卡4卡5免费视频| 美女啪啪网站又黄又免费| 久久久久久亚洲精品不卡| 久久青草精品38国产免费| 亚洲18在线天美| 一级毛片直播亚洲| 中文字幕无码免费久久| 亚洲人成7777影视在线观看| 国产精品国产午夜免费福利看| 国产日韩久久免费影院 | h视频在线观看免费| 久久精品国产亚洲AV网站| 黄页网站在线看免费| 免费毛片毛片网址| 亚洲美女大bbbbbbbbb| 免费成人午夜视频| 99久久久国产精品免费蜜臀| 国产精品亚洲а∨天堂2021 | 你懂的免费在线观看网站| www.亚洲成在线|