2011-09-02 41 views
2

我正在使用ContentProposalAdapter來自動完成文本框,它的工作正常,但我想改變其外觀像彈出式的字體或背景顏色,等等,我搜索了但我不能找到任何ContentProposalAdapter的方法來做這些事情。我如何改變一個ContentProposalAdapter的外觀?如何改變ContentProposalAdapter的外觀

回答

3

我沒有這個JFace的一部分的任何經驗,但是當你查看文檔,你可以找到方法openProposalPopupsee docs

這個類提供了一些重寫的​​方法,以允許客戶端手動控制彈出。但是,大部分實施仍然是私人的。

打開提案彈出窗口並顯示提案提供者提供的提案。此方法立即返回。也就是說,它不會等待提案被選中。子類使用此方法顯式調用彈出窗口的打開。如果沒有要顯示的提議,則彈出窗口不會打開併發出嘟嘟聲。

如果選中該方法的代碼,你會發現

/** 
* Open the proposal popup and display the proposals provided by the 
* proposal provider. If there are no proposals to be shown, do not show the 
* popup. This method returns immediately. That is, it does not wait for the 
* popup to open or a proposal to be selected. 
* 
* @param autoActivated 
*   a boolean indicating whether the popup was autoactivated. If 
*   false, a beep will sound when no proposals can be shown. 
*/ 
private void openProposalPopup(boolean autoActivated) { 
    if (isValid()) { 
     if (popup == null) { 
      // Check whether there are any proposals to be shown. 
      recordCursorPosition(); // must be done before getting proposals 
      IContentProposal[] proposals = getProposals(); 
      if (proposals.length > 0) { 
       if (DEBUG) { 
        System.out.println("POPUP OPENED BY PRECEDING EVENT"); //$NON-NLS-1$ 
       } 
       recordCursorPosition(); 
       popup = new ContentProposalPopup(null, proposals); 
       popup.open(); 
       popup.getShell().addDisposeListener(new DisposeListener() { 
        public void widgetDisposed(DisposeEvent event) { 
         popup = null; 
        } 
       }); 
       internalPopupOpened(); 
       notifyPopupOpened(); 
      } else if (!autoActivated) { 
       getControl().getDisplay().beep(); 
      } 
     } 
    } 
} 

/** 
* Open the proposal popup and display the proposals provided by the 
* proposal provider. This method returns immediately. That is, it does not 
* wait for a proposal to be selected. This method is used by subclasses to 
* explicitly invoke the opening of the popup. If there are no proposals to 
* show, the popup will not open and a beep will be sounded. 
*/ 
protected void openProposalPopup() { 
    openProposalPopup(false); 
} 

的代碼創建ContentProposalPopup實例,它管理彈出窗口小部件和其他一些東西(see source code of whole ContentProposalAdapeter class)的外觀。

因此,如果您將創建新的類,它會覆蓋openProposalPopup(),將使用自己的ContentProposalPopup,你可以,只要你想管理的外觀..

+0

我明白了你的想法,但是有一個問題,這個方法使用彈出對象,它是私有的,子類沒有任何訪問權限。 – Hekmatof

+0

當然,你必須編寫你自己的類,並在override'openProposalPopup()'方法中使用它。但是你可以使用原來的'ContentProposalPopup'類的一些代碼,不需要編寫整個類,只需要改變你想要的東西,並使用你的實現.. – Sorceror

+0

我認爲我應該改變popup對象的屬性來改變彈出窗口的外觀。如果我是對的,我應該可以訪問彈出對象 – Hekmatof

1

我們有問題與ContentProposalAdapter,也和最終副本 - 根據我們的需要進行修改。