Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to dynamic filter the content assistant list in XxxProposalProvider?
How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692350] Wed, 15 April 2015 09:04 Go to next message
Bob Tao is currently offline Bob TaoFriend
Messages: 23
Registered: March 2015
Junior Member
Hi all,

I have a ProposalProvider class.
"public class UclProposalProvider extends AbstractUclProposalProvider "

I also implement the complete function, which works.
	public void completeUclInstanceAttribute_Iafield(EObject model,
			Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) 



when I press ctrl+/, it can show the content assistant.
	public void completeUclInstanceAttribute_Iafield(EObject model,
			Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {

in this function , I can get the prefix String(context.getPrefix()) if I input some char before trigger the content assistant.

My problem is that how to refresh the list in the content assistant when I input the char dynamically.
I wish it just dynamically display the item that start with prefix like JDT editor.

I think Xtext support this feature, But I can't find the guide.

Thanks!
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692355 is a reply to message #1692350] Wed, 15 April 2015 09:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

xtext does the prefix filtering automatically thus you should actually do not need to do anything

maybe you can show what you want to achive by an example to get a better idea


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692356 is a reply to message #1692355] Wed, 15 April 2015 09:33 Go to previous messageGo to next message
Bob Tao is currently offline Bob TaoFriend
Messages: 23
Registered: March 2015
Junior Member
Hi Christian,

if it is a cross reference, it is work automatically.
Before I can't use cross reference in this Object, the proposal is created by myself.
this a segment code in the function completeUclInstanceAttribute_Iafield.
EList<UclClassMember> members = ((UclClass) parentUclType)
					.getMembers();
			for (UclClassMember member : members) {
				UclClassField field = (UclClassField) member;

				UclType fieldType = field.getType();
				String replacement = field.getName();
				int cursorPosition = replacement.length();
				if (fieldType instanceof UclEnum) {
					replacement = field.getName() + " : ";
					cursorPosition = replacement.length();
				}

				else if (field.getMaxSize() != null) {
					replacement = field.getName() + "[  ];";
					cursorPosition = replacement.length() - 3;
				} else if (fieldType.getName().equals("Double")
						|| fieldType.getName().equals("Long")
						|| fieldType.getName().equals("Float")
						|| fieldType.getName().equals("Int")
						|| fieldType.getName().equals("String")
						|| fieldType.getName().equals("JavaScript")
						|| fieldType.getName().equals("Boolean")) {
					replacement = field.getName() + " : ";
					cursorPosition = replacement.length();
				} else {
					replacement = field.getName() + "{\n  \n};";
					cursorPosition = replacement.length() - 4;
				}

				String keyExt;
				if (field.getIsRequired() != null) {
					keyExt = "*";
				} else {
					keyExt = "";
				}
				String key = field.getName();
				
				String additional = field.getType().getName() + " "
						+ field.getName();
				if (field.getType().getName().equals("JavaScript")) {
					additional += "\nExample:\naction:\"/src/hello.js\"";
				}
				if(context.getPrefix()!=null && context.getPrefix().length()>0 && key.startsWith(context.getPrefix()))
				{
					ConfigurableCompletionProposal cp = createDalProposal(model,
							replacement, key, keyExt, additional, cursorPosition,
							context);
					
					acceptor.accept(cp);
				}
				else if(context.getPrefix()==null || context.getPrefix().length()==0)
				{
					ConfigurableCompletionProposal cp = createDalProposal(model,
							replacement, key, keyExt, additional, cursorPosition,
							context);
					
					acceptor.accept(cp);
				}
				

it can filter at first time( I have input the prefix before trigger the content assistant).
but it can't refresh when I input the new char if it has been triggered.
thank your reply.
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692357 is a reply to message #1692356] Wed, 15 April 2015 09:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i still cannot reproduce that.

the following Example Works fine for me

Model:
	value=ID
;
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	override completeModel_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		super.completeModel_Value(model, assignment, context, acceptor)
		acceptor.accept(createCompletionProposal("aaa", context))
		acceptor.accept(createCompletionProposal("aab", context))
		acceptor.accept(createCompletionProposal("aba", context))
		acceptor.accept(createCompletionProposal("abb", context))
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692426 is a reply to message #1692356] Wed, 15 April 2015 15:39 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Here you are using the prefix only once. If a char is entered, your
produced proposal will be checked against the new prefix by Xtext. Since
you do this manually, that functionality is lost.

> if(context.getPrefix()!=null && context.getPrefix().length()>0 &&
> key.startsWith(context.getPrefix()))

You may want to set a custom prefix matcher on the produced proposal.
That prefix matcher will be queried afterwards.

See ConfigurableCompletionProposal.setMatcher

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1695394 is a reply to message #1692426] Thu, 14 May 2015 01:29 Go to previous message
Bob Tao is currently offline Bob TaoFriend
Messages: 23
Registered: March 2015
Junior Member
Thank Sebastian!

I solved it according to your help.

		ConfigurableCompletionProposal cp = new ConfigurableCompletionProposal(
				replacementString, replacementOffset, replacementLength,
				cursorPosition, img, displayString, null,
				additionalProposalInfo);
		cp.setMatcher(uclMatcher);


public class UclPrefixMatcher extends PrefixMatcher {

	@Override
	public boolean isCandidateMatchingPrefix(String name, String prefix) {
		return name.regionMatches(true, 0, prefix, 0, prefix.length());
		
	}

}

Previous Topic:Formatter2: formatting merging
Next Topic:Using annotations in DSL
Goto Forum:
  


Current Time: Thu Apr 25 05:59:30 GMT 2024

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

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

Back to the top