views:

11

answers:

1

i want to design a FlexTable programmaticaly which looks like this: http://uploadz.eu/images/v4z6gucp2gg8ql9pzj.png

Since OnClick Methods can't get other Parameters then an Event and the buttons don't know "on which row they are", i can't tell the button "please swap the row, where you currently are with your buddy on top of you". I would like to know: What's a good way to do this?

A: 

ClickEvents have a getSource() method which contains the source of the event, which is helpful.

public class NiceLabel {
  public final Row row;
  public NiceLabel(Row row, ClickHandler clickHandler) {
    this.row = row;
    addClickHandler(clickHandler);
  }
}

...
// clickHandler has the following:
public void onClick(ClickEvent event) {
  ((NiceLabel) event.getSource()).row.moveUp();
}

And in this way you can add the same ClickHandler to every NiceLabel without having to create a new one for each row.

Jason Hall