Example usage for javafx.scene.control Dialog showAndWait

List of usage examples for javafx.scene.control Dialog showAndWait

Introduction

In this page you can find the example usage for javafx.scene.control Dialog showAndWait.

Prototype

public final Optional<R> showAndWait() 

Source Link

Document

Shows the dialog and waits for the user response (in other words, brings up a blocking dialog, with the returned value the users input).

Usage

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
protected void kFoldCrossValidation(ActionEvent event) throws IOException {
    int tmp = (int) kSlider.getValue();
    if (!CSVdata.isEmpty() && !seedItems.isEmpty()) {
        //            File f = new File(fileName.getText() + "/train-validation-test/.");
        File dir = new File(nameOfTheChosenFile + "/k-fold symmetric cross validation");
        if (dir.exists()) {
            FileUtils.deleteDirectory(dir);
        }/*from   w w  w  .  ja va  2 s  . co m*/
        dir.mkdir();

        for (int iterator = 0; iterator < seedItems.size(); iterator++) {
            long seed = Integer.parseInt(seedItems.get(iterator));
            Collections.shuffle(CSVdata, new Random(seed));

            int size = (int) Math.ceil((double) CSVdata.size() / (double) tmp);
            for (int i = 0; i < tmp; i++) {

                try (FileWriter writeFile = new FileWriter(
                        nameOfTheChosenFile + "/k-fold symmetric cross validation/" + nameOfTheChosenFile + "_"
                                + (iterator + 1) + "_" + (i + 1) + ".csv")) {
                    int limit = 0;
                    int oldLimit = 0;
                    //                        if (tmp > 2) {
                    if (i < (tmp - 1)) {
                        limit = (i + 1) * size;
                    } else {
                        limit = CSVdata.size();
                    }
                    //                        } else if (tmp == 2) { // division 70train :  30test
                    //                            if (i == 0) {
                    //                                limit = (int) Math.ceil((double) 0.7 * CSVdata.size());
                    //                            } else {
                    //                                oldLimit = (int) Math.ceil((double) 0.7 * CSVdata.size());;
                    //                                limit = CSVdata.size();
                    //                            }
                    //                        }

                    writeFile.append(label[0] + "\n");
                    writeFile.append(label[1] + "\n");
                    //                        if (tmp > 2) {
                    for (int j = i * size; j < limit; j++) {
                        writeFile.append(CSVdata.get(j) + "\n");
                    }
                    //                        } else if (tmp == 2) { // division 70train :  30test
                    //                            for (int j = oldLimit; j < limit; j++) {
                    //                                writeFile.append(CSVdata.get(j) + "\n");
                    //                            }
                    //                        }
                    writeFile.close();
                }
            }
        }
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Division successful");
        dialog.showAndWait();
    }
    if (CSVdata.isEmpty()) {
        fileName.setTextFill(Color.RED);
        fileName.setText("Data file is empty");
    }
    if (seedItems.isEmpty()) {
        seedName.setTextFill(Color.RED);
        seedName.setText("Seed file is empty");
    }

}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
protected void divideTVT(ActionEvent event) throws IOException {
    if (!CSVdata.isEmpty() && !seedItems.isEmpty()) {
        File dir1 = new File(nameOfTheChosenFile + "/train-validation-test1");
        File dir2 = new File(nameOfTheChosenFile + "/train-validation-test2");
        if (dir1.exists()) {
            FileUtils.deleteDirectory(dir1);
        }//from  w  w w .  j a v  a  2s .co  m
        dir1.mkdir();

        if (dir2.exists()) {
            FileUtils.deleteDirectory(dir2);
        }
        dir2.mkdir();

        for (int iterator = 0; iterator < seedItems.size(); iterator++) {
            long seed = Integer.parseInt(seedItems.get(iterator));
            Collections.shuffle(CSVdata, new Random(seed));

            try (FileWriter writeTrain = new FileWriter(nameOfTheChosenFile + "/train-validation-test1/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "train.csv")) {
                writeTrain.append(label[0] + "\n");
                writeTrain.append(label[1] + "\n");
                for (int i = 0; i < Math.floor((CSVdata.size() * 3) / 10); i++) {
                    writeTrain.append(CSVdata.get(i) + "\n");
                }
                writeTrain.close();
            }

            try (FileWriter writeValidation = new FileWriter(nameOfTheChosenFile + "/train-validation-test1/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "validation.csv")) {
                writeValidation.append(label[0] + "\n");
                writeValidation.append(label[1] + "\n");
                for (int i = (int) Math.floor((CSVdata.size() * 3) / 10); i < Math
                        .floor(CSVdata.size() / 2); i++) {
                    writeValidation.append(CSVdata.get(i) + "\n");
                }
                writeValidation.close();
            }

            try (FileWriter writeTest = new FileWriter(nameOfTheChosenFile + "/train-validation-test1/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "test.csv")) {
                writeTest.append(label[0] + "\n");
                writeTest.append(label[1] + "\n");
                for (int i = (int) Math.floor(CSVdata.size() / 2); i < CSVdata.size(); i++) {
                    writeTest.append(CSVdata.get(i) + "\n");
                }
                writeTest.close();

            }

            //Second division
            try (FileWriter writeTrain = new FileWriter(nameOfTheChosenFile + "/train-validation-test2/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "test.csv")) {
                writeTrain.append(label[0] + "\n");
                writeTrain.append(label[1] + "\n");
                for (int i = 0; i < Math.floor((CSVdata.size()) / 2); i++) {
                    writeTrain.append(CSVdata.get(i) + "\n");
                }
                writeTrain.close();
            }

            try (FileWriter writeValidation = new FileWriter(nameOfTheChosenFile + "/train-validation-test2/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "train.csv")) {
                writeValidation.append(label[0] + "\n");
                writeValidation.append(label[1] + "\n");
                for (int i = (int) Math.floor((CSVdata.size()) / 2); i < Math
                        .floor((CSVdata.size() * 8) / 10); i++) {
                    writeValidation.append(CSVdata.get(i) + "\n");
                }
                writeValidation.close();
            }

            try (FileWriter writeTest = new FileWriter(nameOfTheChosenFile + "/train-validation-test2/"
                    + nameOfTheChosenFile + "_" + (iterator + 1) + "validation.csv")) {
                writeTest.append(label[0] + "\n");
                writeTest.append(label[1] + "\n");
                for (int i = (int) Math.floor((CSVdata.size() * 8) / 10); i < CSVdata.size(); i++) {
                    writeTest.append(CSVdata.get(i) + "\n");
                }
                writeTest.close();

            }
        }
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Division successful");
        dialog.showAndWait();

    }
    if (CSVdata.isEmpty()) {
        fileName.setTextFill(Color.RED);
        fileName.setText("Data file is empty");
    }
    if (seedItems.isEmpty()) {
        seedName.setTextFill(Color.RED);
        seedName.setText("Seed file is empty");
    }

}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void pruneExtendedly() throws IOException {
    extendedPruningFlag = true;/*from   w  ww  . j  a va 2 s.c o m*/
    resultFileWriter.clear();
    averagedResult.clear();

    FolderHandler.SplitFiles(isExtendedPruningTTVSelected);
    //        FolderHandler.RemoveUnwantedFiles(isExtendedPruningTTVSelected);

    File ruleDirectory = new File("rules/.");
    File[] ruleFiles = ruleDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    if (ruleFiles.length < 1) {
        ButtonType emptyInput = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(emptyInput);
        dialog.setContentText("Folder \"rules\" is empty");
        dialog.showAndWait();
    }

    File trainDirectory = new File("train/.");
    File[] trainFiles = trainDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    File validationDirectory = new File("validation/.");
    File[] validationFiles = validationDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    File testDirectory = new File("test/.");
    File[] testFiles = testDirectory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".csv");
        }
    });

    resultFileWriter.add(
            "rawData,,,,,,,prunedData,,,,,,,prunedDataWithAlpha,,,,,,,,testError,,additionalParameters" + "\n");
    resultFileWriter.add(
            "length,,,coverage,,,noOfRules,length,,,coverage,,,noOfRules,alpha,length,,,coverage,,,noOfRules,prunedRules,prunedRulesWithAlpha,no of misclassifications,support"
                    + "\n");
    resultFileWriter.add(
            "min,avg,max,min,avg,max,result,min,avg,max,min,avg,max,result,alpha,min,avg,max,min,avg,max,result,result,result,result,min,avg,max\n");
    if (ruleFiles.length > 0 && trainFiles.length > 0) {
        for (int i = 0; i < ruleFiles.length; i++) {

            if (ruleFiles[i].getName().contains(".csv") && trainFiles[i].getName().contains(".csv")
                    && ruleFiles[i].getName().contains(".csv")) {
                DataHandler dataHandler1 = new DataHandler("rules/" + ruleFiles[i].getName());
                dataHandler1.splitRules();
                rules.clear();
                decisions.clear();
                rules = dataHandler1.rules;
                decisions = dataHandler1.decisions;
                clickCounter = 0;

                DataHandler dataHandler2 = new DataHandler("train/" + trainFiles[i].getName());
                dataHandler2.splitTraining();
                decisionTable.clear();
                decisionTable = dataHandler2.decisionTable;
                clickCounter = 0;

                if (isExtendedPruningTTVSelected) {
                    clickCounterTestValidation = 0;
                    DataHandler dataHandlerValidation1 = new DataHandler(
                            "validation/" + validationFiles[i].getName());
                    dataHandlerValidation1.splitTraining();
                    validationTable.clear();
                    validationTable = dataHandlerValidation1.decisionTable;
                }

                clickCounterTestValidation = 0;
                DataHandler dataHandlerTest2 = new DataHandler("test/" + testFiles[i].getName());
                dataHandlerTest2.splitTraining();
                testTable.clear();
                testTable = dataHandlerTest2.decisionTable;

                pruneRules();

            }

        }
        File tmpFile = new File("results.csv");
        if (tmpFile.exists()) {
            tmpFile.delete();
        }

        DecimalFormat df = new DecimalFormat("0.00000");
        String resultFileName = "resultsAverage="
                + df.format(DataHandler.calculateAverage(averagedResult)).replace(",", ".") + "std="
                + df.format(DataHandler.calculateSTD(averagedResult)).replace(",", ".") + ".csv";

        try (FileWriter writeFile = new FileWriter(resultFileName, true)) {
            for (int i = 0; i < resultFileWriter.size(); i++) {
                writeFile.append(resultFileWriter.get(i));
            }
        }
        if (!isRemoverContext) {
            ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
            Dialog<String> dialog = new Dialog<>();
            dialog.getDialogPane().getButtonTypes().add(buttonOK);
            dialog.setContentText("Extended pruning successful!");
            dialog.showAndWait();
        }
    } else if (!isRemoverContext) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Extended pruning failed, please check input and rule files!");
        dialog.showAndWait();
    }

    extendedPruningFlag = false;
}

