Example usage for javafx.scene.control DialogPane getButtonTypes

List of usage examples for javafx.scene.control DialogPane getButtonTypes

Introduction

In this page you can find the example usage for javafx.scene.control DialogPane getButtonTypes.

Prototype

public final ObservableList<ButtonType> getButtonTypes() 

Source Link

Document

Observable list of button types used for the dialog button bar area (created via the #createButtonBar() method).

Usage

From source file:org.sleuthkit.autopsy.timeline.ShowInTimelineDialog.java

/**
 * Common Private Constructor//from  w ww. ja va  2 s  .c  o m
 *
 * @param controller The controller for this Dialog.
 * @param eventIDS   A List of eventIDs to present to the user to choose
 *                   from.
 */
@NbBundle.Messages({
        "ShowInTimelineDialog.amountValidator.message=The entered amount must only contain digits." })
private ShowInTimelineDialog(TimeLineController controller, List<Long> eventIDS) {
    this.controller = controller;

    //load dialog content fxml
    final String name = "nbres:/"
            + StringUtils.replace(ShowInTimelineDialog.class.getPackage().getName(), ".", "/")
            + "/ShowInTimelineDialog.fxml"; // NON-NLS
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
        fxmlLoader.setRoot(contentRoot);
        fxmlLoader.setController(this);

        fxmlLoader.load();
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, "Unable to load FXML, node initialization may not be complete.", ex); //NON-NLS
    }
    //assert that fxml loading happened correctly
    assert eventTable != null : "fx:id=\"eventTable\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert typeColumn != null : "fx:id=\"typeColumn\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert dateTimeColumn != null : "fx:id=\"dateTimeColumn\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert amountSpinner != null : "fx:id=\"amountsSpinner\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert unitComboBox != null : "fx:id=\"unitChoiceBox\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";

    //validat that spinner has a integer in the text field.
    validationSupport.registerValidator(amountSpinner.getEditor(), false, Validator.createPredicateValidator(
            NumberUtils::isDigits, Bundle.ShowInTimelineDialog_amountValidator_message()));

    //configure dialog properties
    PromptDialogManager.setDialogIcons(this);
    initModality(Modality.APPLICATION_MODAL);

    //add scenegraph loaded from fxml to this dialog.
    DialogPane dialogPane = getDialogPane();
    dialogPane.setContent(contentRoot);
    //add buttons to dialog
    dialogPane.getButtonTypes().setAll(SHOW, ButtonType.CANCEL);

    ///configure dialog controls
    amountSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1000));
    amountSpinner.getValueFactory().setConverter(new IntegerStringConverter() {
        /**
         * Convert the String to an Integer using Integer.valueOf, but if
         * that throws a NumberFormatException, reset the spinner to the
         * last valid value.
         *
         * @param string The String to convert
         *
         * @return The Integer value of string.
         */
        @Override
        public Integer fromString(String string) {
            try {
                return super.fromString(string);
            } catch (NumberFormatException ex) {
                return amountSpinner.getValue();
            }
        }
    });

    unitComboBox.setButtonCell(new ChronoFieldListCell());
    unitComboBox.setCellFactory(comboBox -> new ChronoFieldListCell());
    unitComboBox.getItems().setAll(SCROLL_BY_UNITS);
    unitComboBox.getSelectionModel().select(ChronoField.MINUTE_OF_HOUR);

    typeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getEventType()));
    typeColumn.setCellFactory(param -> new TypeTableCell<>());

    dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getStartMillis()));
    dateTimeColumn.setCellFactory(param -> new DateTimeTableCell<>());

    //add events to table
    eventTable.getItems().setAll(
            eventIDS.stream().map(controller.getEventsModel()::getEventById).collect(Collectors.toSet()));
    eventTable.setPrefHeight(Math.min(200, 24 * eventTable.getItems().size() + 28));
}