Im currently passing my data through a constructor which fills in data requested from both my abstract and extended classes (i.e MusicItem Abstract and CD and Vinyl classes extended)
Im trying to print these into a Table View using JavaFX from my controller but nothing is showing up even with the system.out line placed.
I've tried putting them into Observable Lists as well as normal array lists, I've triple checked the data fields to see if they match the table and i tried viewing the the object at the moment its entered but when i do that, the hex code for that object shows up. It connects to the database properly but doesn't display anything
abstract class MusicItem {
@Id
private int songID;
private String name;
private String artist;
private String genre;
private String releaseDate;
private double price;
public MusicItem(int songID, String name, String artist, String genre, String releaseDate, double price) {
this.songID = songID;
this.name = name;
this.artist = artist;
this.genre = genre;
this.releaseDate = releaseDate;
this.price = price;
}
}
@Entity
class Vinyl extends MusicItem{
private double speed;
private double diameter;
Vinyl(int songID, String name, String artist, String genre, String releaseDate, double price, double speed, double diameter) {
super(songID, name, artist, genre, releaseDate, price);
this.speed = speed;
this.diameter = diameter;
}
}
@Entity
class CD extends MusicItem{
private double duration;
CD(int songID, String name, String artist, String genre, String releaseDate, double price, double duration) {
super(songID, name, artist, genre, releaseDate, price);
this.duration = duration;
}
}
public WestminsterMusicStoreManager() throws UnknownHostException {
}
@Override
public void insertItem() {
System.out.print("Please enter Song ID : ");
id = Validation.intValidate();
System.out.print("Please enter Song name : ");
name = Validation.stringValidate();
System.out.print("Please enter Artist : ");
artist = Validation.stringValidate();
System.out.print("Please enter genre of " + name + " : ");
genre = Validation.stringValidate();
System.out.println("Please enter the release date in the requested order: ");
releaseDate = date.getDate();
System.out.print("Please enter price of song : ");
price = Validation.doubleValidate();
System.out.println("Will you be entering a CD or Vinyl Entry");
String choice = Validation.stringValidate();
switch (choice.toLowerCase()){
case "vinyl":
System.out.print("Please enter diameter of vinyl : ");
diameter = Validation.doubleValidate();
System.out.print("Please enter speed of vinyl : ");
speed = Validation.doubleValidate();
Vinyl vinyl = new Vinyl(id,name,artist,genre,releaseDate,price,speed,diameter);
musicItemList.add(vinyl);
database.insertVinyl(vinyl);
System.out.println(name+" was succesfully added to the database with an ID of"+id);
break;
case "cd":
System.out.println("Please enter duration of the song");
duration = Validation.doubleValidate();
CD cd = new CD(id,name,artist,genre,releaseDate,price,duration);
musicItemList.add(cd);
System.out.println(cd);
database.insertCD(cd);
break;
default:
System.out.println("Your value needs to be a choice between either CD or Vinyl");
insertItem();
}
}
}
public class Controller implements Initializable {
public GridPane customerMainLayout;
@FXML private TableColumn<MusicItem, String> artistCol, songNameCol, durationCol, genreCol;
@FXML private TableColumn<MusicItem, String> priceCol;
@FXML private TableColumn<MusicItem, Double> speedCol,diameterCol;
@FXML private TableColumn<MusicItem, Integer> songIDCol, releaseYearCol;
public TableView<MusicItem> customerViewTable;
@FXML private static JFXTextField searchBar;
@FXML private static JFXButton searchBtn;
private WestminsterMusicStoreManager musicStoreManager =new WestminsterMusicStoreManager();
private ObservableList<MusicItem> musicItem = FXCollections.observableArrayList(musicStoreManager.musicItemList);
public Controller() throws UnknownHostException {
}
public void initialize(URL location, ResourceBundle resources) {
songIDCol.setCellValueFactory(new PropertyValueFactory<>("songID"));
songNameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
artistCol.setCellValueFactory(new PropertyValueFactory<>("artist"));
genreCol.setCellValueFactory(new PropertyValueFactory<>("genre"));
releaseYearCol.setCellValueFactory(new PropertyValueFactory<>("releaseDate"));
priceCol.setCellValueFactory(new PropertyValueFactory<>("price"));
durationCol.setCellValueFactory(new PropertyValueFactory<>("duration"));
speedCol.setCellValueFactory(new PropertyValueFactory<>("speed"));
diameterCol.setCellValueFactory(new PropertyValueFactory<>("diameter"));
addTableItems();
}
private void addTableItems() {
musicItem.forEach(musicItem -> {
if (musicItem instanceof CD){
CD cd = (CD)musicItem;
System.out.println(cd);
customerViewTable.getItems().add(cd);
}else {
Vinyl vinyl = (Vinyl)musicItem;
System.out.println(vinyl);
customerViewTable.getItems().add(vinyl);
}
});
}
}