Table generated column with a link - how to detect the row?

Hi,

how can I get the row that has been clicked if I place a Button using ColumnGenerator in a table cell?

From the desing point of view, I have an TableUI class that defines all UI component stuff, without behaviour. Behaviour and logic is implemented in TableViewModel, which can register a ClickListener to the table.
Also the ColumnGenerator is wrapped in an own class.

So, how could I access the table row clicked? Because actually no real row is clicked, but just the button in the row. So there is no ItemClickEvent when clicking the button.


//presenter class
class TableViewModel {

  private TableUI ui;

  private ClickListener editListener = new ClickListener() {
	@Override
	public void buttonClick(ClickEvent evt) {
		// how to detect the row? eg to delete or edit it
	}
  };

  init(TabbleUI ui) {
	this.ui = ui;
	ui.getEditButton().addClickListener(editListener);
  }
}


//ui class
class TableUI {
	private Table table;

	void init() {
		table.addGeneratedColumn("modify", new ModifyColumnGenerator());
	}
}

//the custom column generator
class ModifyColumnGenerator() extends ColumnGenerator {
	private Button editButton;
	@Override
	public Component generateCell(final Table source, final Object itemId, final Object columnId) {
		//init probably several buttons an layout in a HorizontalLayout
                editButton.addStyleName("link");
                return layout;
	}

	public Button getEditButton() {
		return editButton;
	}
	
}

You can implement the button listener directly on the generateCell, like:



@Override
public Component generateCell(final Table source, final Object itemId, final Object columnId) {
                //init probably several buttons an layout in a HorizontalLayout
                editButton.addStyleName("link");
                editButton.addClickListener(new Button.ClickListener() {
                      public void onClick(ClickEvent evt) {
                                 doSomethingWithMyItemId(itemId);
                      }
                 });
                return layout;
    }