Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Filtering proposals made by ReferenceProposalCreator
Filtering proposals made by ReferenceProposalCreator [message #558687] Tue, 14 September 2010 01:48 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
I have a use case where I wanted to limit the proposals given by the
RefrenceProposalCreator (used by
AbstractJavaBasedContentProposalProvider) as it often provides proposals
that the validator later will flag as errors.

Is the correct approach to bind my own ReferenceProposalCreator derived
from AbstractJavaBasedContentProposalProvider.ReferenceProposalCr eator
and override:

public void lookupCrossReference(EObject model, EReference reference,
ICompletionProposalAcceptor acceptor,
Predicate<IEObjectDescription> filter, Function<IEObjectDescription,
ICompletionProposal> proposalFactory)

Or is there some other preferred way of doing this?
Is it possible to use the Predicate for this? If so, how can I configure
a particular filter to apply for a particular proposal generation?

Regards
- henrik
Re: Filtering proposals made by ReferenceProposalCreator [message #558689 is a reply to message #558687] Tue, 14 September 2010 01:55 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
One alternative seems to be to configure it with a different scope
provider than the default. It does however inject just IScopeProvider so
it does not seem possible to give the existing proposal provider a
different scope provider than what is used elsewhere.

Handling this with a specialization of the scope provider seems like the
easiest way to implement the filtering.

Should I derive a ReferenceProposalProvider just for the sake of
overriding the scope provider or does someone have any other suggestions?

Regards
- henrik

On 9/14/10 3:48 AM, Henrik Lindberg wrote:
> Hi,
> I have a use case where I wanted to limit the proposals given by the
> RefrenceProposalCreator (used by
> AbstractJavaBasedContentProposalProvider) as it often provides proposals
> that the validator later will flag as errors.
>
> Is the correct approach to bind my own ReferenceProposalCreator derived
> from AbstractJavaBasedContentProposalProvider.ReferenceProposalCr eator
> and override:
>
> public void lookupCrossReference(EObject model, EReference reference,
> ICompletionProposalAcceptor acceptor,
> Predicate<IEObjectDescription> filter, Function<IEObjectDescription,
> ICompletionProposal> proposalFactory)
>
> Or is there some other preferred way of doing this?
> Is it possible to use the Predicate for this? If so, how can I configure
> a particular filter to apply for a particular proposal generation?
>
> Regards
> - henrik
Re: Filtering proposals made by ReferenceProposalCreator [message #558702 is a reply to message #558689] Tue, 14 September 2010 06:25 Go to previous messageGo to next message
Nimesh Mising name is currently offline Nimesh Mising nameFriend
Messages: 23
Registered: March 2010
Junior Member
Hi,

I have achieved something similar overriding method in <GrammarName>ProposalPropvider class. I have also added validation checks so that if the model is edited by typing instead of using proposal then it would still throw an error. Not sure whether this is appropriate mechanism but here it is.

	@Override
	public void completeRecordKey_RecordKeyProperties(EObject model,
			Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		final RecordKey recordKey = (RecordKey)model;
		final Entity entityOfRecordKey = (Entity)model.eContainer();
		lookupCrossReference((CrossReference) assignment.getTerminal(),
				context, acceptor, new Predicate<IEObjectDescription>() {
					@Override
					public boolean apply(IEObjectDescription input) {
						SimpleProperty objectProperty = (SimpleProperty)input.getEObjectOrProxy();
						return (objectProperty.eContainer() == entityOfRecordKey && !exists(objectProperty, recordKey));
					}
					
					private boolean exists(SimpleProperty objectProperty, RecordKey recordKey) {
						return recordKey.getRecordKeyProperties().contains(objectProperty);
					}
				});
	}


And in my <Grammar>JavaValidator class I have added a method.
	@Check
	public void checkNoDuplicatePropertiesInRecordKey(RecordKey recordKey) {
		Set<SimpleProperty> uniqueProperties = new HashSet<SimpleProperty>(recordKey.getRecordKeyProperties());
		if (uniqueProperties.size() != recordKey.getRecordKeyProperties().size()) {
			error("Duplicate properties in record key [" + recordKey.getName() + "] definition", EntityPackage.RECORD_KEY);
		}
	}


Thanks.
Regards,
- Nimesh
Re: Filtering proposals made by ReferenceProposalCreator [message #558709 is a reply to message #558689] Tue, 14 September 2010 07:21 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

my suggestion would be to take Nimesh's approach. Use scoping for the visibility of elements, use validation to check semantic constraints and give useful feedback to the user, for content assist use the existing lookupCrossReference method that has the filter parameter to select those elements from the scope that the user should see.

You should not restrict the visibility of elements too severely, otherwise the user will get "strange" unable-to-resolve-reference-errors.

Alex
Re: Filtering proposals made by ReferenceProposalCreator [message #558814 is a reply to message #558709] Tue, 14 September 2010 14:00 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Thanks,
I was over-complicating it. Just overriding the appropriate 'complete'
method, and not call the super method, and instead call
'lookupCrossReferences' with a suitable filter seems to be the best
approach.

- henrik

On 9/14/10 9:21 AM, Alexander Nittka wrote:
> Hi,
>
> my suggestion would be to take Nimesh's approach. Use scoping for the
> visibility of elements, use validation to check semantic constraints and
> give useful feedback to the user, for content assist use the existing
> lookupCrossReference method that has the filter parameter to select
> those elements from the scope that the user should see.
>
> You should not restrict the visibility of elements too severely,
> otherwise the user will get "strange" unable-to-resolve-reference-errors.
>
> Alex
Previous Topic:Problem with unordered groups
Next Topic:Xtext editor loading non-resource data
Goto Forum:
  


Current Time: Fri Mar 29 11:22:02 GMT 2024

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

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

Back to the top