Home » Modeling » GMF (Graphical Modeling Framework) » IContentAssistProcessor
IContentAssistProcessor [message #56601] |
Wed, 27 September 2006 16:23  |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
Following Michael Golubev's suggestion on a previous thread, I've created
a completion processor using the code below.
However, the method computeCompletionProposals doesn't get called. Other
methods such as getCompletionProposalAutoActivationCharacters get called.
There's also a pop up indicating content assist, but nothing happens when
pressing ctrl-space.
Any suggestions?
thanks in advance,
vlad
public class Bluenose2ContentAssistProcessor implements IContentAssistProcessor {
private static final ICompletionProposal[] NO_PROPOSALS= new ICompletionProposal[0];
private static final IContextInformation[] NO_CONTEXTS= new IContextInformation[0];
private char[] characters;
/**
* list of possible values
*/
private List values;
public Bluenose2ContentAssistProcessor(List values) {
this.values = values;
characters = new char[values.size()];
Iterator it = values.iterator();
int i = 0;
while (it.hasNext()) {
String value = (String) it.next();
characters[i] = value.charAt(0);
}
}
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
int offset) {
try {
String prefix= getPrefix(viewer, offset);
if (prefix == null || prefix.length() == 0)
return NO_PROPOSALS;
List suggestions= getSuggestions(prefix);
List result= new ArrayList();
for (Iterator it= suggestions.iterator(); it.hasNext();) {
String string= (String) it.next();
if (string.length() > 0)
result.add(createProposal(string, prefix, offset));
}
return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]);
} catch (BadLocationException x) {
// ignore and return no proposals
return NO_PROPOSALS;
}
}
private ICompletionProposal createProposal (String string, String prefix, int offset) {
//need to adjust these parameters
return new CompletionProposal(string, offset, string.length(), offset + string.length());
}
/**
*
* @param prefix
* @return list of values beginning with <code>prefix</code>
*/
private List getSuggestions(String prefix) {
List suggestions = new ArrayList();
Iterator it = values.iterator();
while (it.hasNext()) {
String value = (String) it.next();
if (value.startsWith(prefix))
suggestions.add(new String(value));
}
return suggestions;
}
/**
*
* @param viewer
* @param offset
* @return the text input by the user
* @throws BadLocationException
*/
private String getPrefix(ITextViewer viewer, int offset) throws BadLocationException {
IDocument doc= viewer.getDocument();
if (doc == null || offset > doc.getLength())
return null;
int length= 0;
while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)))
length++;
return doc.get(offset + 1, length);
}
public IContextInformation[] computeContextInformation(ITextViewer viewer,
int offset) {
return NO_CONTEXTS;
}
public char[] getCompletionProposalAutoActivationCharacters() {
return characters;
}
public char[] getContextInformationAutoActivationCharacters() {
return characters;
}
public IContextInformationValidator getContextInformationValidator() {
return null;
}
public String getErrorMessage() {
return null;
}
}
|
|
|
Re: IContentAssistProcessor [message #56629 is a reply to message #56601] |
Wed, 27 September 2006 16:56   |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
I've gone past my initial problem. Now I get this exception:
Exception in thread "AutoAssist Delay" java.lang.NullPointerException
at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAs sistListener.showAssist(ContentAssistant.java:327)
at org.eclipse.jface.text.contentassist.ContentAssistant$AutoAs sistListener.run(ContentAssistant.java:252)
at java.lang.Thread.run(Thread.java:595)
Should I give up? Does anyone have integrated a content assist processor
for a structural feature in GMF?
thanks
vlad
On Wed, 27 Sep 2006 16:23:05 -0400, Vlad Ciubotariu wrote:
> Following Michael Golubev's suggestion on a previous thread, I've created
> a completion processor using the code below.
>
> However, the method computeCompletionProposals doesn't get called. Other
> methods such as getCompletionProposalAutoActivationCharacters get called.
> There's also a pop up indicating content assist, but nothing happens when
> pressing ctrl-space.
>
> Any suggestions?
>
> thanks in advance,
> vlad
>
>
>
> public class Bluenose2ContentAssistProcessor implements IContentAssistProcessor {
>
> private static final ICompletionProposal[] NO_PROPOSALS= new ICompletionProposal[0];
> private static final IContextInformation[] NO_CONTEXTS= new IContextInformation[0];
> private char[] characters;
>
> /**
> * list of possible values
> */
> private List values;
>
> public Bluenose2ContentAssistProcessor(List values) {
> this.values = values;
> characters = new char[values.size()];
> Iterator it = values.iterator();
> int i = 0;
> while (it.hasNext()) {
> String value = (String) it.next();
> characters[i] = value.charAt(0);
> }
>
>
> }
>
> public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
> int offset) {
>
> try {
> String prefix= getPrefix(viewer, offset);
> if (prefix == null || prefix.length() == 0)
> return NO_PROPOSALS;
>
> List suggestions= getSuggestions(prefix);
>
> List result= new ArrayList();
> for (Iterator it= suggestions.iterator(); it.hasNext();) {
> String string= (String) it.next();
> if (string.length() > 0)
> result.add(createProposal(string, prefix, offset));
> }
>
> return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]);
>
> } catch (BadLocationException x) {
> // ignore and return no proposals
> return NO_PROPOSALS;
> }
>
> }
>
> private ICompletionProposal createProposal (String string, String prefix, int offset) {
> //need to adjust these parameters
> return new CompletionProposal(string, offset, string.length(), offset + string.length());
> }
>
> /**
> *
> * @param prefix
> * @return list of values beginning with <code>prefix</code>
> */
> private List getSuggestions(String prefix) {
> List suggestions = new ArrayList();
> Iterator it = values.iterator();
> while (it.hasNext()) {
> String value = (String) it.next();
> if (value.startsWith(prefix))
> suggestions.add(new String(value));
> }
>
> return suggestions;
>
> }
>
> /**
> *
> * @param viewer
> * @param offset
> * @return the text input by the user
> * @throws BadLocationException
> */
> private String getPrefix(ITextViewer viewer, int offset) throws BadLocationException {
> IDocument doc= viewer.getDocument();
> if (doc == null || offset > doc.getLength())
> return null;
>
> int length= 0;
> while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)))
> length++;
>
> return doc.get(offset + 1, length);
> }
>
>
>
> public IContextInformation[] computeContextInformation(ITextViewer viewer,
> int offset) {
> return NO_CONTEXTS;
> }
>
> public char[] getCompletionProposalAutoActivationCharacters() {
> return characters;
> }
>
> public char[] getContextInformationAutoActivationCharacters() {
> return characters;
> }
>
> public IContextInformationValidator getContextInformationValidator() {
> return null;
> }
>
> public String getErrorMessage() {
> return null;
> }
>
> }
|
|
|
Re: IContentAssistProcessor [message #57345 is a reply to message #56601] |
Thu, 28 September 2006 17:13  |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
I've managed to get this thing to work using the field assist framework
and overriding a little bit in initCellEditor() of TextDirectEditManager.
cheers
vlad
On Wed, 27 Sep 2006 16:23:05 -0400, Vlad Ciubotariu wrote:
> Following Michael Golubev's suggestion on a previous thread, I've created
> a completion processor using the code below.
>
> However, the method computeCompletionProposals doesn't get called. Other
> methods such as getCompletionProposalAutoActivationCharacters get called.
> There's also a pop up indicating content assist, but nothing happens when
> pressing ctrl-space.
>
> Any suggestions?
>
> thanks in advance,
> vlad
>
>
>
> public class Bluenose2ContentAssistProcessor implements IContentAssistProcessor {
>
> private static final ICompletionProposal[] NO_PROPOSALS= new ICompletionProposal[0];
> private static final IContextInformation[] NO_CONTEXTS= new IContextInformation[0];
> private char[] characters;
>
> /**
> * list of possible values
> */
> private List values;
>
> public Bluenose2ContentAssistProcessor(List values) {
> this.values = values;
> characters = new char[values.size()];
> Iterator it = values.iterator();
> int i = 0;
> while (it.hasNext()) {
> String value = (String) it.next();
> characters[i] = value.charAt(0);
> }
>
>
> }
>
> public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
> int offset) {
>
> try {
> String prefix= getPrefix(viewer, offset);
> if (prefix == null || prefix.length() == 0)
> return NO_PROPOSALS;
>
> List suggestions= getSuggestions(prefix);
>
> List result= new ArrayList();
> for (Iterator it= suggestions.iterator(); it.hasNext();) {
> String string= (String) it.next();
> if (string.length() > 0)
> result.add(createProposal(string, prefix, offset));
> }
>
> return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]);
>
> } catch (BadLocationException x) {
> // ignore and return no proposals
> return NO_PROPOSALS;
> }
>
> }
>
> private ICompletionProposal createProposal (String string, String prefix, int offset) {
> //need to adjust these parameters
> return new CompletionProposal(string, offset, string.length(), offset + string.length());
> }
>
> /**
> *
> * @param prefix
> * @return list of values beginning with <code>prefix</code>
> */
> private List getSuggestions(String prefix) {
> List suggestions = new ArrayList();
> Iterator it = values.iterator();
> while (it.hasNext()) {
> String value = (String) it.next();
> if (value.startsWith(prefix))
> suggestions.add(new String(value));
> }
>
> return suggestions;
>
> }
>
> /**
> *
> * @param viewer
> * @param offset
> * @return the text input by the user
> * @throws BadLocationException
> */
> private String getPrefix(ITextViewer viewer, int offset) throws BadLocationException {
> IDocument doc= viewer.getDocument();
> if (doc == null || offset > doc.getLength())
> return null;
>
> int length= 0;
> while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)))
> length++;
>
> return doc.get(offset + 1, length);
> }
>
>
>
> public IContextInformation[] computeContextInformation(ITextViewer viewer,
> int offset) {
> return NO_CONTEXTS;
> }
>
> public char[] getCompletionProposalAutoActivationCharacters() {
> return characters;
> }
>
> public char[] getContextInformationAutoActivationCharacters() {
> return characters;
> }
>
> public IContextInformationValidator getContextInformationValidator() {
> return null;
> }
>
> public String getErrorMessage() {
> return null;
> }
>
> }
|
|
|
Goto Forum:
Current Time: Wed Apr 30 03:04:06 EDT 2025
Powered by FUDForum. Page generated in 0.03356 seconds
|