Folding on EReferences [message #713556] |
Mon, 08 August 2011 15:42 |
Xavier Seignard Messages: 52 Registered: June 2010 |
Member |
|
|
Hello,
In my EMF metamodel, I've got an EObject which contains (i.e. containment = true) an EReference (with a * cardinality) to another EObject.
In my grammar, I want to be able to fold/unfold the whole list of EObjects handled by this EReference.
So I extended the DefaultFoldingRegionProvider and binded it in the UI module.
I only overwrote the doGetFoldingRegions method to handle my folding strategy.
So I parse my model, get the structural feature which is my EReference, and the call these methods defined in DefaultFoldingRegionProvider :
IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor = createAcceptor(xtextDocument, result);
computeObjectFolding(eReference, foldingRegionAcceptor);
I also overwrote the isHandled method to always return true.
But it doesn't work, so I think I'm missing some points. Or maybe it's not possible to fold/unfold on the whole EReference (and not each elements of that EReference, which works fine actually)?
Regards,
Xavier
[Updated on: Mon, 08 August 2011 15:43] Report message to a moderator
|
|
|
Re: Folding on EReferences [message #713625 is a reply to message #713556] |
Mon, 08 August 2011 17:05 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Xavier,
you may have to use NodeModelUtils.findNodesForFeature(EObject,
EStructuralFeature) and merge the nodes in the resulting list to a
complete range that should be folded.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
On 08.08.11 17:42, Xavier Seignard wrote:
> Hello,
>
> In my EMF metamodel, I've got an EObject which contains (i.e.
> containment = true) an EReference (with a * cardinality) to another
> EObject.
>
> In my grammar, I want to be able to fold/unfold the whole list of
> EObjects handled by this EReference.
>
> So I extended the DefaultFoldingRegionProvider and binded it in the UI
> module.
>
> I only overwrote the doGetFoldingRegions method to handle my folding
> strategy.
> So I parse my model, get the structural feature which is my EReference,
> and the call these methods defined in DefaultFoldingRegionProvider.
>
> IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor =
> createAcceptor(xtextDocument, result);
> computeObjectFolding(eReference, foldingRegionAcceptor);
>
> I also overwrote the isHandled method to always return true.
>
> But it doesn't work, so I think I'm missing some points. Or maybe it's
> not possible to fold/unfold on the whole EReference (and not each
> elements of that EReference, which works fine actually)?
>
> Regards,
>
> Xavier
|
|
|
|
Re: Folding on EReferences [message #713994 is a reply to message #713875] |
Tue, 09 August 2011 13:43 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Xavier,
don't know what you think is smart ... offset + length usually return
the endoffset. I assume that you want to fold everything starting from b
up to the closing brace and starting from c up to the closing brace again.
I'd navigate the node that is associated with A, find the node with
grammarElement==keywordB and navigate to its siblings until you reach
the closing brace. Ask that node for the endOffset and you'll have a
start and the end which leads to a nicely computed length.
Does that make sense?
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
On 09.08.11 11:14, Xavier Seignard wrote:
> Thanks Sebastian for your quick answer.
>
> Lets say my grammar look like this :
>
> A returns A:
> {A}
> 'a'
> name=ID
> '{'
> ('b' '{' setOfB+=B+ '}' )?
> ('c' '{' setOfC+=C* '}' )?
> '}';
>
> Where B and C are other rules defined after.
>
> With NodeModelUtils.findNodesForFeature I do get all nodes in the given
> feature (let's say feature with keyword 'b'). But as I gave a keyword
> for this feature, and it's not in the list of node I have, how can I
> calculate the offset? (For now I calculate it from the root node, but
> it's quite crappy).
>
> And for the lenght, I add the length of each node, but I also need to
> add the length of the keyword and brackets (I do it in a crappy way for
> now), so is there any way to do it smartly?
>
> Finally with I pass offset and length as parameters of
> foldingRegionAcceptor.accept and it works quite ok.
>
> Any suggestion to calculate offset and length smartly?
>
> Regards,
>
> Xavier
|
|
|
Powered by
FUDForum. Page generated in 0.02416 seconds