Example usage for javafx.beans.binding Bindings bindBidirectional

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

Introduction

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

Prototype

public static <T> void bindBidirectional(Property<T> property1, Property<T> property2) 

Source Link

Document

Generates a bidirectional binding (or "bind with inverse") between two instances of javafx.beans.property.Property .

Usage

From source file:de.perdian.apps.tagtiger.fx.handlers.batchupdate.UpdateFileNamesFromTagsActionEventHandler.java

@Override
protected BatchUpdateDialog createDialog() {

    ObservableList<UpdateFileNamesFromTagsItem> items = FXCollections.observableArrayList(
            this.getOtherFiles().stream().map(UpdateFileNamesFromTagsItem::new).collect(Collectors.toList()));
    StringProperty patternFieldProperty = new SimpleStringProperty();

    List<String> patternItems = Arrays.asList("${track} ${title}");
    ComboBox<String> patternBox = new ComboBox<>(FXCollections.observableArrayList(patternItems));
    patternBox.setEditable(true);/* w w  w .  j  a v a 2 s  . c  om*/
    patternBox.setMaxWidth(Double.MAX_VALUE);
    Bindings.bindBidirectional(patternFieldProperty, patternBox.editorProperty().get().textProperty());
    HBox.setHgrow(patternBox, Priority.ALWAYS);

    Button executeButton = new Button(this.getLocalization().executeRename(),
            new ImageView(new Image(UpdateFileNamesFromTagsActionEventHandler.class.getClassLoader()
                    .getResourceAsStream("icons/16/save.png"))));
    executeButton.setDisable(true);
    patternFieldProperty
            .addListener((o, oldValue, newValue) -> executeButton.setDisable(newValue.length() <= 0));

    HBox patternFieldPane = new HBox(10, patternBox, executeButton);
    patternFieldPane.setPadding(new Insets(5, 5, 5, 5));

    TitledPane patternFieldTitlePane = new TitledPane(this.getLocalization().fileNamePattern(),
            patternFieldPane);
    patternFieldTitlePane.setCollapsible(false);

    TableView<?> newFileNamesPane = this.createNewFileNamesPane(items);
    newFileNamesPane.setPrefHeight(400);
    VBox.setVgrow(newFileNamesPane, Priority.ALWAYS);

    VBox actionPane = new VBox(10, patternFieldTitlePane, newFileNamesPane);

    // Create the dialog and finish
    BatchUpdateDialog dialog = new BatchUpdateDialog();
    dialog.setDialogPrefWidth(800);
    dialog.setDialogTitle(this.getLocalization().updateFileNames());
    dialog.setActionPane(actionPane);
    dialog.setLegendPane(this.createLegendPane());

    // Add listeners
    this.getOtherFiles().addListener(
            new WeakListChangeListener<>((Change<? extends TaggableFile> change) -> items.setAll(change
                    .getList().stream().map(UpdateFileNamesFromTagsItem::new).collect(Collectors.toList()))));
    patternFieldProperty.addListener((o, oldValue, newValue) -> this.computeNewFileNames(items, newValue));
    executeButton.setOnAction(event -> {
        this.updateNewFileNames(items);
        ((Stage) executeButton.getScene().getWindow()).close();
    });

    return dialog;

}

From source file:mesclasses.view.JourneeController.java

/**
 * dessine la grid vie scolaire/*ww  w.j a va 2 s.c  o m*/
 * @param eleve
 * @param rowIndex 
 */
private void drawVieScolaire(Eleve eleve, int rowIndex) {
    EleveData eleveData = seanceSelect.getValue().getDonnees().get(eleve);
    drawEleveName(vieScolaireGrid, eleve, rowIndex);
    if (!eleve.isInClasse(currentDate.getValue())) {
        return;
    }
    CheckBox box = new CheckBox();
    Bindings.bindBidirectional(box.selectedProperty(), eleveData.absentProperty());
    vieScolaireGrid.add(box, 3, rowIndex, null);

    TextField retardField = new TextField();
    retardField.setMaxWidth(50);
    Bindings.bindBidirectional(retardField.textProperty(), eleveData.retardProperty(),
            new IntegerOnlyConverter());
    markAsInteger(retardField);

    vieScolaireGrid.add(retardField, 4, rowIndex, HPos.CENTER);

    Label cumulRetard = new Label();
    retardField.textProperty().addListener((observable, oldValue, newValue) -> {
        writeAndMarkInRed(cumulRetard, stats.getNbRetardsUntil(eleve, currentDate.getValue()), 3);
    });

    writeAndMarkInRed(cumulRetard, stats.getNbRetardsUntil(eleve, currentDate.getValue()), 3);
    vieScolaireGrid.add(cumulRetard, 5, rowIndex, null);
}

From source file:mesclasses.view.JourneeController.java

/**
 * dessine la grid travail//from   www.  j av a  2  s  .c  o  m
 * @param eleve
 * @param rowIndex 
 */
private void drawTravail(Eleve eleve, int rowIndex) {

    EleveData eleveData = seanceSelect.getValue().getDonnees().get(eleve);
    drawEleveName(travailGrid, eleve, rowIndex);
    if (!eleve.isInClasse(currentDate.getValue())) {
        return;
    }
    CheckBox travailBox = new CheckBox();
    Bindings.bindBidirectional(travailBox.selectedProperty(), eleveData.travailPasFaitProperty());
    travailGrid.add(travailBox, 3, rowIndex, null);
    Label cumulTravail = new Label();
    travailBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
        writeAndMarkInRed(cumulTravail, stats.getNbTravailUntil(eleve, currentDate.getValue()), 3);
    });
    writeAndMarkInRed(cumulTravail, stats.getNbTravailUntil(eleve, currentDate.getValue()), 3);
    travailGrid.add(cumulTravail, 4, rowIndex, null);

    CheckBox devoirBox = new CheckBox();
    devoirBox.setSelected(model.getDevoirForSeance(eleve, seanceSelect.getValue()) != null);
    devoirBox.selectedProperty().addListener((ob, o, checked) -> {
        Devoir devoir = model.getDevoirForSeance(eleve, seanceSelect.getValue());
        if (checked && devoir == null) {
            model.createDevoir(eleve, seanceSelect.getValue());
        } else if (devoir != null) {
            model.delete(devoir);
        }
    });
    travailGrid.add(devoirBox, 5, rowIndex, null);

    TextField oubliMaterielField = new TextField();
    Bindings.bindBidirectional(oubliMaterielField.textProperty(), eleveData.oubliMaterielProperty());
    travailGrid.add(oubliMaterielField, 6, rowIndex, HPos.LEFT);
    Label cumulOubli = new Label();
    oubliMaterielField.textProperty().addListener((observable, oldValue, newValue) -> {
        writeAndMarkInRed(cumulOubli, stats.getNbOublisUntil(eleve, currentDate.getValue()), 3);
    });

    writeAndMarkInRed(cumulOubli, stats.getNbOublisUntil(eleve, currentDate.getValue()), 3);
    travailGrid.add(cumulOubli, 7, rowIndex, null);

}

From source file:mesclasses.view.JourneeController.java

/**
 * dessine la grid sanctions/*from   www.j a v a  2 s .  c o m*/
 * @param eleve
 * @param rowIndex 
 */
private void drawSanctions(Eleve eleve, int rowIndex) {
    EleveData eleveData = seanceSelect.getValue().getDonnees().get(eleve);

    drawEleveName(sanctionsGrid, eleve, rowIndex);
    if (!eleve.isInClasse(currentDate.getValue())) {
        return;
    }
    HBox punitionsBox = new HBox();
    punitionsBox.setAlignment(Pos.CENTER_LEFT);
    TextFlow nbPunitions = new TextFlow();
    Label nbPunitionLabel = new Label(
            "" + eleve.getPunitions().stream().filter(p -> p.getSeance() == seanceSelect.getValue()).count());
    nbPunitionLabel.setPrefHeight(20);
    nbPunitions.getChildren().add(new Label(" ("));
    nbPunitions.getChildren().add(nbPunitionLabel);
    nbPunitions.getChildren().add(new Label(")"));

    nbPunitions.visibleProperty().bind(nbPunitionLabel.textProperty().isNotEqualTo("0"));
    nbPunitions.managedProperty().bind(nbPunitionLabel.textProperty().isNotEqualTo("0"));

    Button punitionBtn = Btns.punitionBtn();
    punitionBtn.setOnAction((event) -> {
        if (openPunitionDialog(eleve)) {
            int nbPunition = Integer.parseInt(nbPunitionLabel.getText());
            nbPunitionLabel.setText("" + (nbPunition + 1));
        }
    });
    punitionsBox.getChildren().add(punitionBtn);
    punitionsBox.getChildren().add(nbPunitions);

    sanctionsGrid.add(punitionsBox, 3, rowIndex, HPos.LEFT);

    CheckBox motCarnet = new CheckBox();
    Label cumulMot = new Label();
    motCarnet.setSelected(model.getMotForSeance(eleve, seanceSelect.getValue()) != null);
    motCarnet.selectedProperty().addListener((ob, o, checked) -> {
        Mot mot = model.getMotForSeance(eleve, seanceSelect.getValue());
        if (checked && mot == null) {
            model.createMot(eleve, seanceSelect.getValue());
        } else if (mot != null) {
            model.delete(mot);
        }
        writeAndMarkInRed(cumulMot, stats.getMotsUntil(eleve, currentDate.getValue()).size(), 3);
    });
    sanctionsGrid.add(motCarnet, 4, rowIndex, null);
    writeAndMarkInRed(cumulMot, stats.getMotsUntil(eleve, currentDate.getValue()).size(), 3);
    sanctionsGrid.add(cumulMot, 5, rowIndex, null);

    CheckBox exclus = new CheckBox();
    TextField motif = new TextField();
    Bindings.bindBidirectional(exclus.selectedProperty(), eleveData.exclusProperty());
    sanctionsGrid.add(exclus, 6, rowIndex, null);
    exclus.selectedProperty().addListener((o, oldV, newV) -> {
        if (!newV && StringUtils.isNotBlank(motif.getText())
                && ModalUtil.confirm("Effacer le motif ?", "Effacer le motif ?")) {
            motif.clear();
        }
    });

    Bindings.bindBidirectional(motif.textProperty(), eleveData.MotifProperty());
    motif.textProperty().addListener((o, oldV, newV) -> {
        if (StringUtils.isNotBlank(newV)) {
            exclus.setSelected(true);
        }
    });
    GridPane.setMargin(motif, new Insets(0, 10, 0, 0));
    sanctionsGrid.add(motif, 7, rowIndex, HPos.LEFT);

}