Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Sirius and Xtext synchronization
Sirius and Xtext synchronization [message #1599245] Tue, 03 February 2015 13:38 Go to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
I have some issues with the xtext synchronization and i am wondering if there is an example project that uses custom refresh and saving policy like suggested in the eclipsecon 2014 presentation http://www.slideshare.net/cbrun/xtext-sirius.

I found this project: https://github.com/ObeoNetwork/Xtext-Sirius-integration but it seems focussed on the embedded editor.

My main problem is opening the Xtexteditor and select the node of the just created EObject in the sirius diagram. Problem is that the code below will not find the node. (NodeModelUtils seems not updated) To "update" nodemodelutilse the resource is saved (resource.save(null)). But when some object is deleted some object that is still in use and save the resource, unexpected behavior can happen.
Thats why i am looking for the best way to do this. I am not sure if sirius is synchronizing correctly with xtext.




public EObject openTextEditor(EObject any) {
if (any != null && any.eResource() instanceof XtextResource
&& any.eResource().getURI() != null) {

String fileURI = any.eResource().getURI().toPlatformString(true);
IFile workspaceFile = ResourcesPlugin.getWorkspace().getRoot()
.getFile(new Path(fileURI));
if (workspaceFile != null) {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart openEditor = IDE.openEditor(page,
workspaceFile,
"org.eclipse.xtext.example.fowlerdsl.Statemachine",
true);
if (openEditor instanceof AbstractTextEditor) {
ICompositeNode node = NodeModelUtils
.findActualNodeFor(any);
if (node != null) {
int offset = node.getOffset();
int length = node.getTotalEndOffset() - offset;
((AbstractTextEditor) openEditor).selectAndReveal(
offset, length);
System.out
.println("StatemachineServices.openTextEditor()");
}
}
// editorInput.
} catch (PartInitException e) {
// Put your exception handler here if you wish to.
}
}
}
System.out.println(any);
return any;
}