From source file:ruleprunermt2.FXMLDocumentController.java

@FXML
private void pruneRules() throws IOException {
    clickCounter++;// w  ww  . j ava2  s  .  com
    int decisionNumbers = Pruner.BinomialCalculation(decisionTable);

    if (!decisionTable.isEmpty() && (!validationTable.isEmpty() || !isExtendedPruningTTVSelected)
            && !rules.isEmpty() && !decisions.isEmpty() && clickCounter < 2) {
        rulesInATable.clear();
        //deleting all old rule files
        File f = new File(".");
        File[] files = f.listFiles();
        for (File file : files) {
            if (file.getName().contains(".csv")) {
                file.delete();
            }
        }

        for (int i = 0; i < rules.size(); i++) {
            String[] inputString = new String[decisionTable.get(0).length];
            for (int ii = 0; ii < inputString.length; ii++) {
                inputString[ii] = null;
            }
            for (int j = 0; j < rules.get(i).size(); j++) {

                String[] tmp = rules.get(i).get(j).split(" = ");
                //System.out.println(tmp);
                for (int tmpIterator = 0; tmpIterator < decisionTable.get(0).length; tmpIterator++) {
                    if (tmp[0].equals(decisionTable.get(0)[tmpIterator])) {
                        inputString[tmpIterator] = tmp[1];
                    }
                }
            }
            inputString[decisionTable.get(0).length - 1] = decisions.get(i);
            rulesInATable.add(inputString);
        }

        tableData.clear();

        String[] resultLength = Pruner.displayStatistics(tableData, rulesInATable, decisionTable, "Raw data");
        String[] resultCoverage = Pruner.calculateCoverage(tableData, rulesInATable, decisionTable, "");
        tableData.add(new Statistics("", "no of rules", Integer.toString(rulesInATable.size()),
                Integer.toString(rulesInATable.size()), Integer.toString(rulesInATable.size())));

        resultFileWriter.add(resultLength[0] + "," + resultLength[1] + "," + resultLength[2] + ","
                + resultCoverage[0] + "," + resultCoverage[1] + "," + resultCoverage[2] + ","
                + Integer.toString(rulesInATable.size()) + ",");

        //Remove duplicated rules
        Pruner.RemoveDuplicates(rulesInATable);

        Pruner.displayStatistics(tableData, rulesInATable, decisionTable, "Duplicates removed");
        Pruner.calculateCoverage(tableData, rulesInATable, decisionTable, "");
        tableData.add(new Statistics("", "no of rules", Integer.toString(rulesInATable.size()),
                Integer.toString(rulesInATable.size()), Integer.toString(rulesInATable.size())));

        //Cutting rules by simplification algorithm
        Pruner.CutRules(decisionTable, rulesInATable, decisions, isPSelected);

        //Remove duplicated rules
        Pruner.RemoveDuplicates(rulesInATable);

        resultLength = Pruner.displayStatistics(tableData, rulesInATable, decisionTable, "Rules cut");
        resultCoverage = Pruner.calculateCoverage(tableData, rulesInATable, decisionTable, "");
        tableData.add(new Statistics("", "no of rules", Integer.toString(rulesInATable.size()),
                Integer.toString(rulesInATable.size()), Integer.toString(rulesInATable.size())));

        resultFileWriter.add(resultLength[0] + "," + resultLength[1] + "," + resultLength[2] + ","
                + resultCoverage[0] + "," + resultCoverage[1] + "," + resultCoverage[2] + ","
                + Integer.toString(rulesInATable.size()) + ",");

        ArrayList<String[]> solution = Pruner.Prune(decisionTable, rulesInATable, decisions, decisionNumbers,
                isPSelected);

        DisplayResults.DisplayCorrect(rulesInATable, decisionTable, "PrunedRules.csv");

        String[] resultSupport = Pruner.calculateSupport(tableData, rulesInATable, decisionTable, "");

        if (!extendedPruningFlag) {
            if (isExtendedPruningTTVSelected) {
                DisplayResults.DisplayInaccurate(rulesInATable, solution, decisionTable, validationTable,
                        tableData);
            }
        } else {
            //TODO
            DecimalFormat df = new DecimalFormat("0.00000");
            Double error = Pruner.CalculateError(testTable, rulesInATable)[0];
            int misclassification = (int) Pruner.CalculateError(testTable, rulesInATable)[1];
            String tmpError1 = df.format(error);
            tmpError1 = tmpError1.replace(",", ".");
            String tmpError2 = " ";
            if (isExtendedPruningTTVSelected) {
                String[] inaccurateResult = DisplayResults.DisplayInaccurate(rulesInATable, solution,
                        decisionTable, testTable, tableData);
                if (!inaccurateResult[0].equals("")) {
                    resultFileWriter.add(inaccurateResult[0]);
                } else {
                    resultFileWriter.add(",,,,,,,");
                }
                if (inaccurateResult[1] == null) {
                    inaccurateResult[1] = tmpError1;
                }
                if (inaccurateResult[2] != null) {
                    resultFileWriter.add("," + tmpError1 + "," + inaccurateResult[1] + "," + inaccurateResult[2]
                            + "," + inaccurateResult[3] + "\n");
                } else {
                    resultFileWriter.add("," + tmpError1 + "," + inaccurateResult[1] + "," + misclassification
                            + "," + resultSupport[0] + "," + resultSupport[1] + "," + resultSupport[2] + "\n");
                }

                //protection in case of problem with number format
                try {
                    averagedResult.add(Double.parseDouble(inaccurateResult[1]));
                } catch (NumberFormatException ex) {
                    averagedResult.add(Double.parseDouble("1.0"));
                }
            } else {
                resultFileWriter.add("," + tmpError1 + "," + tmpError1 + "," + misclassification + ","
                        + resultSupport[0] + "," + resultSupport[1] + "," + resultSupport[2] + "\n");
                try {
                    averagedResult.add(Double.parseDouble(tmpError1));
                } catch (NumberFormatException ex) {
                    averagedResult.add(Double.parseDouble("1.0"));
                }
            }
        }

        if (!solution.isEmpty() && !extendedPruningFlag) {
            ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
            Dialog<String> dialog = new Dialog<>();
            dialog.getDialogPane().getButtonTypes().add(buttonOK);
            dialog.setContentText("Pruning successful!");
            dialog.showAndWait();
        } else if (resultFileWriter.isEmpty()) {
            ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
            Dialog<String> dialog = new Dialog<>();
            dialog.getDialogPane().getButtonTypes().add(buttonOK);
            dialog.setContentText("Basic pruning successful. Extended pruning failed!");
            dialog.showAndWait();
        }
    } else if (clickCounter < 2 && !extendedPruningFlag) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Error while pruning! Please check your files");
        dialog.showAndWait();
        clickCounter--;
    } else if (!extendedPruningFlag) {
        ButtonType buttonOK = new ButtonType("OK", ButtonData.OK_DONE);
        Dialog<String> dialog = new Dialog<>();
        dialog.getDialogPane().getButtonTypes().add(buttonOK);
        dialog.setContentText("Too many clicks");
        dialog.showAndWait();
    }
}

