Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Imported model/text does not update after inserting a new element,
Imported model/text does not update after inserting a new element, [message #1003189] Sun, 20 January 2013 14:36 Go to next message
Joost van Pinxten is currently offline Joost van PinxtenFriend
Messages: 51
Registered: November 2012
Member
Okay, following my other posts, I now have two quick fixes for a situation in which the validation fails (i.e. a cross-reference is not allowed). Situation 1 is to change the cross-reference into one of the validated references, situation 2 is to add a new model element to the cross-referenced object, which will allow it to pass the validation.

This works, when I'm using a single file to define all the model elements; it shows up in the text and model browser when I activate the quick fix. But I would like to keep using the importURI and it seems that the model/text is not properly updated when the element is added to an element outside the current file. Although the validation says that there is no problem anymore (which should mean that the element has been added properly), it does not show up in the text or model browser.

The following piece of code shows how I'm using the acceptor in a @Fix function of the DefaultQuickFixProvider subclass:

acceptor.accept(issue, "Add the "+ serviceName +" service to " + resourceName, "Add the " + resourceName + " service to " + resourceName, null,
	new ISemanticModification() {
		public void apply(EObject element, IModificationContext context) {
			if(!( element instanceof AllocatorEntry)) return;
			AllocatorEntry ae = (AllocatorEntry) element;
			EObject parent = ae.eContainer();
			while(parent != null && !(parent instanceof Mapping)) {
				parent = parent.eContainer();
			}
			
			if(parent == null) { return; }
			
			Mapping  mapping = (Mapping) parent;
			for (Resource r : mapping.getPlatform().getResources()) {
				if(r.getName().equals(resourceName)) {
					// create a new providesService for this resource:
					ProvidesService ps = PlatformFactory.eINSTANCE.createProvidesService();								
					r.getProvides().add(ps);


What do I need to add in order to make this work for a file other than the file where the QuickFix was suggested?
Re: Imported model/text does not update after inserting a new element, [message #1003729 is a reply to message #1003189] Mon, 21 January 2013 22:16 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
If you change other resources besides the one with the error marker, you
have to take care of saving that one manually.
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 20.01.13 15:36, schrieb Joost van Pinxten:
> Okay, following my other posts, I now have two quick fixes for a
> situation in which the validation fails (i.e. a cross-reference is not
> allowed). Situation 1 is to change the cross-reference into one of the
> validated references, situation 2 is to add a new model element to the
> cross-referenced object, which will allow it to pass the validation.
>
> This works, when I'm using a single file to define all the model
> elements; it shows up in the text and model browser when I activate the
> quick fix. But I would like to keep using the importURI and it seems
> that the model/text is not properly updated when the element is added to
> an element outside the current file. Although the validation says that
> there is no problem anymore (which should mean that the element has been
> added properly), it does not show up in the text or model browser.
> The following piece of code shows how I'm using the acceptor in a @Fix
> function of the DefaultQuickFixProvider subclass:
>
> acceptor.accept(issue, "Add the "+ serviceName +" service to " +
> resourceName, "Add the " + resourceName + " service to " + resourceName,
> null,
> new ISemanticModification() {
> public void apply(EObject element, IModificationContext context) {
> if(!( element instanceof AllocatorEntry)) return;
> AllocatorEntry ae = (AllocatorEntry) element;
> EObject parent = ae.eContainer();
> while(parent != null && !(parent instanceof Mapping)) {
> parent = parent.eContainer();
> }
>
> if(parent == null) { return; }
>
> Mapping mapping = (Mapping) parent;
> for (Resource r : mapping.getPlatform().getResources()) {
> if(r.getName().equals(resourceName)) {
> // create a new providesService for this resource:
> ProvidesService ps =
> PlatformFactory.eINSTANCE.createProvidesService();
> r.getProvides().add(ps);
>
> What do I need to add in order to make this work for a file other than
> the file where the QuickFix was suggested?
Re: Imported model/text does not update after inserting a new element, [message #1003735 is a reply to message #1003729] Mon, 21 January 2013 22:31 Go to previous messageGo to next message
Joost van Pinxten is currently offline Joost van PinxtenFriend
Messages: 51
Registered: November 2012
Member
Sebastian, I don't know if I understand you correctly;

Say that the other editor is 'dirty', i.e. unsaved changes were done (manually) and this quick fix adds something to that file, do you suggest that I should save that file programmatically? Or do you mean that there is some kind of update mechanism that I should use programmatically in order for the text in the other Xtext resource to change?
Re: Imported model/text does not update after inserting a new element, [message #1003936 is a reply to message #1003735] Tue, 22 January 2013 09:24 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Am 21.01.13 23:31, schrieb Joost van Pinxten:
> Sebastian, I don't know if I understand you correctly;
> Say that the other editor is 'dirty', i.e. unsaved changes were done
> (manually) and this quick fix adds something to that file, do you
> suggest that I should save that file programmatically? Or do you mean
> that there is some kind of update mechanism that I should use
> programmatically in order for the text in the other Xtext resource to
> change?

There is no underlying mechanism, you have to take care of all these
things manually right now, e.g. finding other open, dirty editors,
performing document changes, performing resource changes if no editor is
currently open ... these things are currently not part of the quickfix API.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Xtext DSL plugin not loaded
Next Topic:Debugging XBase: skip XBase function
Goto Forum:
  


Current Time: Fri Apr 26 19:33:42 GMT 2024

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

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

Back to the top