All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.datafx.samples.app.DataModel Maven / Gradle / Ivy

There is a newer version: 8.0b5
Show newest version
package org.datafx.samples.app;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import org.datafx.controller.flow.injection.FlowScoped;

/**
 * The data model for the sample. The model is defined as flow scoped.
 * By doing so the model can be injected in any controller or action. For one flow the injected instance will always be the same.
 */
@FlowScoped
public class DataModel {

    private ListProperty persons;

    private IntegerProperty selectedPersonIndex;

    public ListProperty getPersons() {
        if (persons == null) {
            ObservableList innerList = FXCollections.observableArrayList();
            persons = new SimpleListProperty<>(innerList);
        }
        return persons;
    }

    public int getSelectedPersonIndex() {
        return selectedPersonIndexProperty().get();
    }

    public void setSelectedPersonIndex(int selectedPersonIndex) {
        this.selectedPersonIndex.set(selectedPersonIndex);
    }

    public IntegerProperty selectedPersonIndexProperty() {
        if (selectedPersonIndex == null) {
            selectedPersonIndex = new SimpleIntegerProperty();
        }
        return selectedPersonIndex;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy