CDI ButtonCell

The full code and demo jUnit you will find under : BitBucket Repo - RapidPM - Modules - javafx-filtered-tableview 
Please use the release/1.1.1 branch and a commit after 6e440e2 

Today I needed a button inside my TableView. Something needed to be activated, based on some other values in this row. How to do this in a nice, lean and decoupled way? One goal was the possibillity that the definition could be done inside the fxml - file. Let´s start with the basic cdi managed ButtonCell: The main part here is the method setOnAction(): With this we are iterating over a list of ButtonCellActions.
Now we have to implement a class for our used TableView. In this example an simple delete-button.
At this point we are able to inject all the needed logic (here :DeleteButtonLogic) to fullfill our task. The logic will be activated inside an implementtion of the class ButtonCellAction. The order you are filling the Actions is the order the actions are processed. quite easy and mostly all you need.
The implementation is easy, but we want to put this to an fxml file like the following?: For this we need the CellFactory and the CellValueFactory. Both implementations are small: This is all.. and the result is nice and clean..


Beliebte Posts