Click Framework  History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: CLK-369
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Bob Schellink
Reporter: Bob Schellink
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Click

Investigate adding ActionListener objet to Controls

Created: 27/May/08 01:32 AM   Updated: 01/Oct/08 10:08 PM
Component/s: core
Affects Version/s: 1.5 M2
Fix Version/s: 1.5 M2


 Description  « Hide
Currently the listener registered on Controls is string based.

While simple to create it is harder to maintain as refactoring cannot be applied when renaming the method.

An alternative to the string based listener is to introduce a ActionListener object that encapsulates the callback, and a method, AbstractControl.setListener(ActionListener) which registers the listener on the control.

public class ActionListener {
    public boolean onAction(Control control) {
        return true;
    }
}


 All   Comments   Change History      Sort Order:
Malcolm Edgar [27/May/08 09:00 AM]
I presume the use case is:

button.setActionListener(new ActionListener() {
      public boolean onAction(Control control) {
            // TODO
            return true;
      }
});

Passing the event source is a good idea. An early version of the string based method did this, but I never used the event source much. However in more complex scenarios you can definitely see the benefit.

This class could go in the net.sf.click.control or net.sf.click.util package. I think the control package would be the best place.

regards Malcolm Edgar

Bob Schellink [27/Jun/08 11:06 PM]
net.sf.click.ActionListener interface added which supersedes the current String based listener approach.