// Path: admin-offline/src/main/java/ch/ge/ve/offlineadmin/exception/ProcessInterruptedException.java
// public class ProcessInterruptedException extends Exception {
//     /**
//      * Constructor usually used when the interruption was caused by a user action
//      *
//      * @param message the message explaining the interruption
//      */
//     public ProcessInterruptedException(String message) {
//         super(message);
//     }
// 
//     /**
//      * Contructor used when the interruption is caused by a previous exception
//      *
//      * @param message the message explaining the interruption
//      * @param cause   the cause of the interruption
//      */
//     public ProcessInterruptedException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


import javafx.scene.layout.GridPane;
import java.util.Optional;
import java.util.ResourceBundle;
import ch.ge.ve.offlineadmin.exception.ProcessInterruptedException;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.*;
package ch.ge.ve.offlineadmin.controller;

/*-
 * #%L
 * Admin offline
 * %%
 * Copyright (C) 2015 - 2016 République et Canton de Genève
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */




/**
 * Dialog to enter password(s)
 */
public class PasswordDialogController {
    public static final int LABEL_COL = 0;
    public static final int INPUT_COL = 1;

    private static final double GRID_GAP = 10.0;
    private static final Insets GRID_INSETS = new Insets(20, 150, 10, 10);

    private final ResourceBundle resources;
    private ConsoleOutputControl consoleOutputController;

    public PasswordDialogController(ResourceBundle resources, ConsoleOutputControl consoleOutputController) {
        this.resources = resources;
        this.consoleOutputController = consoleOutputController;
    }

    private static boolean isPasswordValid(String newValue) {
        // Length should be between 9 and 10 (incl)
        boolean validLength = newValue.length() >= 9 && newValue.length() <= 10;
        // Password should contain at least one upper, one lower and one digit
        boolean validPattern = newValue.matches(".*[A-Z].*") && newValue.matches(".*[a-z].*") && newValue.matches(".*[0-9].*");
        return validLength && validPattern;
    }

    /**
     * Display the dialogs to enter the two passwords
     * <p/>
     * Whenever requested a password confirmation input-box is displayed
     *
     * @param password1        first password
     * @param password2        second password
     * @param withConfirmation indicates if password confirmation is needed
     * @throws ProcessInterruptedException
     */
// Path: admin-offline/src/main/java/ch/ge/ve/offlineadmin/exception/ProcessInterruptedException.java
// public class ProcessInterruptedException extends Exception {
//     /**
//      * Constructor usually used when the interruption was caused by a user action
//      *
//      * @param message the message explaining the interruption
//      */
//     public ProcessInterruptedException(String message) {
//         super(message);
//     }
// 
//     /**
//      * Contructor used when the interruption is caused by a previous exception
//      *
//      * @param message the message explaining the interruption
//      * @param cause   the cause of the interruption
//      */
//     public ProcessInterruptedException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


// Path: admin-offline/src/main/java/ch/ge/ve/offlineadmin/controller/PasswordDialogController.java
import javafx.scene.layout.GridPane;
import java.util.Optional;
import java.util.ResourceBundle;
import ch.ge.ve.offlineadmin.exception.ProcessInterruptedException;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.*;

package ch.ge.ve.offlineadmin.controller;

/*-
 * #%L
 * Admin offline
 * %%
 * Copyright (C) 2015 - 2016 République et Canton de Genève
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */




/**
 * Dialog to enter password(s)
 */
public class PasswordDialogController {
    public static final int LABEL_COL = 0;
    public static final int INPUT_COL = 1;

    private static final double GRID_GAP = 10.0;
    private static final Insets GRID_INSETS = new Insets(20, 150, 10, 10);

    private final ResourceBundle resources;
    private ConsoleOutputControl consoleOutputController;

    public PasswordDialogController(ResourceBundle resources, ConsoleOutputControl consoleOutputController) {
        this.resources = resources;
        this.consoleOutputController = consoleOutputController;
    }

    private static boolean isPasswordValid(String newValue) {
        // Length should be between 9 and 10 (incl)
        boolean validLength = newValue.length() >= 9 && newValue.length() <= 10;
        // Password should contain at least one upper, one lower and one digit
        boolean validPattern = newValue.matches(".*[A-Z].*") && newValue.matches(".*[a-z].*") && newValue.matches(".*[0-9].*");
        return validLength && validPattern;
    }

    /**
     * Display the dialogs to enter the two passwords
     * <p/>
     * Whenever requested a password confirmation input-box is displayed
     *
     * @param password1        first password
     * @param password2        second password
     * @param withConfirmation indicates if password confirmation is needed
     * @throws ProcessInterruptedException
     */
    public void promptForPasswords(StringProperty password1, StringProperty password2, boolean withConfirmation) throws ProcessInterruptedException {