java - How to use Timer and SwingWorker in an Eclipse Plugin? -


i'm developing eclipse plugin contribute gui view.

the view updated informations versioning system when user selects folder or file in workspace.

in order avoid collecting data everytime user goes through project subfolders , files, need wait 3 seconds in order sure file or folder 1 of interest.

i'm doing using swing timer.

this ok small amount of data, large amount of data gui blocks, waiting timer execute update function.

i know kind of task can use swingworker can't figure out how delay task , restart delay when needed.

can give me solution on how correctly solve problem ?

here current code:

  public void resettimerifneeded()     {         if(timer.isrunning())             timer.restart();         else             timer.start();     }       public void timer()     {         selectiontimer = new timer(3000, new actionlistener() {             @override             public void actionperformed(actionevent arg0) {                 // todo auto-generated method stub                   display.getdefault().syncexec(new runnable(){                     @override                     public void run()                     {                                        updateview();                         selectiontimer.stop();                                       }                 });              }         });     } 

since eclipse uses swt rather swing best avoid using swing code.

you can run code in ui thread after delay using uijob, like:

uijob job = new uijob("job title") {         @override         public istatus runinuithread(iprogressmonitor monitor) {              updateview();              return status.ok_status;         }     };  job.schedule(3000); 

alternatively can use display.timerexec:

display.getdefault().timerexec(3000, new runnable(){          @override          public void run()          {                           updateview();          }     }); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -