Coder Social home page Coder Social logo

easybind's People

Contributors

almibe avatar randers00 avatar tomasmikula avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easybind's Issues

Active?

There's a few outstanding PRs. Is the library safe to use or should we be looking for an active fork? Is there an active fork?

Mapping an ObserveableMap

I have an ObserveableMap<K, V>, from which I would like to create an ObserveableList<K> or ObserveableList<V>

Am I correct that this is not currently possible with EasyBind API? Would be great to have this if it isn't currently supported.

thanks for the cool library! I am using it in this app.
👍

Would it make senese for FlatMapProperty to provide orElse(...) implementations?

Hi,

If there's a better place to post inquiries like this, please let me know. Would it make sense for FlatMapProperty to have orElse(...) implementations that return Property<?> types? Consider the following usage of EasyBind:

private final ObjectProperty<SomeModel> model = new SimpleObjectProperty<>();

private BooleanProperty disabled;
private Property<Boolean> modelDisabled;

{
    disabled = new SimpleBooleanProperty();
    modelDisabled = EasyBind.monadic(model).selectProperty(SomeModel::disabledProperty);
    disabled.bindBidirectional(modelDisabled);
}

Assuming the above is a reasonable thing to do, I'd like to handle the null cases more explicitly. For example:

private final ObjectProperty<SomeModel> model = new SimpleObjectProperty<>();

private BooleanProperty disabled;
private Property<Boolean> modelDisabled;

{
    disabled = new SimpleBooleanProperty();
    modelDisabled = EasyBind.monadic(model).selectProperty(SomeModel::disabledProperty).orElse(false);
    disabled.bindBidirectional(modelDisabled);
}

Basically I'm trying to do bidirectional select bindings.

I'm also curious with regards to how a swap of SomeModel would be handled in my first example. I assume it would be treated as a change in the selected property, so the disabled property would be updated from modelDisabled. Is that correct?

map function for Double property

Currently, if I want to map DoubleProperty to String, I cannot use map function directly like:

Easybind.map(someDoubleProperty, someMapperFromDoubleToString)

because DoubleProperty only implements ObservableValue<Number>, not ObservableValue<Double> and thus the second argument should be Function<Number, U>. I think it would be better the method is overloaded for arguments (ObservableDoubleValue, DoubleFunction), (ObservableIntValue, IntFunction) and so on.

It seems that this repository is not maintained these days. Since this is really splendid project, I hope that it will be continued developing...

Javadoc Broken

The links to the javadocs in the Readme don't work—it seems that fxmisc.org has disappeared. Can you consider hosting the javadocs somewhere else, like Github Pages?

Strange Behaviour with EasyBind.map

Hello

Thanks a lot for sharing this code. It's been realy helpful in lot of situations!

I am experiencing some strange behaviour with 'EasyBind.map'. My goal is to derive a list of conditions (Strings) from a collection of buisiness objects, that will be passed to the application server on a search request.

Basically, what I am doing is this:

ObservableList<MyDataObject> selectedItems = checkComboBox.getCheckModel().getCheckedItems();
ObservableList<String> conditions = EasyBind.map(selectedItems, p -> p.getCondition());
sendRequestToServer(conditions);

What I am seeing is that 'conditions' is always emtpy because 'conditions' will not be updated although the 'selectedItems' change.

The following code has a dependency on ControlsFX (8.20.7). If you run it like this and check the first entry in the combo box, only the 'ListChangeListener' on 'selectedItems' will fire, but not the one on the 'MappedList'.

Now please uncomment the two lines 74 and 75:

ListView<String> selectedView = new ListView<String>(lastNames);
box.getChildren().add(selectedView);

and run the program again. Now, if an item is checked, the selection will be displayed in the new list and both 'ListChangeListener' instances are called!

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.StringConverter;

import org.controlsfx.control.CheckComboBox;
import org.fxmisc.easybind.EasyBind;

public class MapTest extends Application {
    public static void main(String[] args) { 
        launch(args); 
    } 

    private ObservableList<MapTestPerson> people = FXCollections.observableArrayList();

