Class EditorHelper


  • public class EditorHelper
    extends java.lang.Object
    Encapsulates some logic useful in the editors to facilitate correct editing and listening of/to a node's value and prevent notification looping
    • Constructor Summary

      Constructors 
      Constructor Description
      EditorHelper​(DocumentNode node, java.util.function.Consumer<java.lang.Object> updateUiFromNodeValue)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      Removes node listeners
      boolean isUpdatingUi()
      Can be checked to prevent UI listeners from updating the node's value.
      java.awt.event.ItemListener newItemListener​(java.util.function.Consumer<java.lang.Boolean> realListener)
      Convenience function that makes an ItemListener that will automatically ignore events while the updatingUi flag is set.
      void setValue​(java.lang.Object value)
      Sets the value in such a way that the resulting value change event won't re-trigger the ui to update.
      void updateUi​(java.lang.Runnable r)
      Any code that updates the UI should be put through here, that way the updating flag can be set and then used to prevent other ui listeners from firing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EditorHelper

        public EditorHelper​(DocumentNode node,
                            java.util.function.Consumer<java.lang.Object> updateUiFromNodeValue)
        Parameters:
        updateUiFromNodeValue - Called when the node's value changes. Update the UI here. will automatically be called inside the updateUI wrapper.
    • Method Detail

      • destroy

        public void destroy()
        Removes node listeners
      • newItemListener

        public java.awt.event.ItemListener newItemListener​(java.util.function.Consumer<java.lang.Boolean> realListener)
        Convenience function that makes an ItemListener that will automatically ignore events while the updatingUi flag is set.
      • isUpdatingUi

        public boolean isUpdatingUi()
        Can be checked to prevent UI listeners from updating the node's value.
      • setValue

        public void setValue​(java.lang.Object value)
        Sets the value in such a way that the resulting value change event won't re-trigger the ui to update.
      • updateUi

        public void updateUi​(java.lang.Runnable r)
        Any code that updates the UI should be put through here, that way the updating flag can be set and then used to prevent other ui listeners from firing.