Example usage for javafx.beans.binding Bindings and

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

Introduction

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

Prototype

public static BooleanBinding and(final ObservableBooleanValue op1, final ObservableBooleanValue op2) 

Source Link

Document

Creates a BooleanBinding that calculates the conditional-AND operation on the value of two instance of javafx.beans.value.ObservableBooleanValue .

Usage

From source file:caillou.company.clonemanager.gui.customComponent.critere.CritereController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    mainModel.getCritereModel().getFormat().allProperty().bind(formatAllId.selectedProperty());
    mainModel.getCritereModel().getFormat().videoProperty().bind(
            Bindings.and(formatVideoId.selectedProperty(), Bindings.not(formatVideoId.disableProperty())));
    mainModel.getCritereModel().getFormat().audioProperty().bind(
            Bindings.and(formatAudioId.selectedProperty(), Bindings.not(formatAudioId.disableProperty())));
    mainModel.getCritereModel().getFormat().imageProperty().bind(
            Bindings.and(formatImageId.selectedProperty(), Bindings.not(formatImageId.disableProperty())));
    mainModel.getCritereModel().getFormat().archiveProperty().bind(
            Bindings.and(formatArchiveId.selectedProperty(), Bindings.not(formatArchiveId.disableProperty())));

    LongBinding minimumSizeComputationBinding = new LongBinding() {
        {//  w w  w.j a v a2 s . c om
            super.bind(minimumSizeFormatId.valueProperty(), sizeMinId.valueProperty());
        }

        @Override
        protected long computeValue() {
            if (minimumSizeFormatId.getValue().equals("octet")) {
                return (long) sizeMinId.valueProperty().get() * 1;
            }
            if (minimumSizeFormatId.getValue().equals("kilo octet")) {
                return (long) sizeMinId.valueProperty().get() * 1000;
            }
            if (minimumSizeFormatId.getValue().equals("mega octet")) {
                return (long) sizeMinId.valueProperty().get() * 1000000;
            }
            if (minimumSizeFormatId.getValue().equals("giga octet")) {
                return (long) sizeMinId.valueProperty().get() * 1000000000;
            }
            throw new IllegalArgumentException("Unkowned size format");
        }
    };

    mainModel.getCritereModel().getSize().minimalSizeProperty().bind(minimumSizeComputationBinding);

    LongBinding maximumSizeComputationBinding = new LongBinding() {
        {
            super.bind(maximumSizeFormatId.valueProperty(), sizeMaxId.valueProperty());
        }

        @Override
        protected long computeValue() {
            if (maximumSizeFormatId.getValue().equals("octet")) {
                return (long) sizeMaxId.valueProperty().get() * 1;
            }
            if (maximumSizeFormatId.getValue().equals("kilo octet")) {
                return (long) sizeMaxId.valueProperty().get() * 1000;
            }
            if (maximumSizeFormatId.getValue().equals("mega octet")) {
                return (long) sizeMaxId.valueProperty().get() * 1000000;
            }
            if (maximumSizeFormatId.getValue().equals("giga octet")) {
                return (long) sizeMaxId.valueProperty().get() * 1000000000;
            }
            throw new IllegalArgumentException("Unkowned size format");
        }
    };

    mainModel.getCritereModel().getSize().minimalSizeProperty().bind(minimumSizeComputationBinding);
    mainModel.getCritereModel().getSize().maximalSizeProperty().bind(maximumSizeComputationBinding);

    formatAllId.selectedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            disableEnableCheckboxes(newValue);
            if (newValue) {
                formatVideoId.setSelected(false);
                formatAudioId.setSelected(false);
                formatImageId.setSelected(false);
                formatArchiveId.setSelected(false);
            }
        }
    });
}

From source file:caillou.company.clonemanager.gui.customComponent.search.SearchController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    MainApp app = MainApp.getInstance();
    app.getStage().sizeToScene();//from w w w.j a  v  a  2  s  .  c o m
    app.getStage().hide();
    app.getStage().show();
    validerButton.disableProperty().bind(Bindings.not(Bindings
            .and(mainModel.getLocationsModel().validProperty(), mainModel.getCritereModel().validProperty())));
    StatisticsModel searchStatisticsModel = SpringFxmlLoader.getBean(StatisticsModel.class);
    mainModel.setSearchStatisticsModel(searchStatisticsModel);
}

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