    @Override
    public void start(Stage primaryStage) throws Exception {
        initPeople();
        primaryStage.setScene(new Scene(createContent(primaryStage), 420, 200));
        primaryStage.show(); 
    }

    private void initPeople() {
        people.add(new MapTestPerson("Alfonso", "Cuarón"));
        people.add(new MapTestPerson("Ang", "Lee"));
        people.add(new MapTestPerson("Michel", "Hazanavicius"));
        people.add(new MapTestPerson("Tom", "Hooper"));
    }

    private Parent createContent(Stage primaryStage) {
        BorderPane pane = new BorderPane();
        pane.setPadding(new Insets(12));
        VBox box = new VBox(6);
        pane.setCenter(box);

        CheckComboBox<MapTestPerson> view = new CheckComboBox<MapTestPerson>(people);
        view.setConverter(new StringConverter<MapTestPerson>() {
            @Override
            public String toString(MapTestPerson object) {
                return object.getFirstName() + " " + object.getLastName();
            }
            @Override
            public MapTestPerson fromString(String string) {
                return null;
            }
        });
        box.getChildren().add(view);

        final ObservableList<MapTestPerson> selectedItems = view.getCheckModel().getCheckedItems();
        selectedItems.addListener((ListChangeListener<MapTestPerson>)change -> {
            while (change.next()) {
                System.out.println("selectedItems change: " + change);
            }
        });

        ObservableList<String> lastNames = EasyBind.map(selectedItems, p -> p.getLastName());
        lastNames.addListener((ListChangeListener<String>)change -> {
            while (change.next()) {
                System.out.println("lastNames change: " + change);
            }
        });

//      ListView<String> selectedView = new ListView<String>(lastNames);
//      box.getChildren().add(selectedView);

        return pane;
    }
}

class MapTestPerson {
    private StringProperty firstName = new SimpleStringProperty();
    private StringProperty lastName = new SimpleStringProperty();

    public MapTestPerson(String first, String last) {
        firstName.set(first);
        lastName.set(last);
    }

    @Override
    public String toString() {
        return firstName + " " + lastName;
    }

    public final StringProperty firstNameProperty() {
        return this.firstName;
    }

    public final String getFirstName() {
        return this.firstNameProperty().get();
    }

    public final void setFirstName(final String firstName) {
        this.firstNameProperty().set(firstName);
    }

    public final StringProperty lastNameProperty() {
        return this.lastName;
    }

    public final String getLastName() {
        return this.lastNameProperty().get();
    }

    public final void setLastName(final String lastName) {
        this.lastNameProperty().set(lastName);
    }
}

map and listBind and weak references

I want to bind an ObservableList<T> to and `ObservableList.

I wrote a mapping (map) from the first list to an intermediate one, then i use listBind between the intermediate and the target. The problem is that if i don't keep a strong reference on this intermediate list, it is garbaged and the binding is dispose.

I wrote this simple test that fails:

public class ListMapTest {
    @Test
    public void test() throws InterruptedException {
        ObservableList<String> source = FXCollections.observableArrayList();
        source.addAll("1", "2", "8");

        ObservableList<Integer> intermediate = EasyBind.map(source, Integer::parseInt);

        ObservableList<Integer> target = FXCollections.observableArrayList();
        EasyBind.listBind(target, intermediate);

        assertEquals(Arrays.asList(1, 2, 8) , target);

        intermediate = null;
        System.gc();
        Thread.sleep(1000);

        source.addAll(2, Arrays.asList("3", "5"));
        assertEquals(Arrays.asList(1, 2, 3, 5, 8), target);

        source.remove(1, 3);
        assertEquals(Arrays.asList(1, 5, 8), target);
    }
}

Add bindTo method to bind to properties

Right now one has to write

target.targetProperty().bind(
                EasyBind.map(source.sourceProperty(), mapping)
        );

to bind to a property. A more fluent interface like

EasyBind.map(source.sourceProperty(), mapping)
        .bindTo(target.targetProperty);

would be nice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.