Run a long feature with a ProgressBar [message #1311085] |
Wed, 23 April 2014 15:38 |
Antoine Lorence Messages: 3 Registered: September 2013 |
Junior Member |
|
|
In our project, we have 2 or 3 custom features very important but sometimes long to run (depending on the diagram). This is not a problem, but user often think eclipse is crashing, when the feature is simply doing its job. To avoid that, we want to display a progress bar (we don't care the way to do that).
I tried to perform that with IRunnableWithProgress / ProgressMonitorDialog.
@Override
public void execute(ICustomContext context) {
IRunnableWithProgress theTask = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("My cool feature", 10);
bigAndLongWork(monitor);
monitor.done();
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay()
.getActiveShell()).run(true, false, theTask);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
(full code on Github gists: alorence/11219910, sorry I can't post links)
Obviously, it works with simple code, but fails with a RollbackException "Transaction aborted due to concurrent write" if I modify models in the feature (and we do it ;))
Is there a way to run a Command in the editing domain (or any other solution) with a progress monitor we can update to inform user that the job is running, and the IDE is not dead ?
[BONUS question] In some case, the GUI freeze because our computations can become really heavy. Is it possible to run this job asynchronously, with a progress bar ?
|
|
|
Re: Run a long feature with a ProgressBar [message #1311511 is a reply to message #1311085] |
Wed, 23 April 2014 21:12 |
Soeren M Messages: 77 Registered: September 2011 |
Member |
|
|
I just can give you some hints, but I dont know if it works for you...
If I can't edit the model due to write permissions I'll use this:
TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(getDiagram());
ted.getCommandStack().execute(new RecordingCommand(ted) {
@Override
protected void doExecute() {
//edit here
}
});
Well, I dont know if it fits into your async problem, but maybe that:
Display.getDefault().asyncExec(new Runnable() {
public void run() {
//edit
}
});
is able to fix it, good luck
[Updated on: Wed, 23 April 2014 21:14] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03084 seconds