0

I have a RCP GUI in which I want to do an icon "refresh": when the user click on it, it is disabled. After 3 second it is enabled again.

I would like to find a way to do it withou thread.

I followed this tutorial: Enabling/Disabling Toolbar-Command based on selection in ViewPart, not Perspective It works but my problem is that I don't see how to make eclipse reactivate the button, without doing a TimerThread...

Any ideas?

4

1 回答 1

0

如果没有线程,您可以在 while 循环中执行此操作:

long start = System.currentTimeMillis();
long current = start;
long threeSecondsAsMillis = 3 * 1000;
long oneSecondsAsMillis = 1000;

while (current < start + threeSecondsAsMillis) {
    Thread.sleep(oneSecondsAsMillis);
    current += oneSecondsAsMillis;
}
// continue your work

请注意,这是一个糟糕的解决方案,因为它会阻止您的 UI。更好的解决方案是使用 Eclipse Job:

    Job job = new Job("") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    // note, that you are not in the UI-Thread anymore, but you must enable icon in the UI-Thread:


    Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
            // enable icon
            }
        });
        return Status.OK_STATUS;
 }
 };
job.schedule(3000);

如 greg-449 所述,您还可以使用 UIJob:

UIJob job = new UIJob("") {

                @Override
                    public IStatus runInUIThread(IProgressMonitor monitor) {


    // enable icon
                    return Status.OK_STATUS;
                }
            };
            job.schedule(3000);
于 2013-10-21T06:49:39.920 回答