Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Synchronize changes from the Model to the Embedded Editor in Xtext
Synchronize changes from the Model to the Embedded Editor in Xtext [message #1830598] Wed, 29 July 2020 14:28 Go to next message
Georgiana Ecobici is currently offline Georgiana EcobiciFriend
Messages: 23
Registered: July 2019
Junior Member
I used XText to define a DSL Grammar, then I used the XText EmbeddedEditor to use XText editor in it.

I have some issues regarding the synchronization, I obtained the model object that contains my content inside the XText editor, but If I modify in Java directly my Model object, the changes are not reflected in the EmbeddedEditor.

The model is updated like below:
DslscenarioProvider p = eeView.getProvider();
XtextResource resource = p.getResource();
EList<EObject> content = resource.getContents();
if (content.size() > 0 && content.get(0) instanceof Model) {
Model domainModel = (Model) resource.getContents().get(0);
Type type = domainModel.getType();
if (type != null) {
type.setName("test");
}
resource.relink();
}

The EmbeddedEditor is added inside an Eclipse ViewPart:
public class EmbeddedEditorView extends ViewPart {
public void redrawParent() {
getParent().redraw(); // parent = composite
}

@Override
public void createPartControl(Composite parent) {
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
DslscenarioActivator activator = DslscenarioActivator.getInstance();
Injector injector = activator .getInjector(DslscenarioActivator.ORG_EDITOR_DSLSCENARIO_DSL);

provider = injector.getInstance(DslscenarioProvider.class);
EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class);

EmbeddedEditor editor = factory.newEditor(provider).withParent(top);
model = editor.createPartialEditor("", "", "", false);
}
}

The redrawParent is called after doing some changes on the model object, however the view is not updated, even if the model is updated.
Do you have other suggestions?
Re: Synchronize changes from the Model to the Embedded Editor in Xtext [message #1830599 is a reply to message #1830598] Wed, 29 July 2020 14:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13637
Registered: July 2009
Senior Member
i have no plan but two ideas

- wrap doing the changes into XtextDocument.modify org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor.getDocument()
- call ISerializer and then updateModel on EmbeddedEditorModelAccess


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Synchronize changes from the Model to the Embedded Editor in Xtext [message #1830804 is a reply to message #1830599] Tue, 04 August 2020 13:04 Go to previous message
Georgiana Ecobici is currently offline Georgiana EcobiciFriend
Messages: 23
Registered: July 2019
Junior Member
Thanks for the suggestion, it works fine.

String serialized = ((XtextResource) domainModel.eResource()).getSerializer().serialize(domainModel);
eeView.getModel().updateModel(serialized);

And added a formatter2 class to format the code.
Previous Topic:DSL Debugger exits the dsl code and enters java code
Next Topic:Possible to convert part of STRING to an object's ID using a value converter?
Goto Forum:
  


Current Time: Mon Oct 26 11:22:18 GMT 2020

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

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

Back to the top