assemblits / eru

The open JavaFX SCADA
GNU General Public License v3.0
14 stars 9 forks source link

Link Dynamos to Tags #31

Closed marl0rd closed 7 years ago

marl0rd commented 7 years ago

Eru is now has Scene Builder embedded... Now we have to find a way to link Dynamos Properties to tags.

marl0rd commented 7 years ago

Let's take the Dynamo: Display to tests...

marl0rd commented 7 years ago

Basically it has the following structure:

/* ********** Fields ********** */
    private ObjectProperty<Paint>               textFill;
    private StringProperty                      currentText;
    private ObjectProperty<DisplayFont>         valueFont;
    private BooleanProperty                     alarmed;
    private StringProperty                      title;
    private ObjectProperty<DisplayFont>         titleFont;
    private StringProperty                      unit;
    private ObjectProperty<DisplayFont>         unitFont;
    private BooleanProperty                     unitVisible;
    private BooleanProperty                     blinking;
    private IntegerProperty                     blinkingInterval;

    /* ********** Fields ********** */
    private volatile ScheduledFuture<?>         periodicBlinkTask;
    private static ScheduledExecutorService     periodicBlinkExecutorService;

    /* ********** Constructor ********** */
    public Display() {
        getStyleClass().add("display");
        textFill            = new SimpleObjectProperty<>(this, "textFill", DEFAULT_TEXT_FILL);
        currentText         = new SimpleStringProperty(this, "currentTex", "VALUE");
        valueFont           = new SimpleObjectProperty<>(this, "valueFont", DEFAULT_DISPLAY_FONT);
        alarmed             = new SimpleBooleanProperty(this, "alarmed", false);
        title               = new SimpleStringProperty(this, "title", "TITLE");
        titleFont           = new SimpleObjectProperty<>(this, "titleFont", DEFAULT_DISPLAY_FONT);
        unit                = new SimpleStringProperty(this, "unit", "Unit");
        unitFont            = new SimpleObjectProperty<>(this, "unitFont", DEFAULT_DISPLAY_FONT);
        unitVisible         = new SimpleBooleanProperty(this, "unitVisible", true);
        blinking            = new SimpleBooleanProperty(this, "blinking", false);
        blinkingInterval    = new SimpleIntegerProperty(this, "blinkingInterval", DEFAULT_BLINKING_INTERVAL);
    }

    /* ********** Properties Setters and Getters ********** */
    [....]
marl0rd commented 7 years ago

Let's focus on the currentText property:

private StringProperty currentText;

public String getCurrentText() {
    return currentText.get();
}
public StringProperty currentTextProperty() {
    return currentText;
}
public void setCurrentText(String currentText) {
    this.currentText.set(currentText);
}

When a property is added in this way, with the setter, getter and propertygetter, SceneBuilder detect it automatically.

marl0rd commented 7 years ago

scene builder display

marl0rd commented 7 years ago

Now, I am going to add a new property called: currentValueTagID . Notes: 1) This should not be done in the dynamo, the dynamo class should not be related to tags or other eru stuff. So we have to create a package in Eru to extend and add this properties... 2) This property name can change.

marl0rd commented 7 years ago
    /* ********** Fields ********** */
    [...]
    private StringProperty          currentValueTagID;
    private DoubleProperty          currentValue;
    [...]
    /* ********** Constructor ********** */
    public Display() {
        currentValueTagID   = new SimpleStringProperty(this, "currentValueTagID","");
        currentValue        = new SimpleDoubleProperty(this, "currentValue", 0.0);
        [...]
    }

    /* ********** Setters and Getters ********** */
    [...]

    public String getCurrentValueTagID() {
        return currentValueTagID.get();
    }
    public StringProperty currentValueTagIDProperty() {
        return currentValueTagID;
    }
    public void setCurrentValueTagID(String currentValueTagID) {
        this.currentValueTagID.set(currentValueTagID);
    }

    public double getCurrentValue() {
        return currentValue.get();
    }
    public DoubleProperty currentValueProperty() {
        return currentValue;
    }
    public void setCurrentValue(double currentValue) {
        this.currentValue.set(currentValue);
    }
marl0rd commented 7 years ago

Now Scene Builder help us to set the tag ID : display with tag id

And it is saved in the FXML, like the others properties....

marl0rd commented 7 years ago

Adding the ID (Tag table now shows the tag ID): tag table with id

So, adding the ID in Scene Builder: dynamo with tag id

Everything is setted...

marl0rd commented 7 years ago

So, I am going to: 1) Create a package in eru gui to have dynamos extended and to be analyzed by the CustomLibraryLoader. 2) Create dynamos there.