Example usage for javafx.scene.layout FlowPane getChildren

List of usage examples for javafx.scene.layout FlowPane getChildren

Introduction

In this page you can find the example usage for javafx.scene.layout FlowPane getChildren.

Prototype

@Override
public ObservableList<Node> getChildren() 

Source Link

Usage

From source file:com.bekwam.resignator.ResignatorAppMainViewController.java

private boolean validateSign() {

    if (logger.isDebugEnabled()) {
        logger.debug("[VALIDATE]");
    }//  ww  w  .  j av a2  s  .  c om

    boolean isValid = true;

    //
    // Validate the Source JAR field
    //

    if (StringUtils.isBlank(activeProfile.getSourceFileFileName())) {

        if (!tfSourceFile.getStyleClass().contains("tf-validation-error")) {
            tfSourceFile.getStyleClass().add("tf-validation-error");
        }
        isValid = false;

    } else {

        if (!new File(activeProfile.getSourceFileFileName()).exists()) {

            if (!tfSourceFile.getStyleClass().contains("tf-validation-error")) {
                tfSourceFile.getStyleClass().add("tf-validation-error");
            }

            Alert alert = new Alert(Alert.AlertType.ERROR,
                    "Specified Source " + activeProfile.getArgsType() + " does not exist");

            alert.showAndWait();

            isValid = false;
        }
    }

    //
    // Validate the TargetJAR field
    //

    if (StringUtils.isBlank(activeProfile.getTargetFileFileName())) {
        if (!tfTargetFile.getStyleClass().contains("tf-validation-error")) {
            tfTargetFile.getStyleClass().add("tf-validation-error");
        }
        isValid = false;
    }

    if (activeProfile.getArgsType() == SigningArgumentsType.FOLDER) {

        if (StringUtils.equalsIgnoreCase(activeProfile.getSourceFileFileName(),
                activeProfile.getTargetFileFileName())) {

            if (!tfTargetFile.getStyleClass().contains("tf-validation-error")) {
                tfTargetFile.getStyleClass().add("tf-validation-error");
            }

            Alert alert = new Alert(Alert.AlertType.ERROR,
                    "Source folder and target folder cannot be the same");
            alert.showAndWait();

            isValid = false;
        }
    }

    //
    // #13 Validate the Jarsigner Config form
    //

    String jarsignerConfigField = "";
    String jarsignerConfigMessage = "";
    if (isValid && StringUtils.isBlank(activeProfile.getJarsignerConfigKeystore())) {
        jarsignerConfigField = "Keystore";
        jarsignerConfigMessage = "A keystore must be specified";
    } else if (isValid && StringUtils.isBlank(activeProfile.getJarsignerConfigStorepass())) {
        jarsignerConfigField = "Storepass";
        jarsignerConfigMessage = "A password for the keystore must be specified";
    } else if (isValid && StringUtils.isBlank(activeProfile.getJarsignerConfigAlias())) {
        jarsignerConfigField = "Alias";
        jarsignerConfigMessage = "An alias for the key must be specified";
    } else if (isValid && StringUtils.isBlank(activeProfile.getJarsignerConfigKeypass())) {
        jarsignerConfigField = "Keypass";
        jarsignerConfigMessage = "A password for the key must be specified";
    }

    if (StringUtils.isNotEmpty(jarsignerConfigMessage)) {

        if (logger.isDebugEnabled()) {
            logger.debug("[VALIDATE] jarsigner config not valid {}", jarsignerConfigMessage);
        }

        Alert alert = new Alert(Alert.AlertType.ERROR, "Set " + jarsignerConfigField + " in Configure");
        alert.setHeaderText(jarsignerConfigMessage);

        FlowPane fp = new FlowPane();
        Label lbl = new Label("Set " + jarsignerConfigField + " in ");
        Hyperlink link = new Hyperlink("Configure");
        fp.getChildren().addAll(lbl, link);

        link.setOnAction((evt) -> {
            alert.close();
            openJarsignerConfig();
        });

        alert.getDialogPane().contentProperty().set(fp);
        alert.showAndWait();

        isValid = false;
    }

    //
    // #38 check keystore prior to running
    //
    KeytoolCommand keytoolCommand = keytoolCommandProvider.get();

    Task<Boolean> keytoolTask = new Task<Boolean>() {
        @Override
        protected Boolean call() throws Exception {

            final List<String> aliases = keytoolCommand.findAliases(
                    activeConfiguration.getKeytoolCommand().toString(),
                    activeProfile.getJarsignerConfigKeystore(), activeProfile.getJarsignerConfigStorepass());
            if (logger.isDebugEnabled()) {
                logger.debug("[KEYTOOL] # aliases=" + CollectionUtils.size(aliases));
            }

            return true;
        }
    };
    new Thread(keytoolTask).start();

    try {
        if (!keytoolTask.get()) {
            if (logger.isDebugEnabled()) {
                logger.debug("[KEYTOOL] keystore or configuration not valid");
            }
            isValid = false;
        }
    } catch (InterruptedException | ExecutionException e) {

        isValid = false;
        logger.error("error accessing keystore", e);
        Alert alert = new Alert(Alert.AlertType.ERROR, e.getMessage() // contains formatted string
        );
        alert.showAndWait();
    }

    return isValid;
}