Example usage for javafx.beans.binding Bindings createStringBinding

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

Introduction

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

Prototype

public static StringBinding createStringBinding(final Callable<String> func, final Observable... dependencies) 

Source Link

Document

Helper function to create a custom StringBinding .

Usage

From source file:com.github.naoghuman.testdata.abclist.service.ExerciseTermService.java

public void bind(TestdataExerciseTermPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();

    entityProperty.unbind();//  w  w w  .j  av  a  2s .  c  om
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java

public PerformUpdateDialog(RemoteVersionResult newVersion) {
    this.chosen = new SimpleObjectProperty<>(
            Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile());

    this.setHeaderText("Updating to " + newVersion.getVersion());
    this.setTitle("Skadi Updater");
    this.getDialogPane().getStyleClass().add("alert");
    this.getDialogPane().getStyleClass().add("information");

    final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE);
    this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL);

    Node btn = this.getDialogPane().lookupButton(restartButtonType);
    btn.setDisable(true);// w  ww .  j a v a  2 s.c o  m

    Label lbPath = new Label("Save as");
    TextField tfPath = new TextField();
    tfPath.textProperty()
            .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen));
    tfPath.setPrefColumnCount(40);
    tfPath.setEditable(false);

    Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse...");
    btChangePath.setOnAction(event -> {
        FileChooser fc = new FileChooser();
        fc.setTitle("Save downloaded jar..");
        fc.setInitialFileName(this.chosen.getValue().getName());
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar"));
        fc.setInitialDirectory(this.chosen.getValue().getParentFile());
        File selected = fc.showSaveDialog(this.getOwner());
        if (selected != null) {
            this.chosen.set(selected);
        }
    });

    ProgressBar pbDownload = new ProgressBar(0);
    pbDownload.setDisable(true);
    pbDownload.setMaxWidth(Double.MAX_VALUE);
    Label lbDownload = new Label("Download");
    Label lbDownloadValue = new Label();
    Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start");
    btDownload.setMaxWidth(Double.MAX_VALUE);
    btDownload.setOnAction(event -> {
        btChangePath.setDisable(true);
        btDownload.setDisable(true);

        this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue());

        lbDownloadValue.textProperty().bind(this.downloadService.messageProperty());
        pbDownload.progressProperty().bind(this.downloadService.progressProperty());

        this.downloadService.setOnSucceeded(dlEvent -> {
            btn.setDisable(false);
        });
        this.downloadService.setOnFailed(dlFailed -> {
            LOGGER.error("new version download failed", dlFailed.getSource().getException());
            lbDownloadValue.textProperty().unbind();
            lbDownloadValue.setText("Download failed, check log file for details.");
        });

        this.downloadService.start();
    });

    final GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);

    grid.add(lbPath, 0, 0);
    grid.add(tfPath, 1, 0);
    grid.add(btChangePath, 2, 0);
    grid.add(new Separator(), 0, 1, 3, 1);
    grid.add(lbDownload, 0, 2);
    grid.add(pbDownload, 1, 2);
    grid.add(btDownload, 2, 2);
    grid.add(lbDownloadValue, 1, 3);

    this.getDialogPane().setContent(grid);

    this.setResultConverter(btnType -> {
        if (btnType == restartButtonType) {
            return this.chosen.getValue();
        }

        if (btnType == ButtonType.CANCEL) {
            if (this.downloadService.isRunning()) {
                this.downloadService.cancel();
            }
        }

        return null;
    });

}

From source file:com.github.naoghuman.testdata.abclist.service.LinkMappingService.java

public void bind(TestdataLinkMappingPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();

    entityProperty.unbind();/*from  w  ww .j av a 2  s. c o m*/
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:de.pro.dbw.application.testdata.service.DreamService.java

public void bind(DreamPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = UtilProvider.getDefault().getDateConverter().convertLongToDateTime(now,
            IDateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = UtilProvider.getDefault().getDateConverter()
            .convertDateTimeToLong(startTime, IDateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();//from www.jav  a 2s.c  o m
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:com.github.naoghuman.testdata.abclist.service.TermService.java

public void bind(TestdataTermPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = DateConverter.getDefault().convertLongToDateTime(now, DateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = DateConverter.getDefault().convertDateTimeToLong(startTime,
            DateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();//ww  w.  j  a  v a 2 s  .  com
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:de.pro.dbw.application.testdata.service.ReflectionService.java

public void bind(ReflectionPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = UtilProvider.getDefault().getDateConverter().convertLongToDateTime(now,
            IDateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = UtilProvider.getDefault().getDateConverter()
            .convertDateTimeToLong(startTime, IDateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();/*from  w  w w .  j av  a 2s  .com*/
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityReflection().unbind();
    this.presenter.progressPropertyFromEntityReflection().bind(super.progressProperty());
}

From source file:com.github.naoghuman.testdata.abclist.service.LinkService.java

public void bind(TestdataLinkPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = DateConverter.getDefault().convertLongToDateTime(now, DateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = DateConverter.getDefault().convertDateTimeToLong(startTime,
            DateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();/*ww  w  . j  a  v  a2s. com*/
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:com.github.naoghuman.testdata.abclist.service.TopicService.java

public void bind(TestdataTopicPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = DateConverter.getDefault().convertLongToDateTime(now, DateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = DateConverter.getDefault().convertDateTimeToLong(startTime,
            DateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();/*from ww w  . ja v a2  s  .co m*/
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:de.pro.dbw.application.testdata.service.TipOfTheNightService.java

public void bind(TipOfTheNightPresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = UtilProvider.getDefault().getDateConverter().convertLongToDateTime(now,
            IDateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = UtilProvider.getDefault().getDateConverter()
            .convertDateTimeToLong(startTime, IDateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();/*from  w  w w. ja v a  2s .c o m*/
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}

From source file:com.github.naoghuman.testdata.abclist.service.ExerciseService.java

public void bind(TestdataExercisePresenter presenter) {
    this.presenter = presenter;

    saveMaxEntities = presenter.getSaveMaxEntities();
    timePeriod = presenter.getTimePeriod();

    String startTime = DateConverter.getDefault().convertLongToDateTime(now, DateConverter.PATTERN__DATE);
    int year = Integer.parseInt(startTime.substring(6)) - timePeriod;
    startTime = startTime.substring(0, 6) + year;

    final long convertedStartTime = DateConverter.getDefault().convertDateTimeToLong(startTime,
            DateConverter.PATTERN__DATE);
    convertedTimePeriod = now - convertedStartTime;

    entityProperty.unbind();//from   w  w  w.  j a  va  2 s .c  o m
    entityProperty.setValue(0);
    entityProperty.bind(super.progressProperty());

    this.presenter.getProgressBarPercentInformation().textProperty().bind(Bindings.createStringBinding(() -> {
        int process = (int) (entityProperty.getValue() * 100.0d);
        if (process <= 0) {
            process = 0;
        } else {
            ++process;
        }

        return process + "%"; // NOI18N
    }, entityProperty));

    this.presenter.progressPropertyFromEntityDream().unbind();
    this.presenter.progressPropertyFromEntityDream().bind(super.progressProperty());
}