Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [solved] Content Assist with "dynamic templates"
[solved] Content Assist with "dynamic templates" [message #642432] Wed, 01 December 2010 10:24 Go to next message
Jonatan Antoni is currently offline Jonatan AntoniFriend
Messages: 18
Registered: December 2010
Location: Frankfurt/Main
Junior Member
Hello,

I have a simple DSL

Model: AbstractObject | InstanzObject;

AbstractObject: 'AbstractObject' name=ID
  '{'
    (propertyDecls+=PropertyDecl)*
  '}';

InstanzObject : 'InstanzObject' name=ID 'implements' base=[AbstractObject]
  '{'
    (propertyDefs+=PropertyDefs)*
  '}';

PropertyDecl: type=TYPE name=ID;
PropertyDef: name=[PropertyDecl]  ':=' value=VALUE;


to describe object models like

AbstractObject BaseObject
{
  int PropertyA
  string PropertyB
}

InstanzObject Object1 implements BaseObject
{
  PropertyA := 5
  PropertyB := "Hello World"
}


Now I want to achieve the user may type up to

InstanzObject Object1 implements BaseObject


and to get a template implementation like

{
  PropertyA := <int>
  PropertyB: = <string>
}


automatically by consulting the content assist. Thus the user has only to fill in the values.

Currently the content assist only gives me the '{' as an option after "BaseObject". Instead it should generate the whole block depending on the referenced AbstractObject.

Is it possible to do it? Can somebody give me a hint which completion method inside the MyDslProposalProvider I have to implement? And how to get the relevant data from the reference?

Thank you in advance,
Jonatan

[Updated on: Thu, 16 December 2010 09:31]

Report message to a moderator

Re: Content Assist with "dynamic templates" [message #642435 is a reply to message #642432] Wed, 01 December 2010 10:38 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
You don't do this using the content assist but using Template Proposals: see §7.4 of the User Guide.

Re: Content Assist with "dynamic templates" [message #642666 is a reply to message #642432] Thu, 02 December 2010 09:16 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I think you will have to override completeKeyword in AbstractJavaBasedContentProposalProvider.

call super and check if the keyword is an opening brace. If so you can query the contentAssistContext for the current model element. This should give you access to the InstanzObject and now you can navigate the extended object to collect the properties and calculate the completion string.
If you want navigation through the properties (using tab) you will have to use code templates as Meinte says. However, "dynamic" templates as you need them are not supported out of the box.

Alex
Re: Content Assist with "dynamic templates" [message #642679 is a reply to message #642432] Thu, 02 December 2010 10:08 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Jonathan,

Xtext supports somewhat limited placeholders in content proposals out of
the box. Please have a look at
TerminalsProposalProvider#createStringProposal and digg into
ConfigurableCompletionProposal#setSimpleLinkedMode. However, multiple
linked fields in your proposal are not supported out of the box and
you'll have to implement that on your own.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 01.12.10 11:24, schrieb jantoni@web.de:
> Hello,
>
> I have a simple DSL
>
>
> Model: AbstractObject | InstanzObject;
>
> AbstractObject: 'AbstractObject' name=ID
> '{'
> (propertyDecls+=PropertyDecl)*
> '}';
>
> InstanzObject : 'InstanzObject' name=ID 'implements' base=[AbstractObject]
> '{'
> (propertyDefs+=PropertyDefs)*
> '}';
>
> PropertyDecl: type=TYPE name=ID;
> PropertyDef: name=[PropertyDecl] ':=' value=VALUE;
>
>
> to describe object models like
>
>
> AbstractObject BaseObject
> {
> int PropertyA
> string PropertyB
> }
>
> InstanzObject Object1 implements BaseObject
> {
> PropertyA := 5
> PropertyB := "Hello World"
> }
>
>
> Now I want to achieve the user may type up to
>
>
> InstanzObject Object1 implements BaseObject
>
>
> and to get a template implementation like
>
>
> {
> PropertyA := <int>
> PropertyB: = <string>
> }
>
>
> automatically by consulting the content assist. Thus the user has only
> to fill in the values.
>
> Currently the content assist only gives me the '{' as an option after
> "BaseObject". Instead it should generate the whole block depending on
> the referenced AbstractObject.
>
> Is it possible to do it? Can somebody give me a hint which completion
> method inside the MyDslProposalProvider I have to implement? And how to
> get the relevant data from the reference?
>
> Thank you in advance,
> Jonatan
>
>
Re: Content Assist with "dynamic templates" [message #645251 is a reply to message #642679] Thu, 16 December 2010 09:30 Go to previous messageGo to next message
Jonatan Antoni is currently offline Jonatan AntoniFriend
Messages: 18
Registered: December 2010
Location: Frankfurt/Main
Junior Member
Hello all,

thank you for your ideas.

I have figured out a solution. It is not the best way I guess, but the way I was able to do it quickly.

I have just enhanced the org.xtext.mydsl.ui.MyDSLProposalProvider class.

public void completeInstanzObject_base(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	super.completeInstanzObject_base(model, assignment, context, acceptor);
	InstanzObject instanz = (InstanzObject)context.getCurrentModel();
	AbstractObject abstract = instanz.getbase();
	EList<PropertyDecl> properties = abstract.getpropertyDefs();
		
	String dstr = abstract.getname() + " { [..] } - Instanz Template";
	String pstr = abstract.getname() + "\r\n";
	pstr += "{\r\n";
	for (PropertyDecl property: properties) {
		pstr += property.getname() + ":= <" + property.gettype() + ">\r\n";
	} 
	pstr += "}\r\n";

	ICompletionProposal proposal = createCompletionProposal(pstr, dstr, null, context);
	acceptor.accept(proposal);
}


This way the template is constructed on the fly.

Jonatan
Re: Content Assist with "dynamic templates" [message #645436 is a reply to message #645251] Fri, 17 December 2010 09:23 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

note that this is not really a "template" but a simple completion proposal. That is, navigating through the properties using tab is not possible.

Alex
Previous Topic:Outline view problem
Next Topic:[SOLVED] Related file not rebuilt after modification
Goto Forum:
  


Current Time: Fri Sep 20 15:06:44 GMT 2024

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

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

Back to the top