groovy
  1. groovy
  2. GROOVY-4962

SwingBuilder binding updates should happen inside the EDT if the target is an UI component

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.1, 1.9-beta-1
    • Fix Version/s: 1.8.2, 1.9-beta-3
    • Component/s: Swing
    • Labels:
      None
    • Number of attachments :
      0

      Activity

      Hide
      Andres Almiray added a comment -

      Here's an update on the current solution. Whenever a java.awt.Component (or subclass) is to be updated it will happen inside the EDT given the following rule:

      • if the current thread is the EDT then the update will happen immediately
      • else the update will happen the next time the EDT is free, that is, an event will be posted to the EventQueue using invokeLater()

      If the bean to be updated is not a java.awt.Component or subclass then the update will happen in the current thread, whichever it happen to be.

      The bind node accepts a new attribute named update, which controls the update strategy to use. Values are:

      • mixed: proceed if current thread = EDT; else post event with invokeLater. This is the default for java.awt.Component
      • async: post event with invokeLater always.
      • sync: proceed if current thread = EDT; else call invokeAndWait
      • outside: proceed if current thread != EDT; else submit to an ExecutorService (service is non-configurable)
      • same: proceed in the current thread. This is the default for non java.awt.Component beans
      • defer: submit to an ExecutorService (service is non-configurable)

      It's worth nothing that java.awt.Component beans will use mixed all the time, you can only change the update strategy for all other beans

      Sample usage:

      model = new Model() // bindable
      // model.text will be updated with SAME
      textField(text: bind(target: model, 'text'))
      // model.text will be updated with DEFER
      textField(text: bind(target: model, 'text', update: 'defer'))
      // model.text will be updated with OUTSIDE
      bean(model, text: bind(update: 'outside){ textFieldRef.text})
      
      Show
      Andres Almiray added a comment - Here's an update on the current solution. Whenever a java.awt.Component (or subclass) is to be updated it will happen inside the EDT given the following rule: if the current thread is the EDT then the update will happen immediately else the update will happen the next time the EDT is free, that is, an event will be posted to the EventQueue using invokeLater() If the bean to be updated is not a java.awt.Component or subclass then the update will happen in the current thread, whichever it happen to be. The bind node accepts a new attribute named update, which controls the update strategy to use. Values are: mixed: proceed if current thread = EDT; else post event with invokeLater. This is the default for java.awt.Component async: post event with invokeLater always. sync: proceed if current thread = EDT; else call invokeAndWait outside: proceed if current thread != EDT; else submit to an ExecutorService (service is non-configurable) same: proceed in the current thread. This is the default for non java.awt.Component beans defer: submit to an ExecutorService (service is non-configurable) It's worth nothing that java.awt.Component beans will use mixed all the time, you can only change the update strategy for all other beans Sample usage: model = new Model() // bindable // model.text will be updated with SAME textField(text: bind(target: model, 'text')) // model.text will be updated with DEFER textField(text: bind(target: model, 'text', update: 'defer')) // model.text will be updated with OUTSIDE bean(model, text: bind(update: 'outside){ textFieldRef.text})
      Hide
      Andres Almiray added a comment -

      Merged in a patch with the aforementioned spec.
      Leaving open for a few more days in order to gather feedback.

      Show
      Andres Almiray added a comment - Merged in a patch with the aforementioned spec. Leaving open for a few more days in order to gather feedback.
      Andres Almiray made changes -
      Field Original Value New Value
      Status Open [ 1 ] Resolved [ 5 ]
      Fix Version/s 1.9-beta-3 [ 17494 ]
      Fix Version/s 1.8.2 [ 17495 ]
      Resolution Fixed [ 1 ]
      Paul King made changes -
      Status Resolved [ 5 ] Closed [ 6 ]

        People

        • Assignee:
          Andres Almiray
          Reporter:
          Andres Almiray
        • Votes:
          1 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: