Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

Java, the OLPC, and community responsibility

The "One Laptop Per Child" project has a great device ready to ship, but there's no Java on there. Let's think about working together to put Java on OLPC!
Replies: 5 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Text Field Content Proposals in JFace

At 12:38 AM on Oct 26, 2006, R.J. Lorimer Javalobby Editors wrote:

A particularly nice feature of GUI applications is the ability to provide context-sensitive rich field assist for text-fields. As an example, consider this picture of the 'new class' dialog in the Eclipse Java support:

In the past, I think a lot of applications have avoided this user-friendly feature in many cases because of (lack of) support from their widget toolkit. It is so easy to implement with JFace, however, you'd be mistaken not to (I will say, however, that too much of any good thing is in turn a bad thing).

The heart of content proposals is the org.eclipse.jface.fieldassist.ContentProposalAdapter class. Binding content proposals to a text field is trivial:

Text t = new Text(parent, SWT.BORDER); // your SWT text field
ContentProposalAdapter adapter = new ContentProposalAdapter(
	t, 
	new TextContentAdapter(), 
	new SimpleContentProposalProvider(new String [] {"A", "B", "C"}),
	null, 
	null);

Amazingly, this is all you have to do to provide simple content proposals to a text field. Now, the configuration above obviously uses a fairly spartan content proposal provider; you can implement a more functional version that checks a list of local file names, looks at the user's last 100 entries, or even connects via web-service to a dictionary website; Eclipse uses a list of class names that can be subclassed in the dialog above, but the options are only bound by the intended input in the text field. In addition, your proposals can be sensitive to the location of the caret as well as the data already entered in to the field (this simple proposal provider will never consider any of those more subtle details).

The two null values represent the activation keystroke and the 'auto-activation' characters respectively. The activation keystroke is typically Ctrl+Space in Eclipse, but you could make it whatever you want in your application. The auto-activation characters in this case is left empty. If you supply values, ONLY those characters would trigger auto-assistance. If you don't, but you have a key-stroke, only the key-stroke will trigger assistance. If neither are supplied (as in the example above), all character input will trigger auto-activation (meaning the content proposal will always be there when you type).

Here is a screenshot of the content proposal in action:

  Click to reply to this thread Reply
1. At 3:54 AM on Nov 9, 2006, Gérald Eggenberger Javalobby Newcomers wrote:

Re: Text Field Content Proposals in JFace

This Feature is very nice. I use it within my application. The only thing i was wondering is how to make the ContentProposalAdapter filtering the first inserted Char too.

When I configure the ContentProposalAdapter to trigger on alphabetical Userinput the First Char will never be filtered for Content Proposal.
  Click to reply to this thread Reply
2. At 2:44 PM on Jan 7, 2007, Przemyslaw Rudzki Javalobby Newcomers wrote:

Re: Text Field Content Proposals in JFace

Did you figure out how to make it work properly. Maybe this should be considered a bug?
  Click to reply to this thread Reply
3. At 5:40 AM on Jan 8, 2007, Gérald Eggenberger Javalobby Newcomers wrote:

Re: Text Field Content Proposals in JFace

Yes, I tought so ... but they're changing a lot at the moment.
I should do some testing in eclipse 3.3m4 with the newer classes, but i haven't yet. (no Time at the moment)

So if you've any further informations about content proposals, let me know.

tnx.
  Click to reply to this thread Reply
4. At 2:44 PM on Oct 5, 2007, Devender Ramasahayam Javalobby Newcomers wrote:

Re: Text Field Content Proposals in JFace

I'm facing a problem while using the ConentProposalAdapter.

I have a text field and adding the ConentProposalAdapter adapter to the text field.
It is showing me the proposals and inserting the text.
But the problem is whatever I type in before pressing CTRL+Space to get proposals those characters are appended to the proposal.
I dont want those characters to be appened to my proposal

thanks In advance

Cheers
Dev
  Click to reply to this thread Reply
5. At 9:15 AM on Dec 2, 2007, Jens Reimann Javalobby Newcomers wrote:

Re: Text Field Content Proposals in JFace

Quite easy ;-)

contentProposalAdapter.setProposalAcceptanceStyle ( ContentProposalAdapter.PROPOSAL_REPLACE );

there are other options as well.

thread.rss_message