}
}
- private boolean isExecuting = false;
+ private Delay delay = new Delay(Display.getCurrent());
+
+ private class Delay extends Thread{
+
+ private volatile boolean stop = false;
+ private Display display;
+
+ public Delay(Display display) {
+ this.display = display;
+ }
+ @Override
+ public void run() {
+
+ while (!stop) {
+ try {
+ // my code goes here
+ Thread.sleep(1000);
+ if(!stop){
+ display.syncExec(new Runnable() {
+ @Override
+ public void run() {
+ getEditor().getManagedForm().setInput(selection);
+ }
+ });
+ }
+ } catch (InterruptedException ex) {
+ stop = true;
+ }
+ }
+ }
+ public void requestStop() {
+ stop = true;
+ }
+ }
protected void setDelayedSelection() {
- // TODO this might be done better
- // this is the quickest solution i could come up with and it improves
- // performance
- // please reimplement if you know better.
selection = this;
- // start timer
Display display = Display.getCurrent();
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- getEditor().getManagedForm().setInput(selection);
- isExecuting = false;
- }
- };
- if(!isExecuting){
- isExecuting = true;
- display.timerExec(1000, runnable);
- }
+ delay.requestStop();
+ delay = new Delay(display);
+ delay.start();
}