Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » SimpleContentProposalProvider with LabelProvider gives a wrong proposal text
SimpleContentProposalProvider with LabelProvider gives a wrong proposal text [message #333432] Thu, 11 December 2008 07:21 Go to next message
Kirill Zotkin is currently offline Kirill ZotkinFriend
Messages: 21
Registered: July 2009
Junior Member
Hello!
I making a content assist for a text field.

private void createContentAssist(Text field) {
ControlDecoration dec = new ControlDecoration(field, SWT.CENTER
| SWT.LEAD);
dec.setImage(getContentAssistDecoration().getImage());
dec.setDescriptionText(getContentAssistDecoration().getDescr iption()
+ "(" + CONTENT_ASSIST_KEYSTROKE + ")");
dec.setShowOnlyOnFocus(true);

char[] autoActivationCharacters = new char[] { '#', '(' };
KeyStroke keyStroke = null;
try {
keyStroke = KeyStroke.getInstance(CONTENT_ASSIST_KEYSTROKE);
} catch (ParseException e) {
}
ContentProposalAdapter adapter = new ContentProposalAdapter(field,
new TextContentAdapter(), new SimpleContentProposalProvider(
toArrayOfStrings(getTreesList())), keyStroke,
autoActivationCharacters);
adapter.setLabelProvider(getLabelProvider());

}

private static final String CONTENT_ASSIST_KEYSTROKE = "Ctrl+Space";

private FieldDecoration getContentAssistDecoration() {
return FieldDecorationRegistry.getDefault().getFieldDecoration(
FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
}

private String[] toArrayOfStrings(Object[] objects) {
String[] result = new String[objects.length];
for (int i = 0; i < objects.length; i++)
result[i] = objects[i].toString();
return result;
}

and when launching it gives me icons in content assist (that's why i
needed a LabelProvider) and wrong text, something like:
org.eclipse.jface.fieldassist.SimpleContentProposalProvider$1@4ca6b6
org.eclipse.jface.fieldassist.SimpleContentProposalProvider$1@16b904d
org.eclipse.jface.fieldassist.SimpleContentProposalProvider$1@cec78d

getText in my LabelProvider uses toString().
this happens because of this code:

public class ContentProposalAdapter {
...
/*
* Get the string for the specified proposal. Always return a String of
* some kind.
*/
private String getString(IContentProposal proposal) {
if (proposal == null) {
return EMPTY;
}
if (labelProvider == null) {
return proposal.getLabel() == null ? proposal.getContent()
: proposal.getLabel();
}
return labelProvider.getText(proposal);
}

proposal is defined in SimpleContentProposalProvider like that:

public class SimpleContentProposalProvider implements
IContentProposalProvider {
...
/*
* Make an IContentProposal for showing the specified String.
*/
private IContentProposal makeContentProposal(final String proposal) {
return new IContentProposal() {
public String getContent() {
return proposal;
}

public String getDescription() {
return null;
}

public String getLabel() {
return null;
}

public int getCursorPosition() {
return proposal.length();
}
};
}
}

so this proposal doesn't return content in toString().
i've bypassed this by changing a getText() in my LabelProvider to:

public String getText(Object element) {
if (element instanceof IContentProposal) {
IContentProposal proposal = ((IContentProposal) element);
return proposal.getLabel() == null ? proposal.getContent()
: proposal.getLabel();
}

return super.getText(element);
}

but it is not quite right, isn't it?

and i suggest to add this code to SimpleContentProposalProvider:

private IContentProposal makeContentProposal(final String proposal) {
return new IContentProposal() {
...
public String toString() {
return proposal;
}
};
}


Thanks

Kurill
Re: SimpleContentProposalProvider with LabelProvider gives a wrong proposal text [message #333433 is a reply to message #333432] Thu, 11 December 2008 07:26 Go to previous messageGo to next message
Remy Suen is currently offline Remy SuenFriend
Messages: 462
Registered: July 2009
Senior Member
Kirill Zotkin wrote:
> but it is not quite right, isn't it?
>
> and i suggest to add this code to SimpleContentProposalProvider:
>
> private IContentProposal makeContentProposal(final String proposal) {
> return new IContentProposal() {
> ...
> public String toString() {
> return proposal;
> }
> };
> }

Please file an enhancement request at bugzilla.
http://bugs.eclipse.org/bugs/

Remy
Re: SimpleContentProposalProvider with LabelProvider gives a wrong proposal text [message #333434 is a reply to message #333433] Thu, 11 December 2008 10:00 Go to previous message
Kirill Zotkin is currently offline Kirill ZotkinFriend
Messages: 21
Registered: July 2009
Junior Member
Remy Chi Jian Suen wrote:

> Kirill Zotkin wrote:
>> but it is not quite right, isn't it?
>>
>> and i suggest to add this code to SimpleContentProposalProvider:
>>
>> private IContentProposal makeContentProposal(final String proposal) {
>> return new IContentProposal() {
>> ...
>> public String toString() {
>> return proposal;
>> }
>> };
>> }

> Please file an enhancement request at bugzilla.
> http://bugs.eclipse.org/bugs/

> Remy

https://bugs.eclipse.org/bugs/show_bug.cgi?id=258412

Kurill
Previous Topic:Cannot run program "make": Unknown reason
Next Topic:Uninstall plugin
Goto Forum:
  


Current Time: Thu Dec 26 18:00:35 GMT 2024

Powered by FUDForum. Page generated in 0.03605 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top