From source file:cz.lbenda.rcp.DialogHelper.java

/** Show unsaved object if aren't saved. if user want cancel the closing then return false, elserwhere return true
 * @param savableRegistry register which hold unsaved data
 * @return true if window/object can be closed */
public boolean showUnsavedObjectDialog(SavableRegistry savableRegistry) {
    Set<Savable> savables = savableRegistry.dirtySavables();
    if (savables.size() == 0) {
        return true;
    }/*from   w w  w.j  a  va2 s. c  o m*/
    Dialog<?> dialog = new Dialog<>();
    dialog.setResizable(false);
    dialog.setTitle(msgNotSavedObjectsTitle);
    dialog.setHeaderText(msgNotSavedObjectsHeader);

    BorderPane pane = new BorderPane();
    pane.setPrefHeight(400);
    pane.setPrefWidth(300);
    ListView<DialogHelper.Item> listView = new ListView<>();
    listView.getItems()
            .addAll(savables.stream().map(savable -> new Item(savable, true)).collect(Collectors.toList()));
    listView.setCellFactory(CheckBoxListCell.forListView(DialogHelper.Item::onProperty));
    pane.setCenter(listView);

    dialog.getDialogPane().setContent(pane);

    ButtonType btCancel = new ButtonType(button_cancel, ButtonBar.ButtonData.CANCEL_CLOSE);
    ButtonType btSaveClose = new ButtonType(button_saveAndClose, ButtonBar.ButtonData.OK_DONE);
    ButtonType btClose = new ButtonType(button_closeWithoutSave);

    dialog.getDialogPane().getButtonTypes().addAll(btClose, btSaveClose, btCancel);

    Optional<?> result = dialog.showAndWait();
    if (result.isPresent()) {
        if (btCancel == result.get()) {
            return false;
        }
        if (btSaveClose == result.get()) {
            listView.getItems().stream().filter(Item::isOn).forEach(item -> item.getSavable().save());
        }
    } else {
        return false;
    }
    return true;
}

