
|
If you were logged in you would be able to see more operations.
|
|
|
Click
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
|
|
|
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;
}
}
|
|
Description
|
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;
}
}
|
Show » |
|
|
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