Restoring the model to a saved state [message #1792189] |
Thu, 12 July 2018 08:42  |
Eclipse User |
|
|
|
Hello,
I am trying to get a snapshot of the model and restore it back at some if some conditions are true. More specifically, I want to get a snapshot of the resource, and then create a virtual resource, and then display a dialog form to the user. The user can use the opened form to modify the "virtual" resource. If the user clicks on the save button in the form, then the virtual resource will overwrite the actual resource and will save the modifications to the actual model. But if the user pushes the Cancel button, the all the modifications should be reverted to the last snapshot that was taken from the model.
Any help or idea would be appreciated.
Thanks,
Parsa
|
|
|
|
Re: Restoring the model to a saved state [message #1792223 is a reply to message #1792194] |
Thu, 12 July 2018 14:51  |
Eclipse User |
|
|
|
Hi Karsten
Thanks for the reply, DirtyStateEditorSupport is a little bit limited and does not actually meet my requirements (I have other requirements in addition to what I explained). So, in simple steps I need to do the following:
1: take a snapshot from the model,
2: create a virtual resource from the model
3: open the form and do whatever I want on the virtual resource
4: if user pushes Accept button apply the changes from virtual resource to the original resource (probably by merger.copyAllRightToLeft(...); or so ) and if user pushes cancel just revert back to the snapshot (basically dispose the virtual resource).
The main issue is creating a virtual resource that I can work on it. Is the createVirtualXtextResource() method shown below related to what I want ?
private XtextResource createVirtualXtextResource(URI uri,
EObject semanticElement) throws IOException {
IResourceFactory resourceFactory = xtextInjector
.getInstance(IResourceFactory.class);
// TODO use the synthetic scheme.
XtextResourceSet rs = xtextInjector.getInstance(XtextResourceSet.class);
rs.setClasspathURIContext(getClass());
// Create virtual resource
XtextResource xtextVirtualResource = (XtextResource) resourceFactory
.createResource(URI.createURI(uri.toString()));
rs.getResources().add(xtextVirtualResource);
// Populate virtual resource with the given semantic element to edit
xtextVirtualResource.getContents().add(semanticElement);
// Save and reparse in order to initialize virtual Xtext resource
ByteArrayOutputStream out = new ByteArrayOutputStream();
xtextVirtualResource.save(out, Collections.emptyMap());
xtextVirtualResource.reparse(new String(out.toByteArray()));
return xtextVirtualResource;
}
Thanks,
Parsa
|
|
|
Powered by
FUDForum. Page generated in 0.03766 seconds