New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to add and obtain typed listeners to Widgets #1112
Add API to add and obtain typed listeners to Widgets #1112
Conversation
* | ||
* @since 3.126 | ||
*/ | ||
public EventListener[] getTypedListeners(int eventType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment I choose to return an array to not mix styles here, but if I could freely choose I would return a List or even a Stream.
Do you have opinions on that?
Good idea and it gets rid of a lot of duplicate boiler-plate code (null check etc). Thank-you for your work on this.
How do you see that panning out? Our product uses two Nebula widgets and their code makes use of the Yes, we know that |
I personally would prefer List over Array but assume for migration to the new API in libraries it might be easier to use arrays. |
Nebula is an open source project and has regular releases and is tightly coupled to SWT/Platform so I don't see why it should not be possible to change to modern SWT patterns.... |
7895867
to
ba7cb0b
Compare
I just updated the code handle custom typed Listeners that omit the With that this PR is ready for me.
Your welcome, glad you like it.
I agree with Christoph here, from all I see/know about Nebula it should absolutely be possible to migrate it to the new methods and I'm willing to help with that. I'll also inform other projects in sim-rel about this.
Don't worry I don't plan to set the world on fire, just cautiously try to cut a tree. :)
Yes, I think consistency in the API should be maintained. |
7424621
to
14e056a
Compare
I consider no responses as silent consent from everyone already participating. |
8c52a8c
to
839f407
Compare
While preparing the first applications of this new API and reviewing this change I again I found that What do you think? |
Please never combine arrays and generics. From my experience this will break something sooner or later. |
As long as there is a Class argument to create the array it’s probably fine. Otherwise I generally agree. |
I agree those can be confusing or error-prone. What about using |
@iloveeclipse Can you give some examples for this specific case?
If we are fine to be inconsistent with the existing methods I would just return a |
I have now changed the method to return a |
We should not keep styles just because they where there forever, Streams are actually the better return type in any aspect:
|
Absolutely. |
We are fine with adopting a newer style for newer code. |
0e82203
to
e92eba1
Compare
Great, so let's submit this then. |
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Use the new API introduced in SWT via eclipse-platform/eclipse.platform.swt#1112
Leverage new methods introduced in eclipse-platform/eclipse.platform.swt#1112
Leverage new methods introduced in eclipse-platform/eclipse.platform.swt#1112
Leverage new methods introduced in eclipse-platform/eclipse.platform.swt#1112
Leverage new methods introduced in eclipse-platform/eclipse.platform.swt#1112
Leverage new methods introduced in eclipse-platform/eclipse.platform.swt#1112
One of the two main, if not the only reasons why the actually (according to its doc) internal SWT type
TypedListener
and consequently also the internal typeSWTEventListener
is referenced in client code is to register typed listeners in custom widgets.One example in the Eclipse SDK (outside SWT) is:
https://github.com/eclipse-platform/eclipse.platform/blob/c74c80065aa91f5e2f03377aae1cd80928e48534/ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/HyperlinkLabel.java#L157-L164
The second pattern why
TypedListener
is used is to obtain the initially registered typed listeners from a widget:https://github.com/eclipse-platform/eclipse.platform/blob/c74c80065aa91f5e2f03377aae1cd80928e48534/team/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java#L3109-L3119
This pattern is used very often as one can see for example in the repositories of the eclipse organisation or CDT (and probably in more):
This PR suggests to add two new methods to the Widget class to add and obtain typed listeners, which can act as API replacement for the patterns mentioned above and also significantly reduces code-duplications in SWT's own code base (see second commit):
protected void addTypedListener(EventListener listener, int... eventTypes)
public EventListener[] getTypedListeners(int eventType)
With that we can subsequently deprecate
SWTEventListener
for removal andTypedListener
to be moved to an internal package.