package org.simantics.scl.ui.console;
-import gnu.trove.set.hash.THashSet;
-
import java.util.ArrayList;
import org.eclipse.core.runtime.IProgressMonitor;
import org.simantics.scl.ui.assist.SCLContentProposalProvider;
import org.simantics.scl.ui.assist.StyledTextContentAdapter;
+import gnu.trove.set.hash.THashSet;
+
/**
* An SCL console with input and output area that can be embedded
* into any editor or view.
*/
public class SCLConsole extends AbstractCommandConsole {
public static final String JOB_NAME = "org.simantics.scl.console.job";
+ public static final long TERMINATE_GRACE_PERIOD = 1000L;
private THashSet<Job> currentJobs = new THashSet<Job>();
- private Thread currentThread;
private final IdentitySchedulingRule schedulingRule = new IdentitySchedulingRule();
private ArrayList<SCLConsoleListener> listeners = new ArrayList<SCLConsoleListener>(2);
private boolean consoleIsEmpty = true;
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- synchronized(currentJobs) {
- currentJobs.remove(this);
- currentThread = Thread.currentThread();
- }
session.execute(command, handler);
} finally {
synchronized(currentJobs) {
- currentThread = null;
+ currentJobs.remove(this);
if(currentJobs.isEmpty())
for(SCLConsoleListener listener : listeners)
listener.finishedExecution();
}
return Status.OK_STATUS;
}
+
+ @Override
+ protected void canceling() {
+ Thread thread = getThread();
+ if(thread != null)
+ thread.interrupt();
+
+ try {
+ Thread.sleep(TERMINATE_GRACE_PERIOD);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ thread = getThread();
+ if(thread != null)
+ thread.stop();
+ }
};
job.setRule(schedulingRule);
synchronized(currentJobs) {
for(Job job : currentJobs)
job.cancel();
currentJobs.clear();
- if(currentThread != null)
- currentThread.interrupt();
}
}