J
Jason Cavett
I've implemented the Observer pattern in the GUI that I'm writing so
that any property view to a data object will be updated if that
underlying data object is updated. The problem I am having is
described in this scenario...
1. Open two diff. views to a data object.
2. Updated nameField in view1
3. This updates the data object.
4. Data object notifies its observers that it has been updated.
5. Observers (the views) get the data from the name field and update
themselves.
This is where the problem occurs - when view2 updates itself, it fires
off its listeners (in this case, a DocumentListener and an
UndoableListener). As a result, the action takes place that those
listeners specify. So, in the case of the UndoableListener (which I
don't have any control over - it's built into Java), the field is
updated and it counts as an "edit" so that it is placed on the undo
stack. This, in essence, means that if I have more than one view
open, I get multiple items on the stack for one specific edit.
My question is this - is there any way to prevent listeners from
firing while performing an update? This seems like it's a problem
that should have been solved already because Observer is a pretty
heavily used pattern. However, I can't find any information on it
(and I can't find my GoF book either).
that any property view to a data object will be updated if that
underlying data object is updated. The problem I am having is
described in this scenario...
1. Open two diff. views to a data object.
2. Updated nameField in view1
3. This updates the data object.
4. Data object notifies its observers that it has been updated.
5. Observers (the views) get the data from the name field and update
themselves.
This is where the problem occurs - when view2 updates itself, it fires
off its listeners (in this case, a DocumentListener and an
UndoableListener). As a result, the action takes place that those
listeners specify. So, in the case of the UndoableListener (which I
don't have any control over - it's built into Java), the field is
updated and it counts as an "edit" so that it is placed on the undo
stack. This, in essence, means that if I have more than one view
open, I get multiple items on the stack for one specific edit.
My question is this - is there any way to prevent listeners from
firing while performing an update? This seems like it's a problem
that should have been solved already because Observer is a pretty
heavily used pattern. However, I can't find any information on it
(and I can't find my GoF book either).