Class PropertyPublisher<T>
java.lang.Object
com.inductiveautomation.ignition.designer.mvvm.PropertyPublisher<T>
- All Implemented Interfaces:
Flow.Publisher<SubmissionContext<T>>
Represents a Property of value <T> that can be subscribed to using
Note: This class should only be used in a single threaded environment, specifically in the UI thread (in a non-testing context). It is not thread-safe.
There are 3 main methods that can be used to emit values to the subscribers:
PropertySubscriber
. Note: This class should only be used in a single threaded environment, specifically in the UI thread (in a non-testing context). It is not thread-safe.
There are 3 main methods that can be used to emit values to the subscribers:
submit(Object)
: emits a value of type TsubmitDistinct(Object)
: emits a value of type T only if the value is not the same as the last emission.
Used in UI to prevent a feedback loop in MVVM and to prevent needless emissions. As example of feedback prevention. Consider the following scenario:
For a JComboBox, theViewModel
sends a value to the JComboBox as the value that the JComboBox should select. This triggers a change in selection, and the JComboBox sends this selected value back to theViewModel
.submitDistinct(Object)
prevents an endless loop, as the value being the same value that theViewModel
has just emitted, it will not emit this same value again.submitInternal(SubmissionContext.State, String)
: emits the same value as the last emission with some meta data. The meta data is transmitted via theSubmissionContext
, and it's used to send information such as the state of data availability (it's currently being loaded, or it can't be loaded, as an example).
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPropertyPublisher
(T initialValue) This variant uses the defaults ofPropertyPublisher.Mode.UNSPECIFIED
.PropertyPublisher
(T initialValue, PropertyPublisher.Mode mode) -
Method Summary
Modifier and TypeMethodDescriptionvoid
readOnly()
void
resubmit()
Resubmit the last emission.void
int
boolean
submitDistinct
(T value) This variant will only submit a value to aPropertyPublisher
if it differs from thelastEmission()
.boolean
submitDistinctWithPrompt
(T value, String promptText) This variant will only submit a value to aPropertyPublisher
if it differs from the last emission.int
submitInfo
(String infoMessage) protected int
submitInternal
(T value, SubmissionContext.State state, String stateText) void
submitLoading
(T t) void
submitPrompt
(String promptText) void
void
submitWarning
(String warnMessage) void
subscribe
(Flow.Subscriber<? super SubmissionContext<T>> subscriber) void
If there is an existing stash, this stash will then be submitted if it's distinct, and then the stash will be cleared.void
-
Constructor Details
-
PropertyPublisher
This variant uses the defaults ofPropertyPublisher.Mode.UNSPECIFIED
. -
PropertyPublisher
- Parameters:
initialValue
- InPropertyPublisher.Mode.UNSPECIFIED
, if the initialValue is null, then thePropertyPublisher.Mode
will be set toPropertyPublisher.Mode.ALLOW_NULL
, otherwisePropertyPublisher.Mode.NO_NULLS
.mode
- There are only 2 active states:PropertyPublisher.Mode.NO_NULLS
andPropertyPublisher.Mode.ALLOW_NULL
. ThePropertyPublisher.Mode.UNSPECIFIED
will use theinitialValue
to determine which of the 2 active states to set. SeeinitialValue
for details on this.
-
-
Method Details
-
submit
-
stashExisting
public void stashExisting() -
unstashExisting
public void unstashExisting() -
unstashDistinct
public void unstashDistinct()If there is an existing stash, this stash will then be submitted if it's distinct, and then the stash will be cleared. This will submit the value that was stashed and not theSubmissionContext
that was stashed. -
clearStash
public void clearStash() -
submitDistinct
This variant will only submit a value to aPropertyPublisher
if it differs from thelastEmission()
. If you need to find out if thevalue
was submitted, you can use the return value to perform this check.- Returns:
- true if
value
was submitted, otherwise false
-
submitDistinctWithPrompt
This variant will only submit a value to aPropertyPublisher
if it differs from the last emission. Will set a prompt text regardless of whether the submitted value is distinct.- Parameters:
value
- The value to submitpromptText
- The prompt text to display- Returns:
- true if
value
was submitted (distinct), otherwise false
-
resubmit
public void resubmit()Resubmit the last emission. A use case for this:
In a ComboBox, when its data is updated, selection is set to null. The selection has to be re-established. This class will resubmit the selection again, in order to re-established the lost selection caused by the updates the ComboBox's data. -
submitWarning
-
submitInfo
-
submitLoading
-
submitReset
public void submitReset() -
submitPrompt
-
submitInternal
-
subscribe
- Specified by:
subscribe
in interfaceFlow.Publisher<T>
-
lastEmission
-
readOnly
-