In JavaFX 2 I have a TableView beeing populated by reading an Excel file. It looks like this:
identification cellcount calved
o0001 12345 false
o0002 65432 true
o0003 55555 false
...
When users press the 'Import' button, all records have to be added to a database. However, If the 'calved' field has 'true' as value, I show a Dialog window where the users have to select a date to specify when the calving happened. Now the big question is that I want my for loop beeing paused as soon as a Dialog window is open. With my current code, all Dialog windows are stacked on eachother.
This is the Dialog method which loads an FXML:
public void showDialog(String sURL){
final Stage myDialog = new Stage();
myDialog.initStyle(StageStyle.UTILITY);
myDialog.initModality(Modality.APPLICATION_MODAL);
URL url = getClass().getResource(sURL);
FXMLLoader fxmlloader = new FXMLLoader();
fxmlloader.setLocation(url);
fxmlloader.setBuilderFactory(new JavaFXBuilderFactory());
try {
Node n = (Node) fxmlloader.load(url.openStream());
Scene myDialogScene = new Scene(VBoxBuilder.create().children(n).alignment(Pos.CENTER).padding(new Insets(0)).build());
myDialog.setScene(myDialogScene);
myDialog.show();
} catch (Exception ex) {
System.out.println(ex);
}
}
And here is the for loop where I handle the tablerows:
@FXML
private void handle_ImportCowDataButton(ActionEvent event) {
Cows selectedCow;
for(ImportRow row: tblImport.getItems()){
selectedCow = null;
for (Cows cow : olCows) {
if (cow.getOfficial().equals(row.getCownumber())) {
selectedCow = cow;
}
}
if (selectedCow != null) {
if (row.getCalving()) {
//if cow exists and cow has calved, show dialog window loading addcalving.fxml
//then the for loop should wait until that dialog window is closed before continuing
Context.getInstance().setPassthroughObject(selectedCow);
Context.getInstance().showDialog("/GUI/calving/AddCalving.fxml");
}
} else {
//if cow does not exist, show dialog window loading addcow.fxml
//then the for loop should wait until that dialog window is closed before continuing
Context.getInstance().setPassthroughObject(selectedFarmer);
Context.getInstance().showDialog("/GUI/cow/AddCow.fxml");
}
}
}
Is working with setOnCloseRequest()
in my showDialog()
method an option?