I have created a Custom Table Cell in JavaFX, pursuant to this answer, so I can have different font styling for different parts of the cell's text.
I use this Custom Table Cell on two different types of TableViews:TableView<Track>
and TableView<Album>
.
Both Track
and Album
implement the Interface AlbumInfoSource
:
public interface AlbumInfoSource {
public String getAlbumTitle();
public String getFullAlbumTitle();
public String getReleaseType();
public String getDiscSubtitle();
public Integer getDiscCount();
public Integer getDiscNumber();
}
My Custom TableCell is typed with that AlbumInfoSource, so it can render cells for both a TableView<Album>
and a TableView<Track>
.
Here is the basic code:
public class FormattedAlbumCell<T, S> extends TableCell <AlbumInfoSource, String> {
private TextFlow flow;
private Label albumName, albumType, albumDisc;
public FormattedAlbumCell () {
/* Do constructor stuff */
}
@Override
protected void updateItem ( String text, boolean empty ) {
super.updateItem ( text, empty );
/* Do pretty rendering stuff */
}
}
And then I apply it to a column like this:
TableColumn<Album, String> albumColumn;
albumColumn = new TableColumn<Album, String>( "Album" );
albumColumn.setCellFactory( e -> new FormattedAlbumCell () );
Which works perfectly fine, but I get a warning on that last line, which says:
Warning: FormattedAlbumCell is a raw type. References to generic type FormattedAlbumCell< T ,S > should be parameterized
If I change my FormattedAlbumCell class such that it extends TableCell <Album, String>
, then the warning goes away. But then I can't use the FormattedAlbumCell for a TableView<Track>
, I would have to duplicate the FormattedAlbumCell class make it extend TableCell, which seems dumb to me.
Is there a way to get these parameters straight without creating two separate classes? It seems like the issue comes from the paramaterizing stuff having trouble with Interfaces.