btw i have installed "Sirius integration with XText"
But i havent done the following: " Instantiate an XtextResourceSet
Configure the ResourceSet with the project. Change the saving policy " which is on the slide of earlier mentioned presentation
Re: Sirius and Xtext synchronization [message #1622169 is a reply to message #1599245] Wed, 18 February 2015 10:01 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Koen,

Le 03/02/2015 14:38, Koen Staal a écrit :
> I have some issues with the xtext synchronization and i am wondering if
> there is an example project that uses custom refresh and saving policy
> like suggested in the eclipsecon 2014 presentation
> http://www.slideshare.net/cbrun/xtext-sirius.
>
> I found this project:
> https://github.com/ObeoNetwork/Xtext-Sirius-integration but it seems
> focussed on the embedded editor.
>
> My main problem is opening the Xtexteditor and select the node of the
> just created EObject in the sirius diagram. Problem is that the code
> below will not find the node.

You have to save the Sirius session to impact the file you will open in
your Xtext editor.

(NodeModelUtils seems not updated) To
> "update" nodemodelutilse the resource is saved (resource.save(null)).
> But when some object is deleted some object that is still in use and
> save the resource, unexpected behavior can happen.
> Thats why i am looking for the best way to do this. I am not sure if
> sirius is synchronizing correctly with xtext.
>
>
>
>
> public EObject openTextEditor(EObject any) {
> if (any != null && any.eResource() instanceof XtextResource
> && any.eResource().getURI() != null) {
>
> String fileURI =
> any.eResource().getURI().toPlatformString(true);
> IFile workspaceFile = ResourcesPlugin.getWorkspace().getRoot()
> .getFile(new Path(fileURI));
> if (workspaceFile != null) {
> IWorkbenchPage page = PlatformUI.getWorkbench()
> .getActiveWorkbenchWindow().getActivePage();
> try {
> IEditorPart openEditor = IDE.openEditor(page,
> workspaceFile,
>
> "org.eclipse.xtext.example.fowlerdsl.Statemachine",
> true);
> if (openEditor instanceof AbstractTextEditor) {
> ICompositeNode node = NodeModelUtils
> .findActualNodeFor(any);
> if (node != null) {
> int offset = node.getOffset();
> int length = node.getTotalEndOffset() -
> offset;
> ((AbstractTextEditor)
> openEditor).selectAndReveal(
> offset, length);
> System.out
>
> .println("StatemachineServices.openTextEditor()");
> }
> }
> // editorInput.
> } catch (PartInitException e) {
> // Put your exception handler here if you wish to.
> }
> }
> }
> System.out.println(any);
> return any;
> }
> btw i have installed "Sirius integration with XText"
> But i havent done the following: " Instantiate an XtextResourceSet
> Configure the ResourceSet with the project. Change the saving policy "
> which is on the slide of earlier mentioned presentation

If you have installed "Sirius integration withg XText", the
org.eclipse.sirius.common.xtext will provide a XTextResourceSetFactory
which will enable the live scope in the load options and will configure
the resource set (set the platform uri map, the classpath uri context,
the classpath uri resolver). It will also automatically change the
saving policy when an XtextResource is present in the resource set. The
XTextSavingPolicy currently add
SaveOptions.newBuilder().noValidation().getOptions.toOptionsMap() to the
save options.

>

Regards

--
Maxime - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Sirius and Xtext synchronization [message #1622388 is a reply to message #1622169] Wed, 18 February 2015 13:09 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
Thanks for your answer, Reading your comment i assume sirius should update nodemodelutils if the xtext part is included

I have "Sirius integration with XText" installed.
" org.eclipse.sirius.common.xtext" is set as required Plug-in.
the xtextresourcesetFactory and the xtextsavingpolicy are being used.

The user creates a new eobject with sirius and session.save will be called at the end (the eobject is visible in the xtextedior)
The following user action will use the nodeutils but NodeModelUtils.findNodesForFeature(eObject, feature) returns null

Is there something i missed?


(findNodesForFeature returns null because NodeModelUtils.getnode returns null, the object has no IComposeNode adapter
the object does have the following adapters:

[org.eclipse.xtext.util.OnChangeEvictingCache$CacheAdapter@7942381e, org.eclipse.emf.transaction.impl.TransactionChangeRecorder@75ea824a, org.eclipse.sirius.business.internal.session.danalysis.LocalResourceCollector@771004c0, org.eclipse.sirius.common.tools.api.util.LazyCrossReferencer$InternalCrossReferencer@6a7277c3, org.eclipse.sirius.common.tools.api.util.IDAdapter@183a8b7f, org.eclipse.xtext.util.SimpleAttributeResolver$DiscardingAdapter@7a3117d4, my.project,ItemProvider@c9a0570])

[Updated on: Wed, 18 February 2015 13:16]

Report message to a moderator

Re: Sirius and Xtext synchronization [message #1632431 is a reply to message #1622388] Tue, 24 February 2015 09:14 Go to previous message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 703
Registered: July 2009
Senior Member
Le 18/02/2015 14:09, Koen Staal a écrit :
> Thanks for your answer, Reading your comment i assume sirius should
> update nodemodelutils if the xtext part is included
>
> I have "Sirius integration with XText" installed. "
> org.eclipse.sirius.common.xtext" is set as required Plug-in.
> the xtextresourcesetFactory and the xtextsavingpolicy are being used.

I don't know how Xtext works in these aspects, but currently Sirius's
Xtext integration plug-in is strictly about being able to correctly load
and save Xtext models inside Sirius sessions.

If you have both a Sirius session and an Xtext editor opened at the same
time on the same Xtext model, there is no direct synchronization between
them: they both have completely isolated in-memory versions of the Xtext
model, as it was on disk when they loaded it. Modifications in one
context can only be visible to the other if it is saved on disk and
reloaded.

If you make a modification in the Xtext editor, and then save it, the
file will change on disk. Sirius will detect that and update its own
in-memory version with the new content from the disk automatically.

If you make a modification in a Sirius editor, you must first save it.
After that I don't know if the Xtext editor will pick up the updated
content automatically, but from what you say below it seems you make
need some explicit action to do so.

> The user creates a new eobject with sirius and session.save will be
> called at the end (the eobject is visible in the xtextedior) The
> following user action will use the nodeutils but
> NodeModelUtils.findNodesForFeature(eObject, feature) returns null


--
Pierre-Charles David - Obeo

Need professional services for Sirius?
http://www.obeodesigner.com/sirius


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Open a Sirius representation inside a View
Next Topic:Change appearance of model elements
Goto Forum:
  


Current Time: Thu Apr 25 22:15:43 GMT 2024

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

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

Back to the top