Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XtextResource out of sync after saving a XtextEditor
XtextResource out of sync after saving a XtextEditor [message #1404746] Tue, 05 August 2014 13:06 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

I've discovered some strange behavior in the following scenario. I have implemented an Action on XtextEditors by implementing the IEditorActionDelegate interface.
In the selectionChanged-method I try to find the current element ( in the the semantic model) to the selected text.

Here the method:

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		// get the selected text
		if (EditorUtils.getActiveXtextEditor() != null) {
		
			project = EditorUtils.getActiveXtextEditor().getResource().getProject();

			// get the selected text
			ITextSelection textSelection = (ITextSelection) EditorUtils.getActiveXtextEditor().getSelectionProvider().getSelection();
			foundElement = getSelectedElement(textSelection);
			if (foundElement != null)
				System.out.println("foundElement: " + foundElement.toString());

		}

	}


So far everything is working fine. The problem appears when I open my XtextEditor and add some concrete syntax. For example a new state like here:

https://dl.dropboxusercontent.com/u/18688378/eclipseCoding/ids/selected%20element.jpg

After saving the editor I mark the the text and run my action, but the new element is not found in the semantic model.

Here the code for finding the marked element:

	private EObject getSelectedElement(ITextSelection textSelection) {

		if (EditorUtils.getActiveXtextEditor() != null) {

			EObjectAtOffsetHelper atOffsetHelper = new EObjectAtOffsetHelper();
			int offset = textSelection.getOffset();

			String xtextFilePath = EditorUtils.getActiveXtextEditor().getResource().getFullPath().toString();
		        XtextResource xtextRes= (XtextResource) set.getResource(URI.createPlatformResourceURI(xtextFilePath, true), true);

			EObject elem = atOffsetHelper.resolveElementAt(xtextRes, offset);
			if (elem != null) {
				return elem;
			}
		}
		return null;

	}


Is this a bug, or am I doing something wrong?

Thanks for any help!

~Alex
Re: XtextResource out of sync after saving a XtextEditor [message #1404781 is a reply to message #1404746] Tue, 05 August 2014 17:12 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
I don't know whether this is the problem, but you should access the
model in a IUnitOfWork (that ensures the synchronization).

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:UI required when launching mwe2 headlessly?
Next Topic:integrate xtext with graphiti
Goto Forum:
  


Current Time: Thu Mar 28 14:28:11 GMT 2024

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

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

Back to the top