You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Frédéric VERGEZ (JIRA)" <ji...@apache.org> on 2010/11/16 14:22:15 UTC

[jira] Created: (PIVOT-670) Generic types for listeners

Generic types for listeners
---------------------------

                 Key: PIVOT-670
                 URL: https://issues.apache.org/jira/browse/PIVOT-670
             Project: Pivot
          Issue Type: Improvement
          Components: wtk
    Affects Versions: 1.5.2
         Environment: All
            Reporter: Frédéric VERGEZ
            Priority: Trivial
             Fix For: 2.1


Could listener interfaces have generic types ?

This would allow to be type safe in methods, and avoid objects casting.

For instance in a ComponentMouseListener:


public interface ComponentMouseListener<T extends Component> {
    /**
     * Component mouse button listener adapter.
     */
    public static class Adapter implements ComponentMouseListener {
        @Override
        public boolean mouseMove(T component, int x, int y) {
            return false;
        }

        @Override
        public void mouseOver(T component) {
        }

        @Override
        public void mouseOut(T component) {
        }
    }

    /**
     * Called when the mouse is moved over a component.
     *
     * @param component
     * @param x
     * @param y
     *
     * @return
     * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
     * propagate.
     */
    public boolean mouseMove(T component, int x, int y);

    /**
     * Called when the mouse enters a component.
     *
     * @param component
     */
    public void mouseOver(T component);

    /**
     * Called when the mouse exits a component.
     *
     * @param component
     */
    public void mouseOut(T component);
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIVOT-670) Generic types for listeners

Posted by "Frédéric VERGEZ (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932678#action_12932678 ] 

Frédéric VERGEZ commented on PIVOT-670:
---------------------------------------

As i'm looking at the sources, agreed that it can have many impacts...
But using listeners in many UI frameworks (GWT, RCP ...), i generally consider using a single/shared listener for distinct classes as a bad idea. 

> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIVOT-670) Generic types for listeners

Posted by "Frédéric VERGEZ (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932698#action_12932698 ] 

Frédéric VERGEZ commented on PIVOT-670:
---------------------------------------

Good point
Yes, GWT has the same issue on listeners, and was coded the very same way (using Widget). 
Slightly changing though, with Events and Handlers (with some generic in it)

> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PIVOT-670) Generic types for listeners

Posted by "Frédéric VERGEZ (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932678#action_12932678 ] 

Frédéric VERGEZ edited comment on PIVOT-670 at 11/16/10 5:08 PM:
-----------------------------------------------------------------

As i'm looking at the sources, agreed that it can have many impacts...
But using listeners in many UI frameworks (GWT, RCP ...), i generally consider using a single/shared listener for distinct classes as a bad idea. 
Sorry to bother though, and thank you for all the good work done. Pivot is really, really making my day :)

      was (Author: ikarius):
    As i'm looking at the sources, agreed that it can have many impacts...
But using listeners in many UI frameworks (GWT, RCP ...), i generally consider using a single/shared listener for distinct classes as a bad idea. 
  
> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIVOT-670) Generic types for listeners

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932686#action_12932686 ] 

Greg Brown commented on PIVOT-670:
----------------------------------

> i generally consider using a single/shared listener for distinct classes as a bad idea. 

Component fires events that are shared by all components, and each subclass fires its own class-specific events. Are you suggesting that only concrete classes should fire events? If so, how would you handle common events (such as mouse move, etc.)?

Doesn't GWT have the same issue? For example, the com.google.gwt.user.client.ui.MouseListener interface passes a Widget as the sender argument to all of the user input event handler methods.



> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PIVOT-670) Generic types for listeners

Posted by "Noel Grandin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932652#action_12932652 ] 

Noel Grandin commented on PIVOT-670:
------------------------------------

Plus it would be a major pain to implement because every single subclass of wtk.Component would need to specify itself in the extends clause since Java doesn't support self types.

And we'd have to override the listener methods in every subclass to specify the correct return type.

And it would make certain types of generic programming, where you can define a listener object that operates on many different Component subclasses, much harder. 

> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (PIVOT-670) Generic types for listeners

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12932496#action_12932496 ] 

Greg Brown edited comment on PIVOT-670 at 11/16/10 10:26 AM:
-------------------------------------------------------------

That's a slippery slope. If we did that, we'd probably also want to make every listener interface a generic for consistency. I personally don't think it is worth it. IMO, there's nothing wrong with casting when you know what type to expect. Either way (explicit cast or generic type), you're going to get a ClassCastException if you do the wrong thing.


      was (Author: gbrown):
    That's a slippery slope. If we did that, we'd probably also want to make every listener interface a generic, for consistency. I personally don't think it is worth it. IMO, there's nothing wrong with casting when you know what type to expect. Either way (cast or generic type), you're going to get a ClassCastException if you do the wrong thing.

  
> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (PIVOT-670) Generic types for listeners

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Greg Brown resolved PIVOT-670.
------------------------------

    Resolution: Won't Fix

> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>             Fix For: 2.1
>
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (PIVOT-670) Generic types for listeners

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PIVOT-670?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Greg Brown updated PIVOT-670:
-----------------------------

          Component/s:     (was: wtk)
    Affects Version/s:     (was: 1.5.2)
        Fix Version/s:     (was: 2.1)

That's a slippery slope. If we did that, we'd probably also want to make every listener interface a generic, for consistency. I personally don't think it is worth it. IMO, there's nothing wrong with casting when you know what type to expect. Either way (cast or generic type), you're going to get a ClassCastException if you do the wrong thing.


> Generic types for listeners
> ---------------------------
>
>                 Key: PIVOT-670
>                 URL: https://issues.apache.org/jira/browse/PIVOT-670
>             Project: Pivot
>          Issue Type: Improvement
>         Environment: All
>            Reporter: Frédéric VERGEZ
>            Priority: Trivial
>
> Could listener interfaces have generic types ?
> This would allow to be type safe in methods, and avoid objects casting.
> For instance in a ComponentMouseListener:
> public interface ComponentMouseListener<T extends Component> {
>     /**
>      * Component mouse button listener adapter.
>      */
>     public static class Adapter implements ComponentMouseListener {
>         @Override
>         public boolean mouseMove(T component, int x, int y) {
>             return false;
>         }
>         @Override
>         public void mouseOver(T component) {
>         }
>         @Override
>         public void mouseOut(T component) {
>         }
>     }
>     /**
>      * Called when the mouse is moved over a component.
>      *
>      * @param component
>      * @param x
>      * @param y
>      *
>      * @return
>      * <tt>true</tt> to consume the event; <tt>false</tt> to allow it to
>      * propagate.
>      */
>     public boolean mouseMove(T component, int x, int y);
>     /**
>      * Called when the mouse enters a component.
>      *
>      * @param component
>      */
>     public void mouseOver(T component);
>     /**
>      * Called when the mouse exits a component.
>      *
>      * @param component
>      */
>     public void mouseOut(T component);
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.