private void updateProjectTabs(ProjectSettings projectSettings) {

    if (selectedIndexListener != null) {
        projectTabPane.getSelectionModel().selectedIndexProperty().removeListener(selectedIndexListener);
    }// w  w  w.  j a v  a  2s  . c o  m

    menuTabBindingSourceCode.setSettings(projectSettings, true);
    menuTabBindingHelp.setSettings(projectSettings, false);

    if (projectSettings != null) {
        selectedIndexListener = (obs, oldValue, newValue) -> projectSettings
                .setProperty(PROP_SELECTED_TAB_INDEX, newValue);
        projectTabPane.getSelectionModel().selectedIndexProperty().addListener(selectedIndexListener);

        selectedItemListener = (obs, oldTab, newTab) -> {
            butSaveFile.disableProperty().unbind();
            mnuSaveFile.disableProperty().unbind();
            butSaveFile.setDisable(true);
            mnuSaveFile.setDisable(true);
            if (newTab != null) {
                CodeTabData tabData = getData(newTab);
                Platform.runLater(() -> {
                    BooleanBinding scriptChangedBinding = Bindings.createBooleanBinding(
                            () -> !tabData.isDirty(), tabData.getTextProperty(),
                            tabData.getInitialTextProperty());
                    butSaveFile.disableProperty().bind(scriptChangedBinding);
                    mnuSaveFile.disableProperty().bind(scriptChangedBinding);

                    StringBinding tabTextBinding = Bindings.createStringBinding(() -> {
                        String text = tabData.getTabText();
                        if (tabData.isDirty()) {
                            text = "*" + text;
                        }
                        return text;
                    }, tabData.getTextProperty(), tabData.getInitialTextProperty());
                    newTab.textProperty().bind(tabTextBinding);
                });
            }

            Platform.runLater(() -> {
                menuTabBindingSourceCode.setSettings(projectSettings, true);
                menuTabBindingHelp.setSettings(projectSettings, false);

                butSaveAll.disableProperty().unbind();
                mnuSaveAll.disableProperty().unbind();
                butSaveAll.setDisable(true);
                mnuSaveAll.setDisable(true);

                List<BooleanBinding> saveBindings = new ArrayList<>();
                projectTabPane.getTabs().forEach(tab -> {
                    CodeTabData tabData = getData(tab);
                    saveBindings.add(Bindings.createBooleanBinding(() -> !tabData.isDirty(),
                            tabData.getTextProperty(), tabData.getInitialTextProperty()));
                });
                if (!saveBindings.isEmpty()) {
                    BooleanBinding binding = saveBindings.get(0);
                    for (int i = 1; i < saveBindings.size(); i++) {
                        binding = Bindings.and(binding, saveBindings.get(i));
                    }
                    mnuSaveAll.disableProperty().bind(binding);
                    butSaveAll.disableProperty().bind(binding);
                }
            });
        };
        projectTabPane.getSelectionModel().selectedItemProperty().addListener(selectedItemListener);
    }

    int selectedTabIndex = (projectSettings == null) ? 0
            : projectSettings.getProperty(PROP_SELECTED_TAB_INDEX, 0, false);

    ObservableList<Tab> tabs = projectTabPane.getTabs();
    tabs.clear();

    Tab selectedTab = null;
    List<String> openFiles = getOpenFiles(projectSettings);
    for (int i = 0; i < openFiles.size(); i++) {
        String filePath = openFiles.get(i);
        Tab addedTab = null;
        if (filePath.equals(FILE_ALIAS_SOURCE_CODE)) {
            addedTab = tabSourceCode;
            String projectPath = projectPathProperty.get();
            String tabText = (projectPath == null) ? "Code" : new File(projectPath).getName();
            tabSourceCode.setUserData(new CodeTabData(tabText));
        } else if (filePath.equals(FILE_ALIAS_HELP)) {
            addedTab = tabHelp;
        } else {
            try {
                File file = new File(filePath);
                addedTab = CodeAreaTab.fromFile(file);
                final Tab tab = addedTab;
                tab.setOnCloseRequest(ev -> {
                    if (!tryClose(tab))
                        ev.consume();
                });
            } catch (Exception e) {
                addedTab = null;
            }
        }
        if (addedTab != null) {
            tabs.add(addedTab);
            getData(addedTab).setFilePath(filePath);
            if (i == selectedTabIndex) {
                selectedTab = addedTab;
            }
        }
    }
    if (!tabs.isEmpty()) {
        if (selectedTab == null) {
            selectedTab = tabs.get(0);
        }
        projectTabPane.getSelectionModel().select(null);
        projectTabPane.getSelectionModel().select(selectedTab);
    }
}