Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 254984 - [Progress] IWorkbenchSiteProgressService's schedule(Job, long, boolean) method ignores third parameter after the first call
Summary: [Progress] IWorkbenchSiteProgressService's schedule(Job, long, boolean) metho...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Prakash Rangaraj CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 255005 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-11-12 02:17 EST by Remy Suen CLA
Modified: 2009-06-03 13:44 EDT (History)
2 users (show)

See Also:


Attachments
Sample ViewPart to reproduce the problem. (1.72 KB, application/octet-stream)
2008-11-12 02:17 EST, Remy Suen CLA
no flags Details
Patch v01 (1.56 KB, patch)
2008-12-16 01:39 EST, Prakash Rangaraj CLA
no flags Details | Diff
Patch v02 (4.47 KB, patch)
2008-12-18 03:55 EST, Prakash Rangaraj CLA
no flags Details | Diff
Patch v03 + Tests (15.62 KB, patch)
2009-01-29 04:47 EST, Prakash Rangaraj CLA
pwebster: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2008-11-12 02:17:14 EST
Created attachment 117624 [details]
Sample ViewPart to reproduce the problem.

IWorkbenchSiteProgressService's schedule(Job, long, boolean) method spec's that the third boolean argument is for specifying whether a "half busy" mouse cursor should be used or not while the job is being run. However, this boolean parameter is actually only honoured on the first call (or the first call to schedule(Job) or schedule(Job, long), which uses 'false' as the parameter). Subsequent calls will ignore this parameter completely.

The implementation method in WorkbenchSiteProgressService is like so...

public void schedule(Job job, long delay, boolean useHalfBusyCursor) {
  job.addJobChangeListener(getJobChangeListener(job, useHalfBusyCursor));
  job.schedule(delay);
}

...and getJobChangeListener(Job, boolean) looks like so...

public IJobChangeListener getJobChangeListener(final Job job, boolean useHalfBusyCursor) {
  if (listener == null) {
    updateJob.useWaitCursor = useHalfBusyCursor;
    listener = new JobChangeAdapter() {
      /* code commented out */
    };
  }
  return listener;
}

...so as you can see, after the job listener has been created by the first invocation of the schedule method, the parameter is no longer read and the service's updateJob is stuck with the boolean flag that was set by the first invocation.

Please see the attached ViewPart subclass of some sample code that demonstrates the problem. Once you click one of the two buttons, you will notice that clicking the other one will not alter the cursor state as you might expect.
Comment 1 Prakash Rangaraj CLA 2008-12-16 01:39:50 EST
Created attachment 120539 [details]
Patch v01

I don't find any reason why the wait cursor can't be set in schedule() method itself. Attached patch does that and works fine
Comment 2 Remy Suen CLA 2008-12-16 02:02:02 EST
(In reply to comment #1)
> Created an attachment (id=120539) [details]
> Patch v01
> 
> I don't find any reason why the wait cursor can't be set in schedule() method
> itself. Attached patch does that and works fine

This solution does not take the scheduling of multiple jobs into account as it's just arbitrarily setting the boolean parameter based on the most recent call. Consider the code below...

service.schedule(job, 10000, true);
service.schedule(job2, 1000, false);

One second passes and 'job2' starts running without the cursor change, let's say it ends after four seconds. Five seconds later, 'job' will start running but the cursor will not change even though the boolean parameter was set to 'true' because the most recent invocation has overrode the flag with 'false'.
Comment 3 Prakash Rangaraj CLA 2008-12-18 03:55:38 EST
Created attachment 120792 [details]
Patch v02

The busy cursor will be shown only if there is at least one job which has requested for it is in busy state.

This also fixes Bug# 255005.

Remy,
    Whats wrong in removing a listener in side a callback method?
Comment 4 Paul Webster CLA 2008-12-30 14:55:38 EST
(In reply to comment #3)
> Created an attachment (id=120792) [details]
> Patch v02

This looks pretty good.  Please write a test that has overlapping jobs that demonstrates the code works (and that the removal during done() has no ill effects).

PW
Comment 5 Remy Suen CLA 2008-12-30 15:04:31 EST
(In reply to comment #3)
> This also fixes Bug# 255005.
> 
> Remy,
>     Whats wrong in removing a listener in side a callback method?

It "feels" like an unorthodox method of doing things to me but if that's what we have to do then that's how it is.

On Paul's note about tests, if you're going to fix 255005 too in one go then please merge my leak test from attachment 117862 [details] into your patch while you're at it (or write your own variant). Thanks for the help, Prakash.
Comment 6 Paul Webster CLA 2009-01-21 14:38:44 EST
(In reply to comment #4)
> (In reply to comment #3)
> > Created an attachment (id=120792) [details] [details]
> > Patch v02
> 
> This looks pretty good.  Please write a test that has overlapping jobs that
> demonstrates the code works (and that the removal during done() has no ill
> effects).
> 

I just need a test for this and Remy's leak test from bug 255005 attachment 117862 [details] and it can go in as well.

PW

Comment 7 Prakash Rangaraj CLA 2009-01-29 04:47:50 EST
Created attachment 124128 [details]
Patch v03 + Tests

Patch with tests added. Remy's leak test (Bug# 255005) is also added in this patch
Comment 8 Prakash Rangaraj CLA 2009-01-29 04:57:11 EST
*** Bug 255005 has been marked as a duplicate of this bug. ***
Comment 9 Paul Webster CLA 2009-02-10 14:41:20 EST
Released to HEAD >20090210
PW
Comment 10 Remy Suen CLA 2009-02-12 12:08:49 EST
(In reply to comment #9)
> Released to HEAD >20090210

Wait, don't we need a CQ for this?
Comment 11 Paul Webster CLA 2009-02-12 12:38:47 EST
(In reply to comment #10)
> 
> Wait, don't we need a CQ for this?

no, our good friend Prakash works for a member company and is contributing with the full knowledge of the PMC :-)

PW

Comment 12 Prakash Rangaraj CLA 2009-03-11 02:27:39 EDT
Verified in I20090310-0100