Example usage for javafx.scene.control ButtonType getButtonData

List of usage examples for javafx.scene.control ButtonType getButtonData

Introduction

In this page you can find the example usage for javafx.scene.control ButtonType getButtonData.

Prototype

public final ButtonData getButtonData() 

Source Link

Document

Returns the ButtonData specified for this ButtonType in the constructor.

Usage

From source file:com.properned.application.SystemController.java

public void loadFileList(File selectedFile) {
    Platform.runLater(new Runnable() {

        @Override//from www.  ja va 2s .  c  om
        public void run() {
            logger.info("Load the file list associated to '" + selectedFile.getAbsolutePath() + "'");

            if (MultiLanguageProperties.getInstance().getIsDirty()) {
                ButtonType result = askForSave();
                if (result.getButtonData() == ButtonData.CANCEL_CLOSE) {
                    // The file must not be loaded
                    return;
                }
            }
            Preferences.getInstance().setLastPathUsed(selectedFile.getAbsolutePath());
            String fileName = selectedFile.getName();
            String baseNameTemp = fileName.substring(0, fileName.lastIndexOf("."));

            if (fileName.contains("_")) {
                baseNameTemp = fileName.substring(0, fileName.indexOf("_"));
            }
            final String baseName = baseNameTemp;

            List<PropertiesFile> fileList = Arrays
                    .asList(selectedFile.getParentFile().listFiles(new FileFilter() {
                        @Override
                        public boolean accept(File pathname) {
                            return pathname.isFile() && pathname.getName().startsWith(baseName)
                                    && pathname.getName().endsWith(".properties");
                        }
                    })).stream().map(new Function<File, PropertiesFile>() {
                        @Override
                        public PropertiesFile apply(File t) {
                            String language = "";
                            if (t.getName().contains("_")) {
                                language = t.getName().substring(t.getName().indexOf("_") + 1,
                                        t.getName().lastIndexOf("."));
                            }
                            return new PropertiesFile(t.getAbsolutePath(), baseName, new Locale(language));
                        }
                    }).collect(Collectors.<PropertiesFile>toList());

            try {
                multiLanguageProperties.loadFileList(baseName, fileList);
                Preferences.getInstance().addFileToRecentFileList(selectedFile.getAbsolutePath());
                Properned.getInstance().getPrimaryStage().getScene()
                        .setOnKeyReleased(new EventHandler<KeyEvent>() {
                            @Override
                            public void handle(KeyEvent event) {
                                if (event.getCode() == KeyCode.S && event.isControlDown()) {
                                    logger.info("CTRL-S detected");
                                    save();
                                    event.consume();
                                }
                            }
                        });
            } catch (IOException e) {
                Properned.getInstance().showError(MessageReader.getInstance().getMessage("error.load"), e);
            }
        }
    });
}