53 lines
1.4 KiB
Java
53 lines
1.4 KiB
Java
package envoy.client.ui.listcell;
|
|
|
|
import javafx.scene.control.ListCell;
|
|
import javafx.scene.control.ListView;
|
|
import javafx.util.Callback;
|
|
|
|
import envoy.data.Contact;
|
|
|
|
/**
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>ContactListCellFactory.java</strong><br>
|
|
* Created: <strong>13.07.2020</strong><br>
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @param <T> the type of contact to display
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public class ContactListCellFactory<T extends Contact> implements Callback<ListView<T>, ListCell<T>> {
|
|
|
|
/**
|
|
* Wraps a the {@link ContactControl} inside a list cell.
|
|
*
|
|
* @param <T> the type of contact to display
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public static final class ContactListCell<T extends Contact> extends ListCell<T> {
|
|
|
|
private final ListView<T> listView;
|
|
|
|
/**
|
|
* @param listView the list view containing this list cell
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public ContactListCell(ListView<T> listView) { this.listView = listView; }
|
|
|
|
@Override
|
|
protected void updateItem(T contact, boolean empty) {
|
|
super.updateItem(contact, empty);
|
|
if (empty || contact == null) {
|
|
setText(null);
|
|
setGraphic(null);
|
|
} else {
|
|
final var control = new ContactControl(contact);
|
|
prefWidthProperty().bind(listView.widthProperty().subtract(40));
|
|
setGraphic(control);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ListCell<T> call(ListView<T> listView) { return new ContactListCell<>(listView); }
|
|
}
|