在GEF中實(shí)現(xiàn)帶content assist的Directedit

          GEF中自帶有Directeditrequest,所以實(shí)現(xiàn)Directedit還是比較容易的,八進(jìn)制的gef例子里面就有實(shí)現(xiàn).但我在給directedit加上content assist的時(shí)候卻發(fā)現(xiàn)由一個(gè)小bug不太好弄,費(fèi)了兩天才搞定,現(xiàn)在先記下來(lái),以供參考
            directedit是通過(guò)一個(gè)text celleditor來(lái)實(shí)現(xiàn)編輯功能的,所以可以在directeditmanager類(lèi)里面的initCellEditor方法里面加上ContentAssistHandler來(lái)實(shí)現(xiàn)auto complete.但是加上去之后卻發(fā)現(xiàn)有一個(gè)問(wèn)題:不支持用鼠標(biāo)來(lái)選擇proposal.只能用鍵盤(pán)上的上下箭頭來(lái)選擇.雖然也可以用,但是終究不是那么的人性化.
            為了修復(fù)這個(gè)bug,走了不少的彎路,一開(kāi)始以為是contentassist的問(wèn)題,因?yàn)樗莇eprecated,所以換了3.3里面的assist api,發(fā)現(xiàn)還是不行.后來(lái)才知道是因?yàn)閏elleditor有一個(gè)focus listener,當(dāng)用戶點(diǎn)擊proposals 來(lái)選擇一行的時(shí)候,celleditor的focus就lost了,就會(huì)調(diào)用focusLost方法,導(dǎo)致directedit編輯失敗.所以我重寫(xiě)了celleditor的focusLost方法,把它設(shè)成當(dāng)focus在contentassist的popup dialog就什么都不干,否則調(diào)用父類(lèi)的focusLost方法.理論上是一個(gè)好的解決方法,但是contentassist的hasPopupFocus居然一直都返回false,這個(gè)方法也失敗了.
             最后,在bug.eclipse.org上面有人提到GMF里面的TextDirectEditManager是可以做到用鼠標(biāo)選擇proposal的,于是又去看gmf的這個(gè)類(lèi),它也是繼承自DirectEditManager,不過(guò)它消除這個(gè)bug不是在listener上作文章,而是在commit方法里面,在這個(gè)方法里面判斷popup dialog是否是active的,如果是的話則給celleditor加上deactive lock,不允許它deactive,這樣來(lái)實(shí)現(xiàn)用鼠標(biāo)選擇proposal.
          下面是TextDirectEditManager的方法commit里面的部分代碼:

          Shell activeShell = Display.getCurrent().getActiveShell();
                  if (activeShell != null
                      && getCellEditor().getControl().getShell().equals(
                          activeShell.getParent())) {
                      Control[] children = activeShell.getChildren();
                      if (children.length == 1 && children[0] instanceof Table) {
                          /*
                           * CONTENT ASSIST: focus is lost to the content assist pop up -
                           * stay in focus
                           */
                          getCellEditor().getControl().setVisible(true);
                          ((MyTextCellEditor) getCellEditor()).setDeactivationLock(true);
                          return;
                      }
                  }

            下面是MyTextCellEditor里面對(duì)于deactive lock的應(yīng)用,MyTextCellEditor的deactive之前會(huì)判斷一下deactive lock是否為true:
          public boolean isDeactivationLocked() {
            return deactivationLock;
           }
           public void deactivate() {
            if (! isDeactivationLocked())
             super.deactivate();
            setDeactivationLock(false);
           }
           

           public void setDeactivationLock(boolean deactivationLock) {
            this.deactivationLock = deactivationLock;
           }

          posted on 2008-08-05 17:09 小牛小蝦 閱讀(1121) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: 在GEF中實(shí)現(xiàn)帶content assist的Directedit[未登錄](méi) 2008-08-06 08:56 寒武紀(jì)

          不錯(cuò)!  回復(fù)  更多評(píng)論   


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章檔案

          eclipse

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 五原县| 汤原县| 甘肃省| 衡水市| 宁国市| 镇安县| 紫金县| 博客| 德兴市| 兴隆县| 克什克腾旗| 杨浦区| 仁化县| 五峰| 柏乡县| 霍林郭勒市| 启东市| 镇沅| 巴林右旗| 潜江市| 扬中市| 彰化市| 丰原市| 长沙市| 固安县| 谢通门县| 重庆市| 上蔡县| 遂川县| 元氏县| 内黄县| 定州市| 抚松县| 香港 | 上栗县| 尖扎县| 鹤岗市| 岐山县| 荃湾区| 辽宁省| 邳州市|