Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Prevent Listeners From Firing/Observer Pattern

Thread view: 
Jason Cavett - 20 Jun 2007 17:15 GMT
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).
Hendrik Maryns - 20 Jun 2007 17:54 GMT
Jason Cavett schreef:
> 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
[quoted text clipped - 22 lines]
> heavily used pattern.  However, I can't find any information on it
> (and I can't find my GoF book either).

It seems like the easier solution is to build in a test in the view or
the listener which checks whether such an object is already in the stack
and don’t enter an equivalent one if there is.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.