From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java

private Optional<String> askUserForTextField(String text) {
    TextField textfield = new TextField();

    Dialog<ButtonType> dialog = new Dialog<>();
    dialog.getDialogPane().headerTextProperty().set(text);
    dialog.getDialogPane().contentProperty().set(textfield);
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
    Optional<ButtonType> result = dialog.showAndWait();

    if (result.isPresent() && result.get().equals(ButtonType.OK))
        return Optional.of(textfield.getText());
    else//from w w w  .j a  va2  s.c o m
        return Optional.empty();
}

From source file:com.ggvaidya.scinames.dataset.BinomialChangesSceneController.java

private Optional<String> askUserForTextArea(String label, String initialText) {
    TextArea textarea = new TextArea();
    if (initialText != null)
        textarea.setText(initialText);/*w  w  w .  ja v a2 s . c  o m*/

    Dialog<ButtonType> dialog = new Dialog<>();
    dialog.getDialogPane().headerTextProperty().set(label);
    dialog.getDialogPane().contentProperty().set(textarea);
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
    Optional<ButtonType> result = dialog.showAndWait();

    if (result.isPresent() && result.get().equals(ButtonType.OK))
        return Optional.of(textarea.getText());
    else
        return Optional.empty();
}

From source file:com.cdd.bao.editor.EditSchema.java

