I'm using a ContentProposalAdapter to开发者_如何学C auto completion of a textbox, it work's OK, but I want change its appearance like font or background color of popup, and more, I searched but I can't find any ContentProposalAdapter's method for doing these stuff. how can i change the appearance of a ContentProposalAdapter?
I don't have any experiences with this jface part, but when you check the documentation, you can find method openProposalPopup
(see docs)
This class provides some overridable methods to allow clients to manually control the popup. However, most of the implementation remains private.
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.
If you check code of this method, you'll find
/**
* 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);
}
The code creates ContentProposalPopup
instance, which manage the appearance of popup widget and few other things (see source code of whole ContentProposalAdapeter class).
So if you'll create new class which will override openProposalPopup()
and will use your own ContentProposalPopup
, you could manage the appearance as you want..
We had issues with the ContentProposalAdapter
, too, and ended up copy-pasting it, then modified according to our needs.
精彩评论