/**
 * Copyright Notice
 *
 * This is a work of the U.S. Government and is not subject to copyright
 * protection in the United States. Foreign copyrights may apply.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package gov.va.isaac.gui.dialog;

import gov.va.isaac.interfaces.utility.DialogResponse;
import java.io.IOException;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;

/**
 * {@link YesNoDialog}
 *
 * @author <a href="mailto:daniel.armbrust.list@gmail.com">Dan Armbrust</a>
 */
public class YesNoDialog
{
	private YesNoDialogController yndc_;
	private Stage yesNoStage_;

	public YesNoDialog(Window owner) throws IOException
	{
		yesNoStage_ = new Stage();
		yesNoStage_.initModality(Modality.WINDOW_MODAL);
		yesNoStage_.initOwner(owner);
		yesNoStage_.initStyle(StageStyle.UTILITY);
		FXMLLoader loader = new FXMLLoader();
		loader.setLocation(YesNoDialogController.class.getResource("YesNoDialog.fxml"));
		Scene scene = new Scene((Parent) loader.load(YesNoDialogController.class.getResourceAsStream("YesNoDialog.fxml")));
		yndc_ = loader.getController();
		yesNoStage_.setScene(scene);
		
		//Problem on linux, where modal windows don't always stay on top...
		yesNoStage_.iconifiedProperty().addListener(new ChangeListener<Boolean>()
		{
			@Override
			public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue)
			{
				Platform.runLater(() -> {
					yesNoStage_.toFront();
				});
			}
		});
	}

	public DialogResponse showYesNoDialog(String title, String question)
	{
		yndc_.init(question);
		yesNoStage_.setTitle(title);
		yesNoStage_.showAndWait();
		return yndc_.getAnswer();
	}
}

@@ -752,16 +752,48 @@
 ialog;%0A%0A
+import gov.va.isaac.AppContext;%0A
 import g
@@ -843,36 +843,8 @@
 se;%0A
-import java.io.IOException;%0A
 impo
@@ -1162,16 +1162,48 @@
 .Window;
+%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A *
@@ -1437,31 +1437,23 @@
 ner)
- throws IOException%0A
+%0A%09%7B%0A%09%09try%0A%09
 %09%7B%0A
+%09
 %09%09ye
@@ -1473,24 +1473,25 @@
 ew Stage();%0A
+%09
 %09%09yesNoStage
@@ -1529,16 +1529,17 @@
 MODAL);%0A
+%09
 %09%09yesNoS
@@ -1560,24 +1560,25 @@
 r(owner);%0A%09%09
+%09
 yesNoStage_.
@@ -1610,16 +1610,17 @@
 ITY);%0A%09%09
+%09
 FXMLLoad
@@ -1649,16 +1649,17 @@
 ader();%0A
+%09
 %09%09loader
@@ -1735,16 +1735,17 @@
 l%22));%0A%09%09
+%09
 Scene sc
@@ -1854,16 +1854,17 @@
 %22)));%0A%09%09
+%09
 yndc_ = 
@@ -1885,24 +1885,25 @@
 roller();%0A%09%09
+%09
 yesNoStage_.
@@ -1921,19 +1921,21 @@
 ene);%0A%09%09
+%09
 %0A%09%09
+%09
 //Proble
@@ -1994,16 +1994,17 @@
  top...%0A
+%09
 %09%09yesNoS
@@ -2073,18 +2073,20 @@
 an%3E()%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09@Over
@@ -2093,16 +2093,17 @@
 ride%0A%09%09%09
+%09
 public v
@@ -2196,26 +2196,28 @@
 ewValue)%0A%09%09%09
+%09
 %7B%0A
+%09
 %09%09%09%09Platform
@@ -2239,16 +2239,17 @@
  %7B%0A%09%09%09%09%09
+%09
 yesNoSta
@@ -2263,16 +2263,17 @@
 ront();%0A
+%09
 %09%09%09%09%7D);%0A
@@ -2279,16 +2279,217 @@
 %0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%7D);%0A
+%09%09%7D%0A%09%09catch (Exception e)%0A%09%09%7B%0A%09%09%09LoggerFactory.getLogger(this.getClass()).error(%22Unexpected%22, e);%0A%09%09%09AppContext.getCommonDialogs().showErrorDialog(%22Unexpected error showing Yes / No Dialog%22, e);%0A%09%09%7D%0A
 %09%7D%0A%0A

fix this API to not throw exceptions