public void actionFileAssayStats() {
    List<String> stats = new ArrayList<>();
    SchemaUtil.gatherAssayStats(stack.peekSchema(), stats);
    String text = String.join("\n", stats);
    Dialog<Boolean> showdlg = new Dialog<>();
    showdlg.setTitle("Assay Stats");

    TextArea area = new TextArea(text);
    area.setWrapText(true);//from   w ww .ja v  a 2s.  com
    area.setPrefWidth(700);
    area.setPrefHeight(500);
    showdlg.getDialogPane().setContent(area);

    showdlg.getDialogPane().getButtonTypes().addAll(new ButtonType("OK", ButtonBar.ButtonData.OK_DONE));
    showdlg.setResultConverter(buttonType -> true);
    showdlg.showAndWait();
}

From source file:com.cdd.bao.editor.EditSchema.java

public void actionFileMerge() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Merge Schema");
    if (schemaFile != null)
        chooser.setInitialDirectory(schemaFile.getParentFile());

    File file = chooser.showOpenDialog(stage);
    if (file == null)
        return;/*w  w w  . j av  a2s .  c om*/

    Schema addSchema = null;
    try {
        addSchema = ModelSchema.deserialise(file);
    } catch (IOException ex) {
        ex.printStackTrace();
        Util.informWarning("Merge", "Failed to parse file: is it a valid schema?");
        return;
    }

    List<String> log = new ArrayList<>();
    Schema merged = SchemaUtil.mergeSchema(stack.getSchema(), addSchema, log);
    if (log.size() == 0) {
        Util.informMessage("Merge", "The merge file is the same: no action.");
        return;
    }

    String text = String.join("\n", log);
    Dialog<Boolean> confirm = new Dialog<>();
    confirm.setTitle("Confirm Merge Modifications");

    TextArea area = new TextArea(text);
    area.setWrapText(true);
    area.setPrefWidth(700);
    area.setPrefHeight(500);
    confirm.getDialogPane().setContent(area);

    ButtonType btnApply = new ButtonType("Apply", ButtonBar.ButtonData.OK_DONE);
    confirm.getDialogPane().getButtonTypes().addAll(new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE),
            btnApply);
    confirm.setResultConverter(buttonType -> {
        if (buttonType == btnApply)
            return true;
        return null;
    });

    Optional<Boolean> result = confirm.showAndWait();
    if (!result.isPresent() || result.get() != true)
        return;

    stack.changeSchema(merged, true);
    rebuildTree();
}

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

