Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XtextEditor manipulation(Adding/Editing some functionality to the XtextEditor)
XtextEditor manipulation [message #1059996] Wed, 22 May 2013 13:30 Go to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Hello everyone,
could someone help me with the following problem, please:
I want to be able when I'm pressing in a view (like the outline) on a object from my model to be able to show in the editor only that element + subelements and the rest of the things in the editor I would like to have them collapsed or grayed.
Something like this:
View:
Red
Blue
Black

and if I click on Red in the editor should show me:
+myLanguage
Red name id 
 subelementOfRed name id
 subelement2OfRed id
+code
Red name id
 subelementOfRed name id
+code

the + is for collapse code

More info: now I have the XtextEditor and the IXtextDocument, I got also the model from : IXTextDocument.readOnly(new IUnitOfWork<Object, XtextResource>()).
But I'm a little stuck of how should I make this thing to collapse in between (I get the right elements from the model)


Thanks in advance!


Edwin W.T.
Re: XtextEditor manipulation [message #1060017 is a reply to message #1059996] Wed, 22 May 2013 14:32 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I did some foldig customizations in a project. The corresponding code is in the folding package and the TerminologyXtextEditor (just as inspiration for how to collapse regions).

You will have to solve the following problems:
* identify the folding regions that correspond to the outline view selection
* find a good hook for your selection change in the view (OutlineWithEditorLinker?), where you collapse/expand the regions

A very hacky (but possibly minimal effort) idea if there was a 1:1 correspondence between outline element and text element (which seems not to be your use case).
When you select an element in the outline view, the corresponding model element is expanded automatically, so you could simply collapse *all* regions first.

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
Re: XtextEditor manipulation [message #1060027 is a reply to message #1060017] Wed, 22 May 2013 15:01 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Thanks for the quick answer.
I will look into it, but first I have another question, because I already did something in another way.
I used the ISourceViewer sourceViewer to show only what I'm interested and it works, but now I have only the problem that if I have more elements (at different offsets) will take only my last element with the function: sourceViewer.setVisibleRegion(offset, length); can I somehow make more regions visible in the same time ?
This will resolve my problem faster Smile.


Edwin W.T.
Re: XtextEditor manipulation [message #1060091 is a reply to message #1060027] Thu, 23 May 2013 06:09 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

Quote:
A projection source viewer is a source viewer which supports multiple visible regions which can dynamically be changed.
(Projection Viewer Java Doc)

So I guess, folding is the way to show more than one region at a time.

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
Re: XtextEditor manipulation [message #1060237 is a reply to message #1060091] Thu, 23 May 2013 16:13 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Is there a nice way to get the offset in the xtexteditor when you have the EMF object from the state ( IXTextDocument.readOnly(new IUnitOfWork<Object, XtextResource>())) ?

Edwin W.T.
Re: XtextEditor manipulation [message #1060264 is a reply to message #1060237] Thu, 23 May 2013 17:35 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

use NodeModelUtils.

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
Re: XtextEditor manipulation [message #1060336 is a reply to message #1060264] Fri, 24 May 2013 08:13 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Hi,
This is so perfect, thanks a lot!


Edwin W.T.
Re: XtextEditor manipulation [message #1063699 is a reply to message #1060264] Thu, 13 June 2013 18:52 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Hi Alex,
Now I am doing something like
ICompositeNode node = NodeModelUtils.findActualNodeFor(findP);//NodeModelUtils.getNode(findP);
								sourceViewer.setVisibleRegion(node.getOffset(), node.getLength());


works fine, but I have only one problem.
When I have something that is optional in my grammar for ex:
'car'  (model=STRING (color=STRING)?) 

if I'm using: car Audi works just fine, but if now I want to add the color Red to it the node will have the same length as when was only without the color.
The model is updated (saw it in debug).
Could you help me please?
Thanks in advance


Edwin W.T.
Re: XtextEditor manipulation [message #1063750 is a reply to message #1063699] Fri, 14 June 2013 06:09 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

when adding the color, is the code setting the visible region invoked at all? Have you checked that the color is set in the findP variable?

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
Re: XtextEditor manipulation [message #1063770 is a reply to message #1063750] Fri, 14 June 2013 07:57 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Hi,
yes is added, as I said I check with debug and is added in findP.
When I write:
car Audi
4 wheels 
- the visible part is the whole object car Audi 4 wheels
works fine
but when I add the color to this and then I have
car Audi "Red"
4 wheels
- the visible part is car Audi "Red" 4 - so this mean that the length of the string "Red" (+"") is 5 + 1 ws = 6 which is the length of the wheels (6) so will not show me the wheels in my code.
I think the problem of the node is that doesn't compute the length when you add the new feature.
As in my example the 'color' at start was null, but when I decided to update/add the color the length didn't add the new string.
Hope now is clear.
Thanks!


Edwin W.T.
Re: XtextEditor manipulation [message #1063799 is a reply to message #1063770] Fri, 14 June 2013 09:37 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it is not quite clear to me, because what you are saying is: the semantic model (findP) and the node model attached to it (node) are out of synch, although reparsing must have happened (otherwise the color feature would not be set). I have never experienced this problem. What does node.getText() look like?

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
Re: XtextEditor manipulation [message #1063855 is a reply to message #1063799] Fri, 14 June 2013 14:00 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Hi again,
So the node.getText() shows what I need/expected the whole text
car Audi "Red"
4 wheels

but in the editor appears:
car Audi "Red"
4 

I have the breakpoint at this line: sourceViewer.setVisibleRegion(node.getOffset(), node.getLength());
Thanks!
Cheers,


Edwin W.T.
Re: XtextEditor manipulation [message #1065216 is a reply to message #1063855] Mon, 24 June 2013 20:02 Go to previous message
Edwin Tuzar is currently offline Edwin TuzarFriend
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

so no idea what can this be ?

Edwin W.T.
Previous Topic:JvmModelInferrer and code generation
Next Topic:Read Xtext resource as EMF resource
Goto Forum:
  


Current Time: Thu Mar 28 14:43:19 GMT 2024

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

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

Back to the top