Example usage for javafx.beans.binding Bindings isEmpty

List of usage examples for javafx.beans.binding Bindings isEmpty

Introduction

In this page you can find the example usage for javafx.beans.binding Bindings isEmpty.

Prototype

public static <K, V> BooleanBinding isEmpty(final ObservableMap<K, V> op) 

Source Link

Document

Creates a new javafx.beans.binding.BooleanBinding that holds true if a given javafx.collections.ObservableMap is empty.

Usage

From source file:aajavafx.LoginController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    //Disables checkbox if username and password are blank
    saveCredentials.disableProperty()/*  w w w . j av  a 2s  . co m*/
            .bind(Bindings.isEmpty(userID.textProperty()).or(Bindings.isEmpty(passwordID.textProperty())));
    if (Files.isReadable(savedCredentials)) {
        //reads file and autofills the textfields
        try (ObjectInputStream in = new ObjectInputStream(Files.newInputStream(savedCredentials))) {
            UserCredentials user = (UserCredentials) in.readObject();
            userID.setText(user.getUsername());
            passwordID.setText(user.getPassword());

        } catch (IOException ex) {
            System.out.println("IO Exception: " + ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:ninja.javafx.smartcsv.fx.SmartCSVController.java

private void binExportButtons() {
    exportButton.disableProperty().bind(Bindings.isEmpty(currentCsvFile.getContent().getValidationError()));
    exportMenuItem.disableProperty().bind(Bindings.isEmpty(currentCsvFile.getContent().getValidationError()));
}

From source file:org.cryptomator.ui.controllers.MainController.java

@Override
public void initialize() {
    vaultList.setItems(vaults);//from w  ww  .j  av  a  2  s  .co m
    vaultList.setCellFactory(this::createDirecoryListCell);
    activeController.set(welcomeController.get());
    selectedVault.bind(vaultList.getSelectionModel().selectedItemProperty());
    removeVaultButton.disableProperty().bind(canEditSelectedVault.not());
    emptyListInstructions.visibleProperty().bind(Bindings.isEmpty(vaults));
    changePasswordMenuItem.visibleProperty().bind(isSelectedVaultValid);

    EasyBind.subscribe(selectedVault, this::selectedVaultDidChange);
    EasyBind.subscribe(activeController, this::activeControllerDidChange);
    EasyBind.subscribe(isShowingSettings, settingsButton::setSelected);
    EasyBind.subscribe(addVaultContextMenu.showingProperty(), addVaultButton::setSelected);
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.drawableviews.GroupPane.java

/**
 * called automatically during constructor by FXMLConstructor.
 *
 * checks that FXML loading went ok and performs additional setup
 *///  w w  w. j a va2  s .c  o  m
@FXML
@NbBundle.Messages({ "GroupPane.gridViewContextMenuItem.extractFiles=Extract File(s)",
        "GroupPane.bottomLabel.displayText=Group Viewing History: ",
        "GroupPane.hederLabel.displayText=Tag Selected Files:",
        "GroupPane.catContainerLabel.displayText=Categorize Selected File:",
        "GroupPane.catHeadingLabel.displayText=Category:" })
void initialize() {
    assert cat0Toggle != null : "fx:id=\"cat0Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat1Toggle != null : "fx:id=\"cat1Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat2Toggle != null : "fx:id=\"cat2Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat3Toggle != null : "fx:id=\"cat3Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat4Toggle != null : "fx:id=\"cat4Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat5Toggle != null : "fx:id=\"cat5Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert gridView != null : "fx:id=\"tilePane\" was not injected: check your FXML file 'GroupPane.fxml'.";
    assert catSelectedSplitMenu != null : "fx:id=\"grpCatSplitMenu\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert tagSelectedSplitMenu != null : "fx:id=\"grpTagSplitMenu\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert headerToolBar != null : "fx:id=\"headerToolBar\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert segButton != null : "fx:id=\"previewList\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert slideShowToggle != null : "fx:id=\"segButton\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert tileToggle != null : "fx:id=\"tileToggle\" was not injected: check your FXML file 'GroupHeader.fxml'.";

    for (Category cat : Category.values()) {
        ToggleButton toggleForCategory = getToggleForCategory(cat);
        toggleForCategory.setBorder(new Border(
                new BorderStroke(cat.getColor(), BorderStrokeStyle.SOLID, CORNER_RADII_2, BORDER_WIDTHS_2)));
        toggleForCategory.getStyleClass().remove("radio-button");
        toggleForCategory.getStyleClass().add("toggle-button");
        toggleForCategory.selectedProperty().addListener((ov, wasSelected, toggleSelected) -> {
            if (toggleSelected && slideShowPane != null) {
                slideShowPane.getFileID().ifPresent(fileID -> {
                    selectionModel.clearAndSelect(fileID);
                    new CategorizeAction(controller, cat, ImmutableSet.of(fileID)).handle(null);
                });
            }
        });
    }

    //configure flashing glow animation on next unseen group button
    flashAnimation.setCycleCount(Timeline.INDEFINITE);
    flashAnimation.setAutoReverse(true);

    //configure gridView cell properties
    DoubleBinding cellSize = controller.thumbnailSizeProperty().add(75);
    gridView.cellHeightProperty().bind(cellSize);
    gridView.cellWidthProperty().bind(cellSize);
    gridView.setCellFactory((GridView<Long> param) -> new DrawableCell());

    BooleanBinding isSelectionEmpty = Bindings.isEmpty(selectionModel.getSelected());
    catSelectedSplitMenu.disableProperty().bind(isSelectionEmpty);
    tagSelectedSplitMenu.disableProperty().bind(isSelectionEmpty);

    Platform.runLater(() -> {
        try {
            TagSelectedFilesAction followUpSelectedACtion = new TagSelectedFilesAction(
                    controller.getTagsManager().getFollowUpTagName(), controller);
            tagSelectedSplitMenu.setText(followUpSelectedACtion.getText());
            tagSelectedSplitMenu.setGraphic(followUpSelectedACtion.getGraphic());
            tagSelectedSplitMenu.setOnAction(followUpSelectedACtion);
        } catch (TskCoreException tskCoreException) {
            LOGGER.log(Level.WARNING, "failed to load FollowUpTagName", tskCoreException); //NON-NLS
        }
        tagSelectedSplitMenu.showingProperty().addListener(showing -> {
            if (tagSelectedSplitMenu.isShowing()) {
                List<MenuItem> selTagMenues = Lists.transform(
                        controller.getTagsManager().getNonCategoryTagNames(),
                        tagName -> GuiUtils.createAutoAssigningMenuItem(tagSelectedSplitMenu,
                                new TagSelectedFilesAction(tagName, controller)));
                tagSelectedSplitMenu.getItems().setAll(selTagMenues);
            }
        });

    });

    CategorizeSelectedFilesAction cat5SelectedAction = new CategorizeSelectedFilesAction(Category.FIVE,
            controller);
    catSelectedSplitMenu.setOnAction(cat5SelectedAction);
    catSelectedSplitMenu.setText(cat5SelectedAction.getText());
    catSelectedSplitMenu.setGraphic(cat5SelectedAction.getGraphic());
    catSelectedSplitMenu.showingProperty().addListener(showing -> {
        if (catSelectedSplitMenu.isShowing()) {
            List<MenuItem> categoryMenues = Lists.transform(Arrays.asList(Category.values()),
                    cat -> GuiUtils.createAutoAssigningMenuItem(catSelectedSplitMenu,
                            new CategorizeSelectedFilesAction(cat, controller)));
            catSelectedSplitMenu.getItems().setAll(categoryMenues);
        }
    });

    slideShowToggle.getStyleClass().remove("radio-button");
    slideShowToggle.getStyleClass().add("toggle-button");
    tileToggle.getStyleClass().remove("radio-button");
    tileToggle.getStyleClass().add("toggle-button");

    bottomLabel.setText(Bundle.GroupPane_bottomLabel_displayText());
    headerLabel.setText(Bundle.GroupPane_hederLabel_displayText());
    catContainerLabel.setText(Bundle.GroupPane_catContainerLabel_displayText());
    catHeadingLabel.setText(Bundle.GroupPane_catHeadingLabel_displayText());
    //show categorization controls depending on group view mode
    headerToolBar.getItems().remove(catSegmentedContainer);
    groupViewMode.addListener((ObservableValue<? extends GroupViewMode> observable, GroupViewMode oldValue,
            GroupViewMode newValue) -> {
        if (newValue == GroupViewMode.SLIDE_SHOW) {
            headerToolBar.getItems().remove(catSplitMenuContainer);
            headerToolBar.getItems().add(catSegmentedContainer);
        } else {
            headerToolBar.getItems().remove(catSegmentedContainer);
            headerToolBar.getItems().add(catSplitMenuContainer);
        }
    });

    //listen to toggles and update view state
    slideShowToggle
            .setOnAction(onAction -> activateSlideShowViewer(selectionModel.lastSelectedProperty().get()));
    tileToggle.setOnAction(onAction -> activateTileViewer());

    controller.viewState().addListener((observable, oldViewState, newViewState) -> setViewState(newViewState));

    addEventFilter(KeyEvent.KEY_PRESSED, tileKeyboardNavigationHandler);
    gridView.addEventHandler(MouseEvent.MOUSE_CLICKED, new MouseHandler());

    ActionUtils.configureButton(undoAction, undoButton);
    ActionUtils.configureButton(redoAction, redoButton);
    ActionUtils.configureButton(forwardAction, forwardButton);
    ActionUtils.configureButton(backAction, backButton);
    ActionUtils.configureButton(nextGroupAction, nextButton);
    /*
     * the next button does stuff in the GroupPane that next action does'nt
     * know about, so do that stuff and then delegate to nextGroupAction
     */
    final EventHandler<ActionEvent> onAction = nextButton.getOnAction();
    nextButton.setOnAction(actionEvent -> {
        flashAnimation.stop();
        nextButton.setEffect(null);
        onAction.handle(actionEvent);
    });

    nextGroupAction.disabledProperty().addListener((Observable observable) -> {
        boolean newValue = nextGroupAction.isDisabled();
        nextButton.setEffect(newValue ? null : DROP_SHADOW);
        if (newValue) {//stop on disabled
            flashAnimation.stop();
        } else { //play when enabled
            flashAnimation.play();
        }
    });

    //listen to tile selection and make sure it is visible in scroll area
    selectionModel.lastSelectedProperty().addListener((observable, oldFileID, newFileId) -> {
        if (groupViewMode.get() == GroupViewMode.SLIDE_SHOW && slideShowPane != null) {
            slideShowPane.setFile(newFileId);
        } else {
            scrollToFileID(newFileId);
        }
    });

    setViewState(controller.viewState().get());
}