Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [nebula-dev] Re: Search and auto-complete widgets

I agree at some point, that if you want a simple text-field with auto-complete functionality, implementing an IContentProposalProvider and supplying an IContentProposal object for each possible completion feels like a little overkill - especially when the proposals are fixed for a given text-field. I guess, that is the price you have to pay for having a much more general framework.

But considering the following lines of code, which are necessary to set-up an auto-complete text-field, I think that price is not too high ;-)

// --------------- [ code ] ------------------------------------------
Text text = new Text(shell, SWT.NONE);

ContentProposalAdapter adapter = new ContentProposalAdapter(text,
new TextContentAdapter(), new TextProposalProvider(), null, null);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

class TextProposalProvider implements IContentProposalProvider {
   public IContentProposal[] getProposals(String contents, int position) {
       // return possible proposals / completions
   }
}
// ------------------ [ end code ] -----------------------------------

But, of course, there is place for a wrapper for the simplest cases. Maybe something like

// ------------------ [ code ] -------------------------------------
class AutoCompleteText  {
   private String[] proposals;
   ...
   public AutoCompleteText(Composite parent, int style) {
       ContentProposalAdapter adapter = new ContentProposalAdapter(text,
new TextContentAdapter(), new TextProposalProvider(), null, null); adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
   }

   public void setProposals(String[] proposals) {...}
   public Text getControl() {...}
   ...

   class TextProposalProvider implements IContentProposalProvider {
public IContentProposal[] getProposals(String contents, int position) {
           // filter proposals
       }
   }
}
// --------------------- [ end code ] -----------------------------------------------------

I don't know if this would qualify for a Nebula widget, though. But I agree that it would be nice to have a simpler API for the trivial auto-completion cases, although the wrapper classes seem to be quite straight-forward to implement.

Sascha



Michael Krkoska wrote:
I really like the features of jface field assist. But to be honest I
am not very happy with the corresponding API. It seems rather
cumbersome, just look at the sourcecode of the example plug-ins. (You
get a "FieldAssist" menu in Eclipse with a single entry, if you
install these plug-ins, which shows-off the features.)

It seems to me that you need to implement a lot of stuff on top of the
jface field assist API to get your auto complete. That's why I'd still
favor a nebula API which enables you to implement such a common
use-case much more easily.

Currently I am using the autocomplete API of the SWTPlus alpha
version, the predecessor of nebula, which I find easy to use.

What about another wrapper API on top of jface field assist, to make
it more usable? I guess not in nebula, because of the reference to
jface, but I'd like it :)

Bye,
  Michael



ditto :)

can I use it to do auto-completion similar to OpenOffice.org (best
example I can think of) where, rather than dropping a selection list, it
completes the word in place?
can I also use it with multiple, character delimited, fields per text box?

thanks!


Chris Gross wrote:
> Hi Sascha,
>
> You bring up a good point. I wasn't aware of the new field assist added
> to JFace.
>
> -Chris
>
> Sascha Zelzer wrote:
>> Hi,
>>
>> I am very excited about the Nebula project and am looking forward to
>> some great contributions.
>>
>> The only thing which irritates me is the constant mentioning of
>> "auto-complete" widgets, be it text-fields, combos or others. I am
>> just not sure if the creators of such widgets (and the Nebula team)
>> are aware of the package org.eclipse.jface.fieldassist which allows,
>> in a very general way, to attach auto-complete functionality to any
>> widget.
>>
>> I do not want in any way to diminish the efforts of people who
>> implemented such widgets themselves, but for the sake of consistency
>> and not duplicating functionality, these "widgets" can (at least now
>> in Eclipse 3.2) easily by implemented by programmers themselves.
>>
>> If those widgets should be available for Eclipse < 3.2 then, of
>> course, one has the create them "by hand".
>>
>> Just some thoughts...
>>
>>
>> Sascha
_______________________________________________
nebula-dev mailing list
nebula-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/nebula-dev



Back to the top