Example usage for javafx.beans.binding Bindings createBooleanBinding

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

Introduction

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

Prototype

public static BooleanBinding createBooleanBinding(final Callable<Boolean> func,
        final Observable... dependencies) 

Source Link

Document

Helper function to create a custom BooleanBinding .

Usage

From source file:de.ks.file.FileViewController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    fileList.setItems(files);/*from ww  w  .  j a  v a  2 s  .c  o m*/

    MultipleSelectionModel<File> selectionModel = fileList.getSelectionModel();
    selectionModel.setSelectionMode(SelectionMode.MULTIPLE);

    ReadOnlyObjectProperty<File> selection = selectionModel.selectedItemProperty();
    selection.addListener((p, o, n) -> {
        folderName.setText(n == null ? "" : n.getParentFile().getAbsolutePath());
        fileNameLabel.setText(n == null ? "" : n.getName());
    });

    BooleanBinding isDirectory = Bindings
            .createBooleanBinding(() -> selection.get() != null && selection.get().isDirectory(), selection);
    edit.disableProperty().bind(isDirectory);

    files.addListener((ListChangeListener<File>) change -> {
        files.forEach(file -> {
            if (!fileReferences.containsKey(file) && file.exists() && !file.isDirectory()) {
                fileReferences.put(file, fileStore.getReference(file));
            }
        });
    });
    BooleanBinding disable = fileList.getSelectionModel().selectedItemProperty().isNull();
    open.disableProperty().bind(disable);
    edit.disableProperty().bind(disable);
    openFolder.disableProperty().bind(disable);
    removeFile.disableProperty().bind(disable);
}

From source file:org.beryx.viewreka.fxapp.ProjectBasicInfo.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    check("txtNewProjectName", txtNewProjectName);
    check("txtNewProjectDir", txtNewProjectDir);
    check("butNewProjectDir", butNewProjectDir);

    Bindings.createBooleanBinding(() -> isProjectNameValid(txtNewProjectName.getText()),
            txtNewProjectName.textProperty());
    Bindings.createBooleanBinding(() -> isDirPathValid(txtNewProjectDir.getText()),
            txtNewProjectDir.textProperty());
}

From source file:org.beryx.viewreka.fxapp.ProjectLibs.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    check("lstLib", lstLib);
    check("butBundleAdd", butBundleAdd);
    check("butUncatalogedLibAdd", butUncatalogedLibAdd);
    check("butLibRemove", butLibRemove);
    check("lstExistingLib", lstExistingLib);

    lstLib.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    BooleanBinding libRemoveBinding = Bindings.createBooleanBinding(() -> lstLib.getSelectionModel().isEmpty(),
            lstLib.getSelectionModel().selectedItemProperty());
    butLibRemove.disableProperty().bind(libRemoveBinding);

    lstLib.setCellFactory(new Callback<ListView<LibListEntry>, ListCell<LibListEntry>>() {
        @Override//  ww  w. jav  a  2s  .co m
        public ListCell<LibListEntry> call(ListView<LibListEntry> entry) {
            return new ListCell<LibListEntry>() {
                @Override
                public void updateItem(LibListEntry item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty || item == null) {
                        setText(null);
                        setGraphic(null);
                    } else {
                        setText(item.getCellText());
                        String tooltipText = item.getTooltipText();
                        if (tooltipText != null && !tooltipText.isEmpty()) {
                            setTooltip(new Tooltip(tooltipText));
                        }
                    }
                }
            };
        }
    });
}

From source file:org.beryx.viewreka.fxapp.Viewreka.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    check("mainSplitPane", mainSplitPane);
    check("fileSplitPane", fileSplitPane);
    check("sourceCodeArea", sourceCodeArea);
    check("errorArea", errorArea);
    check("projectTabPane", projectTabPane);
    check("viewsTabPane", viewsTabPane);

    check("mnuNewProject", mnuNewProject);
    check("butNewProject", butNewProject);
    check("mnuOpenProject", mnuOpenProject);
    check("butOpenProject", butOpenProject);
    check("mnuEditProject", mnuEditProject);

    check("mnuNewFile", mnuNewFile);
    check("butNewFile", butNewFile);
    check("mnuOpenFile", mnuOpenFile);
    check("butOpenFile", butOpenFile);

    check("mnuSaveFile", mnuSaveFile);
    check("butSaveFile", butSaveFile);
    check("mnuSaveAll", mnuSaveAll);
    check("butSaveAll", butSaveAll);

    check("mnuCloseTab", mnuCloseTab);
    check("mnuCloseProject", mnuCloseProject);

    check("mnuReloadProject", mnuReloadProject);
    check("butReloadProject", butReloadProject);

    check("mnuToggleFilePane", mnuToggleFilePane);

    check("mnuShowSourceCode", mnuShowSourceCode);
    check("tabSourceCode", tabSourceCode);
    check("mnuShowHelp", mnuShowHelp);
    check("tabHelp", tabHelp);

    check("mnuExportChart", mnuExportChart);
    check("butExportChart", butExportChart);
    check("mnuExportVideo", mnuExportVideo);
    check("butExportVideo", butExportVideo);

    check("mnuStylesheet", mnuStylesheet);

    check("helpBrowser", helpBrowser);

    helpBrowser.getEngine().load("about:blank");

    menuTabBindingSourceCode = new MenuTabBinding(projectTabPane, tabSourceCode, mnuShowSourceCode,
            FILE_ALIAS_SOURCE_CODE, true);
    menuTabBindingHelp = new MenuTabBinding(projectTabPane, tabHelp, mnuShowHelp, FILE_ALIAS_HELP, false);
    projectTabPane.getTabs().addListener((ListChangeListener<Tab>) (change -> {
        showFilePane(!projectTabPane.getTabs().isEmpty(), project);
    }));//from ww  w.  ja  v a  2 s  . c  o  m

    // TODO - implement Help and remove the following line
    mnuShowHelp.setVisible(false);

    BooleanBinding projectClosedBinding = projectPathProperty.isNull();
    mnuReloadProject.disableProperty().bind(projectClosedBinding);
    butReloadProject.disableProperty().bind(projectClosedBinding);
    mnuCloseProject.disableProperty().bind(projectClosedBinding);
    mnuEditProject.disableProperty().bind(projectClosedBinding);

    BooleanBinding tabClosedBinding = Bindings.createBooleanBinding(
            () -> projectTabPane.getSelectionModel().isEmpty(),
            projectTabPane.getSelectionModel().selectedItemProperty());
    mnuCloseTab.disableProperty().bind(tabClosedBinding);

    BooleanBinding chartExportDisabledBinding = viewsTabPane.getSelectionModel().selectedItemProperty()
            .isNull();
    mnuExportChart.disableProperty().bind(chartExportDisabledBinding);
    butExportChart.disableProperty().bind(chartExportDisabledBinding);

    BooleanBinding videoExportDisabledBinding = Bindings.createBooleanBinding(() -> {
        ViewPane<?> viewPane = getCurrentViewPane();
        if (viewPane == null)
            return true;
        Parameter<?> parameter = viewPane.getIteratedParameter();
        if (parameter == null)
            return true;
        if (!parameter.isIterable())
            return true;
        if (parameter.getPossibleValues() == null || parameter.getPossibleValues().isEmpty())
            return true;
        return false;
    }, viewsTabPane.getSelectionModel().selectedItemProperty());

    mnuExportVideo.disableProperty().bind(videoExportDisabledBinding);
    butExportVideo.disableProperty().bind(videoExportDisabledBinding);

    sourceCodeArea.setClassLoaderManager(this);

    setProject(null, null, false);
}