Questions tagged [easybind]

From the Github website: EasyBind leverages lambdas to reduce boilerplate when creating custom bindings, provides a type-safe alternative to `Bindings.select*` methods (inspired by Anton Nashatyrev's feature request, planned for JavaFX 9) and adds monadic operations to ObservableValue.

Static methods

map

Creates a binding whose value is a mapping of some observable value.

ObservableStringValue str = ...;
Binding<Integer> strLen = EasyBind.map(str, String::length);

Compare to plain JavaFX:

ObservableStringValue str = ...;
IntegerBinding strLen = Bindings.createIntegerBinding(() -> str.get().length(), str);

combine

Creates a binding whose value is a combination of two or more (currently up to six) observable values.

ObservableStringValue str = ...;
ObservableValue<Integer> start = ...;
ObservableValue<Integer> end = ...;
Binding<String> subStr = EasyBind.combine(str, start, end, String::substring);

Compare to plain JavaFX:

ObservableStringValue str = ...;
ObservableIntegerValue start = ...;
ObservableIntegerValue end = ...;
StringBinding subStr = Bindings.createStringBinding(() -> str.get().substring(start.get(), end.get()), str, start, end);

select

Type-safe alternative to Bindings.select* methods.

Binding<Boolean> bb = EasyBind.select(control.sceneProperty()) 
        .select(s -> s.windowProperty()) 
        .selectObject(w -> w.showingProperty());

Compare to plain JavaFX:

BooleanBinding bb = Bindings.selectBoolean(control.sceneProperty(), "window", "isShowing");

map list

Returns a mapped view of an ObservableList.

ObservableList<String> tabIds = EasyBind.map(tabPane.getTabs(), Tab::getId);

combine list

Turns an observable list of observable values into a single observable value. The resulting observable value is updated when elements are added or removed to or from the list, as well as when element values change.

Property<Integer> a = new SimpleObjectProperty<>(5);
Property<Integer> b = new SimpleObjectProperty<>(10);
ObservableList<Property<Integer>> list = FXCollections.observableArrayList();

Binding<Integer> sum = EasyBind.combine(
        list,
        stream -> stream.reduce((a, b) -> a + b).orElse(0));

assert sum.getValue() == 0;

// sum responds to element additions
list.add(a);
list.add(b);
assert sum.getValue() == 15;

// sum responds to element value changes
a.setValue(20);
assert sum.getValue() == 30;

// sum responds to element removals
list.remove(a);
assert sum.getValue() == 10;

bind list

Occasionally one needs to synchronize the contents of an (observable) list with another observable list:

ObservableList<T> sourceList = ...;
List<T> targetList = ...;
EasyBind.listBind(targetList, sourceList);

subscribe to values

Often one wants to execute some code for each value of an ObservableValue, that is for the current value and each new value. This typically results in code like this:

this.doSomething(observable.getValue());
observable.addListener((obs, oldValue, newValue) -> this.doSomething(newValue));

This can be expressed more concisely using the `subscribe` helper method:
```java
EasyBind.subscribe(observable, this::doSomething);

conditional collection membership

EasyBind.includeWhen includes or excludes an element in/from a collection based on a boolean condition.

Say that you want to draw a graph and highlight an edge when the edge itself or either of its end vertices is hovered over. To achieve this, let's add .highlight CSS class to the edge node when either of the three is hovered over and remove it when none of them is hovered over:

BooleanBinding highlight = edge.hoverProperty()
        .or(v1.hoverProperty())
        .or(v2.hoverProperty());
EasyBind.includeWhen(edge.getStyleClass(), "highlight", highlight);
.highlight { -fx-stroke: green; }

Maven Artifact

<!-- https://mvnrepository.com/artifact/org.fxmisc.easybind/easybind -->
<dependency>
    <groupId>org.fxmisc.easybind</groupId>
    <artifactId>easybind</artifactId>
    <version>1.0.3</version>
</dependency>
13 questions
7
votes
0 answers

JavaFX: Dynamic Boolean Binding in RowFactory

This question goes further where JavaFX: BooleanBindings in bind with multiple EasyBind maps stopped. I would like to extend the row factory a bit further: In table 1 the products are presented with 1 piece a row, so there could be multiple rows for…
bashoogzaad
  • 4,611
  • 8
  • 40
  • 65
4
votes
1 answer

Groovy method reference for multiple instances

I am migrating from Java to Groovy and having an issue with method references. In Java, I could do this: Function f = Bean::method; String s = f.apply(new Bean()); I want to implement the same functionality in Groovy. I tried…
Chris Smith
  • 2,928
  • 4
  • 27
  • 59
2
votes
2 answers

Binding to a ObservableValue instead of an ObservableList with EasyBind

I've got a master/detail panel with ModelItem items. Each ModelItem has a ListProperty, and each ModelItemDetail has a few StringPropertys. In the detail panel, I want to show a Label that will have its text bounded to and derived…
Xavi López
  • 27,550
  • 11
  • 97
  • 161
1
vote
1 answer

Bind sum of integer from values of a map to text property

I got the following data model: public class Player { // enum to integer (count) @Getter private MapProperty resourceCards = new SimpleMapProperty<>(); public void addResource(final ResourceType resourceType, final…
alexander
  • 1,191
  • 2
  • 20
  • 40
1
vote
1 answer

JavaFX Bind UI to a nested class's property

I have a class called Passage that contains a non-observable class called Action. And Action contains a SimpleStringProperty. class Passage { Action action = null; Action getAction() { return action; } void setAction(Action action) {…
skrilmps
  • 625
  • 2
  • 10
  • 29
1
vote
0 answers

Make JavaFX TableView Rows Unselectable and NoFocusTraversable

I am trying to make JavaFX Rows Unselectable,NoFocusTraversable but i have no luck doing that. Below is the code of another question which you can use to play with it . I have added two custom lines to make some rows no focus traversable. Although i…
GOXR3PLUS
  • 6,877
  • 9
  • 44
  • 93
1
vote
1 answer

JavaFX: BooleanBindings in bind with multiple EasyBind maps

This question goes further where JavaFX: Disable multiple rows in TableView based on other TableView stops. I want to generate a more general topic, of which other people could also benefit. I also have the two tableviews. I also want to disable a…
bashoogzaad
  • 4,611
  • 8
  • 40
  • 65
0
votes
0 answers

Error when attempting to remove elements from an observable mapped by EasyBind.map()

The following code gives me trouble when I click on one of the generated checkboxes: public class Controller implements Initializable { ObservableList strings = FXCollections.observableArrayList("a", "b", "c"); @FXML public HBox…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
0
votes
1 answer

TreeTableView selection contains null values after source change

A list of basic values is filtered by a (changing) predicate. The FilteredList is mapped to TreeItems and this resulting list is then used as the root TreeItems children. When a selection was made on the TreeTableView and afterwards the predicate…
JD3
  • 33
  • 1
  • 7
0
votes
1 answer

Simple syntax for treating a instance method as a function

In Java, we can do something like this: ObservableStringValue str = ...; Binding strLen = EasyBind.map(str, String::length); Where String::length effectively is an instance method being used as a function. Is there an equivalent form in…
Benedict Lee
  • 714
  • 8
  • 21
0
votes
1 answer

Using EasyBind with subclass of NumberProperty

Before introducing EasyBind - DoubleBinding contentHeight = Bindings.createDoubleBinding( () -> getHeight() - getInsets().getTop() - getInsets().getBottom(), heightProperty(), insetsProperty()); After introducing EasyBind - Binding
Venusaur
  • 191
  • 12
0
votes
1 answer

Binding two ObservableLists of different Objects. (Without EasyBind)

ObservableList src = FXCollections.observableArrayList(); ObservableList other = FXCollections.observableArrayList(); //Create binding. src.addAll("1", "2", "3"); System.out.println(other);//Should print [1, 2, 3]. Above I have an…
Toni_Entranced
  • 969
  • 2
  • 12
  • 29
-1
votes
1 answer

How to download easyBI report in PDF format?

I am using this API to download PDF report of easyBI dashboard but I get this error only for PDF format but working fine with CSV and XLS. Please visit the eazyBI for Jira installation and setup documentation page and check setup instructions or see…