bob
bob

Reputation: 1889

Open AutoCompleteField on click

I'm using the Eclipse AWT framework, and I've got a combobox.

I've set the visible amount of items in the combobox to 0, so that clicking the dropdown doesn't show anything (even though the box is populated).

I have an AutoCompleteField on the box, so that anyone typing into the combobox sees the Eclipse-style AutoCompleteField. This works perfectly.

However, I'd like to be able to trigger the AutoCompleteField to appear in certain circumstances, and not just when the user starts typing. For instance, I'd like it to appear when the user clicks the dropdown triangle, so it's like the Eclipse-style AutoCompleteField appears instead of the normal drop-down.

Unfortunately, the AutoCompleteField exposes NO useful methods, and I hardly understand how it works.

How can I get it to appear at whim?

Upvotes: 1

Views: 265

Answers (1)

greg-449
greg-449

Reputation: 111218

I assume you mean the SWT / JFace AutoCompleteField (AWT is the old Java GUI).

AutoCompleteField is only intended for the simplest use of the auto complete, for anything more complex you need to use the lower level classes.

This is what AutoCompleteField sets up:

Control control = your control
IControlContentAdapter controlContentAdapter = your control context adapter
String[] proposals = your proposals

SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(proposals);

proposalProvider.setFiltering(true);

ContentProposalAdapter adapter = new ContentProposalAdapter(control, controlContentAdapter, proposalProvider, null, null);

adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

It is the ContentProposalAdapter that can open the assist as required using the openProposalPopup() method - this is a protected method so would need to use a class derived from ContentProposalAdapter to use it.

ContentProposalAdapter also has parameters for a KeyStroke to activate the assist and a set of auto-activation characters.

Upvotes: 3

Related Questions