@FXML
public void saveAsProfile() {

    Dialog<String> dialog = new TextInputDialog();
    dialog.setTitle("Profile name");
    dialog.setHeaderText("Enter profile name");
    Optional<String> result = dialog.showAndWait();

    if (result.isPresent()) {

        ////  www.j  av a2s  .com
        // Check for uniqueness; prompt for overwrite
        //
        final String profileName = result.get();
        if (profileNameInUse(profileName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("[SAVE AS] profile name in use; prompt for overwrite");
            }
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION,
                    "Overwrite existing profile '" + profileName + "'?");
            alert.setHeaderText("Profile name in use");
            Optional<ButtonType> response = alert.showAndWait();
            if (!response.isPresent() || response.get() != ButtonType.OK) {
                if (logger.isDebugEnabled()) {
                    logger.debug("[SAVE AS] overwrite canceled");
                }
                return;
            }
        }

        if (configurationDS.profileExists(profileName)) {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Overwrite existing profile?");
            alert.setHeaderText("Profile exists");
            Optional<ButtonType> response = alert.showAndWait();
            if (!response.isPresent() || response.get() != ButtonType.OK) {
                return;
            }
        }

        activeConfiguration.activeProfileProperty().set(profileName); // activeProfile object tweaked w. new name

        try {
            recordRecentProfile(activeProfile.getProfileName()); // #18
            configurationDS.saveProfile();

            Stage s = (Stage) sp.getScene().getWindow();
            s.setTitle("ResignatorApp - " + profileName);

            needsSave.set(false);

            addToProfileBrowser(profileName);

        } catch (IOException exc) {
            logger.error("error saving profile '" + profileName + "'", exc);

            Alert alert = new Alert(Alert.AlertType.ERROR, exc.getMessage());
            alert.setHeaderText("Can't save profile");
            alert.showAndWait();
        }

    } else {
        String msg = "A profile name is required";
        Alert alert = new Alert(Alert.AlertType.ERROR, msg);
        alert.setHeaderText("Can't save profile");
        alert.showAndWait();
    }
}