Input fields that also get set from within the program [message #1836080] |
Sun, 20 December 2020 01:26 |
James Garrison Messages: 16 Registered: July 2009 |
Junior Member |
|
|
tl;dr
SWT fires modify events whenever a text widget's text is modified, whether the modification originated from a real user action or some other code invoking setText().
Is there any unified way in SWT to distinguish between real user actions and program actions other than just keeping boolean flags to suppress events at the right times?
Detail
I have a set of fields that represent a file name composed of various parts, including a date, a description and a sequence number, and a complete "composed" filename with all the parts correctly arranged.
An input file name is parsed into its components and the fields are initialized. The "composed" filename is reconstructed from the parts. Note that the parser accepts a looser syntax than the standard but the composed filename strictly adheres to the standard.
When the user modifies one of the components, the "composed" filename gets updated in real time (keystroke by keystroke). Also, the user can type directly into the composed filename. If the data entered is in valid format, the other fields are updated to match, but a non-standard format filename can be entered if the need arises.
What I'm finding is that any call to textWidget.setText() fires a modify event for the modified field. Given the fields' interdependence, I have to add code to all the modify listeners to discard some events or I get into infinite recursion.
For example, if the user modifies the composed filename and the input is validly formatted, I update the other fields. But that causes modify events on those fields, which causes an attempt to modify the composed field, which modifies the other fields, etc.
|
|
|
Powered by
FUDForum. Page generated in 0.04173 seconds