commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Wooten (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-580) Add Event Support Utilities
Date Thu, 22 Jul 2010 16:34:52 GMT

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891231#action_12891231
] 

Michael Wooten commented on LANG-580:
-------------------------------------

James,

I'm proposing a best-of-both-worlds approach. I have added a patch to
the LANG-580 JIRA entry that combines both your classes and my own. I
changed your EventListenerSupport class to extend my
AbstractEventSupport class and removed the duplicated methods. This
leaves the AbstractEventSupport class as an extensible class that can
be extended as described in its JavaDocs, and replaces the
ReflectiveEventSupport implementation with your EventListenerSupport
implementation, which I agree is a far better solution.

I would prefer that the EventSupport interface remains, as it provides
a generic way to easily identify a class as being able to add and
remove listeners. I also think that there is a case for leaving
AbstractEventSupport, since it is designed to be extended and models
the behavior of PropertyChangeSupport.

There is also a new patch for LANG-580 that adds the package.html
file. This will probably need to be updated to include descriptions of
your classes.

Thanks.

-Michael




> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-merged.patch,
commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This
would be based on the way that PropertyChangeSupport can be used to add and remove listeners
and post events. 
> Add interface EventSupport<L extends EventListener> 
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will
be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener>
{
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this);
}
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener);
} 
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener);
} 
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be
used so that you're not constantly rewriting the code and interfaces for adding and removing
listeners, and it provides a fairly easy method of creating methods to fire events.

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


Mime
View raw message