Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Advanced Scripting Environment (EASE) » Waiting for a command to complete
Waiting for a command to complete [message #1752213] Fri, 20 January 2017 01:01 Go to next message
Arthur Mising name is currently offline Arthur Mising nameFriend
Messages: 4
Registered: July 2009
Junior Member
I am working on a little script to do a refactoring (Scala's Organize Imports in this case) on every file in a project. However, I've run into a problem since it seems the script opens and tried to perform the refactor on the next file before the previous has finished. This means that if there is an error or something all the windows stack up.

How do I block my script until a command has finished?

The structure of the script is:
var files = findFiles(...);
for each (var f in files) {
	var editor = showEditor(f);
	executeUI(function() { 
		executeCommand("org.scalaide.refactoring.OrganizeImports");
		editor.close(true);
	});
}

I would like to save/close the a file when the refactor has totally completed and I would like to handle the next file when the previous editor has fully closed.

Any thoughts on a good approach?

To be clear: The script actually does work. It just tries to run the command and save all the files at once. The files start being processed at a rate of two or three a second, so it is waiting for something to start each one, but it is not waiting for completion.

Thanks.




The full script is:
loadModule('/System/Resources');
loadModule('/System/Environment');
loadModule('/System/Platform');
loadModule('/System/UI');

var files = findFiles("*.scala", "workspace://OrcScala/src/");
print("files: ");
for each (var f in files) {
	print(f);
	var editor = showEditor(f);
	executeUI(function() { 
		executeCommand("org.scalaide.refactoring.OrganizeImports");
		editor.close(true);
	});
}

[Updated on: Fri, 20 January 2017 01:03]

Report message to a moderator

Re: Waiting for a command to complete [message #1752272 is a reply to message #1752213] Fri, 20 January 2017 13:52 Go to previous messageGo to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
Hi Arthur,

executeCommand() calls the command handler, in your case directly from the UI thread as you pushed the code (correctly) there. Now it depends on what the handler does. From its name I guess it might push its exeution into a background thread to not block the UI thread it was called from. In that case your only chance would be that this background thread somehow signals when it is done. Your best chance is to find the command contribution and look into its handler implementation.

Christian
Re: Waiting for a command to complete [message #1752286 is a reply to message #1752272] Fri, 20 January 2017 15:52 Go to previous messageGo to next message
Arthur Mising name is currently offline Arthur Mising nameFriend
Messages: 4
Registered: July 2009
Junior Member
Alright. Thanks.

Is there a well known event that is published when an editor closes?

I have looked, but I cannot find any list of events or any way to print out all events as they occur so I can see if there is any useful event.
Re: Waiting for a command to complete [message #1752309 is a reply to message #1752213] Fri, 20 January 2017 20:55 Go to previous message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
Editors do fire change events, so probably you could listen for one of them, but I am not the expert on this. Ev. ask on the SWT forum.

Christian
Previous Topic:debugging java code - during EASE script execution
Next Topic:using ease with plugins
Goto Forum:
  


Current Time: Fri Oct 04 15:53:13 GMT 2024

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

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

Back to the top