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!
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:
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.
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.
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
Text Field Content Proposals in JFace
At 12:38 AM on Oct 26, 2006, R.J. Lorimer
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.ContentProposalAdapterclass. 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:
5 replies so far (
Post your own)
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.
Re: Text Field Content Proposals in JFace
Did you figure out how to make it work properly. Maybe this should be considered a bug?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.
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
Re: Text Field Content Proposals in JFace
Quite easycontentProposalAdapter.setProposalAcceptanceStyle ( ContentProposalAdapter.PROPOSAL_REPLACE );
there are other options as well.