dev.archiecortez.jfacelog.dialogs.NewPassDialog.java Source code

Java tutorial

Introduction

Here is the source code for dev.archiecortez.jfacelog.dialogs.NewPassDialog.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dev.archiecortez.jfacelog.dialogs;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextField;
import javafx.util.Pair;
import org.springframework.stereotype.Component;

/**
 *
 * @author Administrator
 */
@Component
public class NewPassDialog extends Dialog<Pair<String, String>> implements Initializable {

    @FXML
    TextField oldPassword;
    @FXML
    TextField newPassword;
    @FXML
    TextField newPasswordCopy;

    public NewPassDialog() throws IOException {
        super();
        FXMLLoader loader = new FXMLLoader(getClass().getResource("newpassdialog.fxml"));
        loader.setController(this);

        Parent root = loader.load();
        this.getDialogPane().setContent(root);
        getDialogPane().getButtonTypes().add(ButtonType.APPLY);
        getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
        getDialogPane().lookupButton(ButtonType.APPLY).disableProperty()
                .bind(newPassword.textProperty().isNotEqualTo(newPasswordCopy.textProperty())
                        .or(newPassword.textProperty().isEmpty()).or(oldPassword.textProperty().isEmpty()));

        setResultConverter(value -> {
            if (value == ButtonType.APPLY) {
                return new Pair<>(oldPassword.getText(), newPassword.getText());
            } else {
                return null;
            }
        });
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}