Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Modifying an Xtext document from a worker thread(How to execute long-running Xtext operations without blocking the UI thread?)
Modifying an Xtext document from a worker thread [message #900238] Mon, 06 August 2012 04:12 Go to next message
Scott Mising name is currently offline Scott Mising nameFriend
Messages: 11
Registered: August 2010
Junior Member
Hi All

I have a DSL for an existing file format (that forms part of the input for an application I am testing). I am using the EMF factory to generate thousands of records and Xtext to serialize them. This can take several minutes (especially if the file was not empty to begin with, and as the format has no delimiters, I've had to enable backtracking) and Eclipse stops responding while it's happening. If I use an IRunnableWithProgress (in my JFace wizard) that calls IXtextDocument.modify(), it works well - the UI is responsive, the progress monitor is updated and cancel works - but I get 'Invalid thread access' from SWT when the notifications fire (on the worker thread). If I stop listener notifications and resume them when I'm back on the UI thread, I get 'assertion failed' because this is not the thread that modified the document.

Does anyone have any suggestions? Is what I want possible with the current implementation?

Thanks and regards
Scott
Re: Modifying an Xtext document from a worker thread [message #902123 is a reply to message #900238] Thu, 16 August 2012 04:42 Go to previous message
Scott Mising name is currently offline Scott Mising nameFriend
Messages: 11
Registered: August 2010
Junior Member
Hi All

I've found a solution to the issue, but it involves a sequence of hacks that I'm not at all happy with:

1 Subclass XtextEditor (and bind the UI module to it)

2 Create a delegate for ITextViewerExtension.setRedraw()
	public void setRedraw(boolean redraw)
	{
		// Can access protected final method getSourceViewer() from here
		((ITextViewerExtension)getSourceViewer()).setRedraw(redraw);
	}


3 Wrap a run() call in Wizard.performFinish() with calls to setRedraw()
	editor.setRedraw(false);

	// Spawn a cancellable task using our dialog as a context
	getContainer().run(true, true, new IRunnableWithProgress()
	{
		public void run(final IProgressMonitor monitor) throws InvocationTargetException
		{
			monitor.beginTask("Generating", count);

			try
			{
				// Obtain write access to document model
				editor.getDocument().modify(new IUnitOfWork.Void<XtextResource>()
				{
					public void process(XtextResource res) throws Exception
					{
						// Can make semantic changes and call monitor.worked() and monitor.isCanceled() here
					}
				});
			}
			finally
			{
				monitor.done();
			}
		}
	});

	editor.setRedraw(true);


Does anyone know of a more elegant way to gain access to ITextViewerExtension?
Previous Topic:Loading of huge model
Next Topic:How to remove internal validation
Goto Forum:
  


Current Time: Fri Apr 26 01:05:44 GMT 2024

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

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

Back to the top