Dynamic Template Proposal [message #696686] |
Thu, 14 July 2011 14:39 |
Markus Schindler Messages: 30 Registered: July 2009 |
Member |
|
|
Hello,
I have a dsl which does a mapping of 2 other dsl. For example:
DSL Mapping:
mapping Entity A (from dsl Entities) {
field a to Class B field x (from dsl Classes)
field b to Class B field y
field c to Class B field z
}
Now, I want to make a proposals after "mapping" to select a Entity from dsl 1. After selecting a Entity, all fields of Entity A should inserted also,
so the mapping looks like this:
mapping Entity A {
field a to [FIELD]
field b to [FIELD]
field c to [FIELD]
}
Where [FIELD] should be properties of the template, where I can navigate using tabs.
Is this possible?
I achieved this already as a "normal" content proposal without the template features. But I had one BIG problem:
public void completeMapping(...)
IScope scope = provider.getScope(model, DomainmodelPackage.eINSTANCE.getEntity());
for (IEObjectDescription element : scope.getAllElements()) {
StringBuffer b = new StringBuffer();
b.append(element.getName().toString());
b.append(" {\n");
Entity x = (Entity ) element.getEObjectOrProxy();
for(AbstractField f : x.getFeatures()){ <
b.append("\n"+f.getName()+"(TYPE) {}\n");
}
b.append("}");
ICompletionProposal completionProposal = createCompletionProposal(...
// register proposal
acceptor.accept(completionProposal);
}
}
Problem is, the x.getFeatures is always empty, I think that is, because the Entity is from an other Dsl. And I got only a proxy. So how can I get now
the "real" object?
I tried to get the Entity_Fields also by Scoping:
IScope scope2 = provider.getScope(element.getEObjectOrProxy(), DomainmodelPackage.eINSTANCE.getProperty_Field());
for (IEObjectDescription element2 : scope2.getAllElements()) {
b.append("\n"+element2.getName()+"(TYPE) {}\n");
}
but, this rises a NullPointer from my ScopeProvider, because the ScopeProvider should only deliever Fields from the selected Entity.
val entity = EcoreUtil2::getContainerOfType(context, typeof(Entity));
val d = entity.features.filter(e | e.isJavaType).map(e | e.createIEObjectDescription()); <-- NullPointer
Any hints? Maybe a configurable Scoping Problem?
Regards,
Markus
|
|
|
|
|
Re: Dynamic Template Proposal [message #696997 is a reply to message #696992] |
Fri, 15 July 2011 09:46 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi,
a) check out this blog if you consider going via the template infrastructure
b) there was a thread in this forum about a way to make the CompletionProposal having template functionality. I think, the bottom line is that you have to create your own ConfigurableCompletionProposal (maybe adapting setUpLinkedMode). As I have not looked into that topic, I cannot be more precise
Alex
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
|
|
|
Powered by
FUDForum. Page generated in 0.03720 seconds