Class PropertyPublisher<T>

java.lang.Object
com.inductiveautomation.ignition.designer.mvvm.PropertyPublisher<T>
All Implemented Interfaces:
Flow.Publisher<SubmissionContext<T>>

public class PropertyPublisher<T> extends Object implements Flow.Publisher<SubmissionContext<T>>
Represents a Property of value <T> that can be subscribed to using 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:
  1. submit(Object): emits a value of type T
  2. submitDistinct(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, the ViewModel 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 the ViewModel. submitDistinct(Object) prevents an endless loop, as the value being the same value that the ViewModel has just emitted, it will not emit this same value again.
  3. submitInternal(SubmissionContext.State, String): emits the same value as the last emission with some meta data. The meta data is transmitted via the SubmissionContext, 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).
  • Constructor Details

  • Method Details

    • submit

      public int submit(T value)
    • 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 the SubmissionContext that was stashed.
    • clearStash

      public void clearStash()
    • submitDistinct

      public boolean submitDistinct(T value)
      This variant will only submit a value to a PropertyPublisher if it differs from the lastEmission(). If you need to find out if the value was submitted, you can use the return value to perform this check.
      Returns:
      true if value was submitted, otherwise false
    • submitDistinctWithPrompt

      public boolean submitDistinctWithPrompt(T value, String promptText)
      This variant will only submit a value to a PropertyPublisher 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 submit
      promptText - 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

      public void submitWarning(String warnMessage)
    • submitInfo

      public int submitInfo(String infoMessage)
    • submitLoading

      public void submitLoading(T t)
    • submitReset

      public void submitReset()
    • submitPrompt

      public void submitPrompt(String promptText)
    • submitInternal

      protected int submitInternal(T value, SubmissionContext.State state, String stateText)
    • subscribe

      public void subscribe(Flow.Subscriber<? super SubmissionContext<T>> subscriber)
      Specified by:
      subscribe in interface Flow.Publisher<T>
    • lastEmission

      public T lastEmission()
    • readOnly

      public PropertyPublisherReadOnly<T> readOnly()