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, theViewModelsends 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 theViewModelhas 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 TypeMethodDescriptionvoidreadOnly()voidresubmit()Resubmit the last emission.voidintbooleansubmitDistinct(T value) This variant will only submit a value to aPropertyPublisherif it differs from thelastEmission().booleansubmitDistinctWithPrompt(T value, String promptText) This variant will only submit a value to aPropertyPublisherif it differs from the last emission.intsubmitInfo(String infoMessage) protected intsubmitInternal(T value, SubmissionContext.State state, String stateText) voidsubmitLoading(T t) voidsubmitPrompt(String promptText) voidvoidsubmitWarning(String warnMessage) voidsubscribe(Flow.Subscriber<? super SubmissionContext<T>> subscriber) voidIf 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.Modewill be set toPropertyPublisher.Mode.ALLOW_NULL, otherwisePropertyPublisher.Mode.NO_NULLS.mode- There are only 2 active states:PropertyPublisher.Mode.NO_NULLSandPropertyPublisher.Mode.ALLOW_NULL. ThePropertyPublisher.Mode.UNSPECIFIEDwill use theinitialValueto determine which of the 2 active states to set. SeeinitialValuefor 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 theSubmissionContextthat was stashed. -
clearStash
public void clearStash() -
submitDistinct
This variant will only submit a value to aPropertyPublisherif it differs from thelastEmission(). If you need to find out if thevaluewas submitted, you can use the return value to perform this check.- Returns:
- true if
valuewas submitted, otherwise false
-
submitDistinctWithPrompt
This variant will only submit a value to aPropertyPublisherif 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
valuewas 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:
subscribein interfaceFlow.Publisher<T>
-
lastEmission
-
readOnly
-