--- /dev/null
+package com.axyus.generator.pespj;
+
+import com.axyus.generator.pespj.utilities.Version;
+import com.axyus.swing.components.UnexpectedErrorDlg;
+import com.axyus.swing.components.UnexpectedErrorDlg.CloseWindowRequestHandler;
+import com.axyus.swing.components.wizard.WizardDialog;
+import com.axyus.swing.components.wizard.WizardProcess;
+import java.awt.Toolkit;
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.net.URL;
+import javax.swing.ImageIcon;
+import javax.swing.JFrame;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author CBO
+ */
+public class WizardLauncher {
+
+ public static final String TITLE = "Générateur de PES PJ";
+ private static Log logger = LogFactory.getLog(WizardLauncher.class);
+
+ public static void startUI(final RunContextAdapter runContextAdapter) {
+ java.awt.EventQueue.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+ WizardProcess wizardProcess = new GeneratorPesPjWizardProcess(runContextAdapter);
+ WizardDialog dialog = new WizardDialog(wizardProcess, runContextAdapter.getParentFrame(), true);
+ wizardProcess.setWizardDialog(dialog);
+ wizardProcess.getCurrentStep().beforeDisplay();
+ dialog.setTitle(new StringBuilder(TITLE).append(" - ").append(Version.getCurrent().toString()).toString());
+ dialog.setLogo(new ImageIcon(this.getClass().getResource("/com/axyus/generator/pespj/logo.png")).getImage());
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ dialog.setLocation((toolkit.getScreenSize().width - dialog.getWidth()) / 2, (toolkit.getScreenSize().height - dialog.getHeight()) / 2);
+ dialog.addWindowListener(new java.awt.event.WindowAdapter() {
+
+ @Override
+ public void windowClosing(java.awt.event.WindowEvent e) {
+ runContextAdapter.onCloseRequest();
+ }
+ });
+ dialog.setVisible(true);
+ }
+ });
+ }
+
+ public static interface RunContextAdapter {
+ boolean isPesFileImportSupported();
+ boolean isInXemelios();
+ URL getPesSchemaURL();
+
+ JFrame getParentFrame();
+ void onCloseRequest();
+ }
+
+ static public class CustomUncaughtExceptionHandler implements UncaughtExceptionHandler {
+
+ static RunContextAdapter runContextAdapter;
+
+ @Override
+ public void uncaughtException(Thread thread, Throwable throwable) {
+ handle(throwable);
+ }
+
+ public void handle(Throwable throwable) {
+ logger.error("Erreur inattendue", throwable);
+ UnexpectedErrorDlg errorDlg = new UnexpectedErrorDlg(null, true, throwable, new CloseWindowRequestHandler() {
+
+ @Override
+ public void onCloseWindowRequest(UnexpectedErrorDlg unexpectedErrorDlg) {
+ if (runContextAdapter != null) {
+ runContextAdapter.onCloseRequest();
+ }
+ }
+ });
+ errorDlg.setVisible(true);
+ }
+ };
+}