Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 332511 - [Widget] add/removeListener(type, listener) does not mix with e.g. add/removeVerifyListener
Summary: [Widget] add/removeListener(type, listener) does not mix with e.g. add/remove...
Status: RESOLVED FIXED
Alias: None
Product: RAP
Classification: RT
Component: RWT (show other bugs)
Version: 1.4   Edit
Hardware: PC All
: P4 normal (vote)
Target Milestone: 2.0 M3   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 334028
Blocks:
  Show dependency tree
 
Reported: 2010-12-14 06:06 EST by Jürgen Becker CLA
Modified: 2012-10-12 07:19 EDT (History)
2 users (show)

See Also:


Attachments
Sample project for reproducing issue (5.92 KB, application/x-zip-compressed)
2010-12-17 01:45 EST, Elias Volanakis CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jürgen Becker CLA 2010-12-14 06:06:49 EST
If I add e.g. a VerifyListener with text.addVerifyListener(listener), I can not remove it with text.removeListener(SWT.Verify, listener).

The problem is, all "untyped" listeners added with addListener(type, listener) are stored in the field untypedAdapter (EventAdapter), but the typed listeners are stored in EventAdapter instances specific to the type.

Since the different EventAdapter instances do not know about each other, the mixture of add/removeListener and add/remove<Type>Listener methods does not work.

The win32 SWT implementation uses one EventTable instance for both typed an untyped listeners. Maybe that would be a solution for RWT too.
Comment 1 Jürgen Becker CLA 2010-12-14 06:09:28 EST
I think the bug #286039 is related.
Comment 2 Ralf Sternberg CLA 2010-12-16 09:26:43 EST
Not sure if I understand your request. Text#addVerifyListener( VerifyListener ) and Widget.removeListener( int, Listener ) have incompatible argument types. Could you post a snippet that explains your use case?
Comment 3 Elias Volanakis CLA 2010-12-17 01:40:24 EST
I'm attaching an example project (snippet, see snippet.Snippet.java).

The issue is the following difference between SWT and RWT:

text.addVerifyListener(vl);
Assert.isLegal(text.getListeners(SWT.Verify).length == 1);

In RAP the result has 0 entries (and it breaks our code).

Would it be possible to change the behavior to match SWT ?
Comment 4 Elias Volanakis CLA 2010-12-17 01:45:15 EST
Created attachment 185399 [details]
Sample project for reproducing issue

Sample single-sourced project (name: 'snippet')
Comment 5 Elias Volanakis CLA 2010-12-17 01:51:30 EST
The second incompatibility is that in SWT typed listeners are wrapped in untyped listeners, so you can remove the typed listener by way of widget.remove(SWT.Verify, untypedListener) -- this is also demoed in the snippet.
Comment 6 Elias Volanakis CLA 2010-12-17 02:12:02 EST
@Riena-Team: I've found a workaround using internal RWT code. I'll single source the affected code. See Bug 332819 for details.

VerifyListener[] listeners2 = (VerifyListener[]) VerifyEvent.getListeners(text); // 1 entry
for(VerifyListener lsnr : listeners2) {
VerifyEvent.removeListener(text, lsnr);
}

@RAP-Team: less urgent now, but it would be nice to investigate if this can be made to work same way as in SWT.
Comment 7 Rüdiger Herrmann CLA 2010-12-17 03:49:02 EST
For historical reasons, typed and untyped listeners in RWT are handled the opposite way as in SWT. In W4Toolkit, the predecessor of RWT, there were only typed listeners and RWT started out with having only typed listeners as well. As a consequence, in RWT untyped listeners are wrapped in typed listeners.

From my own experience I can tell, that reworking this is a rather large undertaking. Otherwise I would have changed this already.

This also blocks bug 308527 and bug 286039.
Comment 8 Christian Campo CLA 2010-12-17 04:42:57 EST
I understand that reworking a historical thing is a large undertaking and of course its your call whether you have the resources for this.

I am a little concerned that using RAP is not the same as using SWT at this specific point. Maybe you can think of a less ressource consuming way to hide the difference.

Because while Elias has now fixed or worked-around this one issue it well be that we have other issues where we use VerifyListeners and where we assume that RAP works the same as SWT.

What do you think ?
Comment 9 Elias Volanakis CLA 2010-12-20 00:37:34 EST
FYI - I've single sourced all places where this was an issue in Riena
Comment 10 Jürgen Becker CLA 2010-12-23 03:12:57 EST
@Elias / Riena Team

Their is a simpler workaround. 

in the method TextRidget.forceTextToControl(...) we can replace

final Listener[] vListeners = removeListeners(control, SWT.Verify);
final Listener[] mListeners = removeListeners(control, SWT.Modify);
TextRidget.this.setUIText(newValue);
addListeners(control, SWT.Modify, mListeners);
addListeners(control, SWT.Verify, vListeners);

with:

removeListeners(control);
TextRidget.this.setUIText(newValue);
addListeners(control);

All classes derived from TextRidget implement the two methods add/removeListeners.
In this special case we do not need to single-source. I don't know if their are other cases.
Comment 11 Ralf Sternberg CLA 2011-01-11 15:16:28 EST
(In reply to comment #8)
> I understand that reworking a historical thing is a large undertaking and of
> course its your call whether you have the resources for this.
> 
> I am a little concerned that using RAP is not the same as using SWT at this
> specific point. Maybe you can think of a less ressource consuming way to hide
> the difference.

Hi Christian, I don't see a shortcut here but I'm sure that we will sooner or later take the time to rework the event system. I opened bug 334028 for this.

However, since the deviations between the RAP and the SWT event systems are only marginal, there are still a couple of higher priorities to work on. I'd consider the scenario described above (adding a typed listener but removing the wrapped untyped one) a rare use case.
Comment 12 Rüdiger Herrmann CLA 2012-10-12 07:19:51 EDT
Resolved while reworking the event system (bug 334028)