For a JFXTreeTableColumn I wrote a custom Cell Factory as Callback. Code works fine but what if I want to pass different Generics?
I already tried to pass the Generics as ? or T, S but I definitely did something wrong
public class CallbackImpl implements Callback<TreeTableColumn<Order, String>, TreeTableCell<Order, String>> {
private final ObservableList<String> paymentData;
public CallbackImpl(ObservableList<String> paymentData) {
this.paymentData = paymentData;
}
@Override
public TreeTableCell<Order, String> call(TreeTableColumn<Order, String> tc) {
ComboBox<String> combo = new ComboBox<>();
combo.getItems().addAll(paymentData);
JFXTreeTableCell<Order, String> cell = new JFXTreeTableCell<Order, String>() {
@Override
protected void updateItem(String payment, boolean empty) {
super.updateItem(payment, empty);
if (empty) {
setGraphic(null);
} else {
combo.setValue(payment);
setGraphic(combo);
}
}
};
return cell ;
}
}
I want to to pass a Table with <DifferentClass, String> or even <DifferentClass, Integer> (I know that i have to change the code for Integer to work).
Usage in FXML Controller:
col.setCellFactory(new CallbackImpl(paymentData));
I just did a quick change to generics. Since I don't have full code, I dunno if it will all work (or if everything I changed SHOULD be changed) but it will give you rough idea how to attempt to do it :D
class CallbackImpl<V, U> implements Callback<TreeTableColumn<V, U>, TreeTableCell<V, U>>
{
private final ObservableList<U> paymentData;
public CallbackImpl(ObservableList<U> paymentData) {
this.paymentData = paymentData;
}
@Override
public TreeTableCell<V, U> call(TreeTableColumn<V, U> tc) {
ComboBox<U> combo = new ComboBox<>();
combo.getItems().addAll(paymentData);
JFXTreeTableCell<V, U> cell = new JFXTreeTableCell<V, U>() {
@Override
protected void updateItem(U payment, boolean empty) {
super.updateItem(payment, empty);
if (empty) {
setGraphic(null);
} else {
combo.setValue(payment);
setGraphic(combo);
}
}
};
return cell ;
}
}
Just make whole CallbackImpl generic, and then you can specify what you wish to give it when using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With