How to manage Undo with multiple models linked together

Hello,
I'm writing a java desktop application using MVC model. I'm using javax.swing.undo.UndoManager and related classes to manage the undo/redo capabilities. I know how to use it but I can't see how to implement it in a clean way when I have several models linked together. I hope someone can help...
I have 2 models M1 and M2. M2 depends on M1, so M2 listens to M1 changes.
Each model has its own view V1 and V2.
Model's methods which change the model's state create an UndoableEdit to restore the previous model's state.
UndoableEdits are combined together in a CompoundEdit created by the controller.
Upon a user action on V1:
1. M1 change
=> add UndoableEdit to current CompoundEdit
=> notify V1
=> notify M2
2. M2 change
=> add UndoableEdit to current CompoundEdit
=> notify V2
When we undo the CompoundEdit:
1. Undo M2 change
=> notify V2
2. Undo M1 change
=> notify V1
=> notify M2 !! PROBLEM
3. M2 change !! PROBLEM
=> notify V2 !! PROBLEM
And this is my problem: when undoing change on M1, I need to notify listeners (V1 and M2), but in this case M2 should not be notified because M2 has already restored its previous state in the CompoundEdit undo chain.
A solution might be to inhibit M2 listener if we're inside a undo/redo, but I feel it's not clean and not sure it will always work... Is there another way to solve this ? Or is it my architecture which is wrong ?
Thank you.
Edited by: gibi_31 on Aug 19, 2010 3:08 AM
Edited by: gibi_31 on Aug 19, 2010 3:11 AM

Hello,
Upon a user action on V1:
1. M1 change
=> add UndoableEdit to current CompoundEdit
=> notify V1
=> notify M2
2. M2 change
=> add UndoableEdit to current CompoundEditWhy?
Do you need to be able to undo the M2 change alone in any other case than undoing M1's change?
And if you don't add M2 change to the compound edit, doesn't the M2 update triggered by undoing the the M1 undo the M2 state automatically (thus performing the M2 undo)?
And this is my problem: when undoing change on M1, I need to notify listeners (V1 and M2), but in this case M2 should not be notified because M2 has already restored its previous state in the CompoundEdit undo chain.
A solution might be to inhibit M2 listener if we're inside a undo/redo, but I feel it's not clean and not sure it will always work...I agree it looks unclean (and quite dangerous actually if the app ever needs to support some form of multi-threaded model changes).
Regards,
J.

Similar Messages

  • How to manage playlists with multiple devices?

    We have multiple devices in our household that use the same Macbook Pro.  We all like different kinds of music and we are now having a difficult time trying to manage the playlists on the different devices.  How do we manually manage playlists for each separate device?  We have iPhones, iPads and iPods.

    How to use multiple iPods, iPads, or iPhones with one computer
    http://support.apple.com/kb/HT1495
    How to Share a Family iPad
    http://www.macworld.com/article/1163347/how_to_share_a_family_ipad.html
    Using iPhone, iPad, or iPod with multiple computers
    http://support.apple.com/kb/ht1202
    iOS & iCloud Tips: Sharing an Apple ID With Your Family
    http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/
    How To Best Use and Share Apple IDs across iPhones, iPads and iPods
    http://www.nerdsonsite.com/blog/2012/06/07/help-im-appleid-confused/
     Cheers, Tom

  • How do i deal with multiple iPhoto libraries when migrating to Photos

    how do i deal with multiple iPhoto libraries when migrating to Photos

    I would merge them before the migration.  Also, spend some time doing any batch changes of names and dates beforehand too.
    iPhoto Library Manager has good merge and duplicate search facilities.
    http://www.fatcatsoftware.com/iplm/

  • How Transaction Manager work with Resource Manager, like Connection pool?

    hi,
    I'm using BEA Webloigc8.1 Stateless Session Bean/DAO/Oracle stored proc.
    but I'm not quite clear how Transaction Manager work with Resource Manager, like Connection pool.
    my understanding is that, in a weblogic transaction, a stateless session bean interact with several DAOs, and for each method of DAO a connection is acquired from connection pool. I've heard that the connection will not return to pool until the transaction commits.
    My question is that, does it mean that for a weblogic transaction, multiple connections might be allocated to it? and if multiple connections are allocated, then how many oracle transactions would be started? or multiple connections share the same oracle transaction?
    I didn't feel it make sense to start multiple oracle transactions, cause deadlock might be incurred in a single weblogic transaction.
    any help appreciated!

    Xin Zhuang wrote:
    hi,
    I'm using BEA Webloigc8.1 Stateless Session Bean/DAO/Oracle stored proc.
    but I'm not quite clear how Transaction Manager work with Resource Manager, like Connection pool.
    my understanding is that, in a weblogic transaction, a stateless session bean interact with several DAOs, and for each method of DAO a connection is acquired from connection pool. I've heard that the connection will not return to pool until the transaction commits.
    My question is that, does it mean that for a weblogic transaction, multiple connections might be allocated to it? and if multiple connections are allocated, then how many oracle transactions would be started? or multiple connections share the same oracle transaction?
    I didn't feel it make sense to start multiple oracle transactions, cause deadlock might be incurred in a single weblogic transaction.
    any help appreciated!Hi. If you configure your WLS DataSource to use keep a connection for
    the duration of a tx, it will do that, and in any case there can be
    no deadlock however many connections operate for a given XA transaction.
    Here is the best coding form for DAOs or any other user-written code
    for using WebLogic DataSources. This is important for two reasons:
    1 - Thread-safety is maintained as long as the connection is a
    method-level object.
    2 - It is crucial to notify WebLogic that you are done with a connection
    ASAP, by your calling close() on it. We will then put it back in the
    pool, or keep it under the covers for your next request if it's in a
    transaction etc. The pool is optimized for quick get-use-close scenarios.
    public void one_of_my_main_JDBC_Methods()
    Connection con=null; // Must be a method level object for thread-safety
    // It will be closed by the end of the method.
    try {
    con = myDataSource.getConnection(); // Get the connection in the try
    // block, directly from the WebLogic
    // datasource
    // do all the JDBC within this try block. You can pass the
    // connection to subordinate methods, but not to anywhere
    // that thinks it can use the connection later.
    rs.close(); // close any result set asap
    stmt.close(); // then close any statement asap
    // When you're done with JDBC
    con.close(); // close the connection asap
    con = null; // nullify it so the finally knows it's done
    catch (Exception e) {
    // do whatever catch stuff you want. You don't
    // need a catch block if you don't want one...
    finally {
    // It is important to close a JDBC connection ASAP when it's not needed.
    // without fail, and regardless of exit path. Do everything in your
    // finally block in it's own try-catch-ignore so everything is done.
    try { if (con != null) con.close();} catch (Exception ignore){}
    return ret;
    }

  • ORACLE EXPRESS: build a page with multiple forms linked to one table

    hi,
    im using oravle application express. APEX
    i would like to build a page with multiple forms linked to one table (orders) , the page has 4 from  each one with different order_id number (depending on filtering),  and if the order is prepared click yes for each order and this 'YES' should be UPDATED AND SAVED to each order number in the same table with the press of one button.
    i created all the form as (sql query)
    and create one update process
    (UPDATE ORDERS
    SET TRAY_PREPARED =:P10_TRAY_PREPARED_1
    WHERE ORDER_ID =:P10_ORDER_ID_1;
    UPDATE ORDERS
    SET TRAY_PREPARED =:P10_TRAY_PREPARED_2
    WHERE ORDER_ID =:P10_ORDER_ID_2;
    UPDATE ORDERS
    SET TRAY_PREPARED =:P10_TRAY_PREPARED_3
    WHERE ORDER_ID =:P10_ORDER_ID_3;
    UPDATE ORDERS
    SET TRAY_PREPARED =:P10_TRAY_PREPARED_4
    WHERE ORDER_ID =:P10_ORDER_ID_4;
    i dont know really if i can do that, but it appear hat it actually saving according to order_id number , but not all the time some time it saved the value as "null".
    please guide me what is the correct way to do this.
    I READ THIS ONE
    http://stackoverflow.com/questions/7877396/apex-creating-a-page-with-multiple-forms-linked-to-multiple-related-tables
    BUT IT WAS FOR MULTIPLE INSERT
    thanks.

    Sans,
    I am no Apex expert, but with a situation as "complex" as yours, have you thought about creating a VIEW that joins these 7/8 tables, placing an INSTEAD OF trigger on that view to do all the business logic in the database, and base your application on the view?
    This is the "thick-database" approach that has been gaining momentum of late. The idea is to put your business logic in the database wherever possible, and let the application (Form, Apex, J2EE, whatever) concentrate on UI issues,

  • How to create parameter with multiple selection in a query (SQ02) ?

    Hi Exports
    Do you know how to create parameter with multiple selection in a query (transaction SQ02)?
    thanks.

    Hi
    i know how to create user parameter at SQ02,
    the question is how to create multiple selection parameter?

  • How can build BMM with multiple fact tables

    HI Gurus,
    I have 4 fact tables and 18 Dimension table. Dimension tables have links with multiple fact tables. i have created physical joins in Physical layer. Now my questions is how can i create Business Model with multiple fact tables.
    i mean should i create 4 fact tables as logical tables and logical keys ? Then i have to move all dimension tables in to Business model?
    i am new to OBIEE. i gone through tutorial it is showing with one fact and multi dimension table. Should i do follow same style with multi fact tables.
    Please help me. Thanks in advance for your support.

    Thanks for your response.
    I had drag all tables from the phisical layer to Business Model. then i have deleted all links and recreated complex joins with default values.
    now i have some revenue amont columns in fact tables.
    my question is should i should i create aggregation ( like Sum..) for those columns? is it must ?
    please let me know thank you very much

  • How to share account with multiple devices?

    3 kids with 3 devices - an iPod Touch and two iPads Mini - family shares one account with Apple/iTunes and one library on our family PC.  They use FACETIME and MESSAGES with their friends, and they all see each others messages and conversations.  How do I fix this?  Is there a setting or a way to create sub-accounts off the family account so they can still share the main library for music and video OR do I have to create separate Apple/iTunes accounts for each kid?  Is there a setting on their devices that can help?  Any help is greatly appreciated.  I'm not even sure the right question to ask...

    How to use multiple iPods, iPads, or iPhones with one computer
    http://support.apple.com/kb/HT1495
    How to Share a Family iPad
    http://www.macworld.com/article/1163347/how_to_share_a_family_ipad.html
    Using iPhone, iPad, or iPod with multiple computers
    http://support.apple.com/kb/ht1202
    iOS & iCloud Tips: Sharing an Apple ID With Your Family
    http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/
    How To Best Use and Share Apple IDs across iPhones, iPads and iPods
    http://www.nerdsonsite.com/blog/2012/06/07/help-im-appleid-confused/
     Cheers, Tom

  • ABCS with multiple partner link invocation through artifact generator

    hi,
    I have requirement to generate ABCS through Artifact generator and this ABCS would be invoking multiple web services with different ABMs.
    How can we specify this in the input.xml of artifact generator to auto generate a code with multiple external web service invocations?

    You should be able to populate the Target multiple times. Could you please give it a try and post the metadata input file if the issue still persists.
    Regards
    Rohit

  • Manage clients with multiple workgroups

    In our business, everyone belongs to a departamental group, e.g. "Staff Accounts", "Staff Drafting", etc. Each of these groups belongs to a workgroup called "Access Company" that is a managed group that creates non-syncing mobile accounts and manages some other preferences upon login.
    There are some additional preferences we'd like to manage for select groups, but not the whole company.
    E.g. we wish to have some users use network accounts if they move from desk to desk, but not all users. We've set up a "NetworkUsers" workgroup for this, problem is, for correct access to file server volumes, etc. they also need to belong to "Access Company" group. When they log in, they are prompted which one of the two workgroups they would like to join. We don't exactly want to educate these users to select "NetworkUsers" each time. Is there a way instead to have a certain workgroup take priority over another? Or better, is it possible for different workgroups managed preferences to be combined, which would be even better, that way we don't have to copy all the managed preferences from "Access Company" group over to "NetworkUsers" each time we wish to make change to the managed preferences.
    Also, in combination with the "Access Company" workgroup, we wish to manage printers, however, we don't want to add all the same printers to the "Access Company" group because some of our users are at remote sites so don't want irrelevant printers showing up in their list. When we add somebody to a "Print something" workgroup, they will also be part of "Access Company" workgroup. Once again, ideally, we'd like to have the managed preferences combined, if not possible, we can add all the managed preferences from "Access Company" group to "Print something" group and have that single workgroup managing their preferences, but this takes time and when we wish to make a change to managed preference for the whole company, we'll have to update that change in each one of the workgroups in use, so combining managed preferences is definitely desired, otherwise, if really not possible, we could manage with only one workgroup per user, but once again, we're at the problem of them having to belong to the "Access Company" workgroup for file server permission, etc. and we don't want the box to pop up asking them which workgroup they want to join.
    Any ideas to get around this problem?
    If it's just a limitation of Mac OS X server 10.5, it's a pretty **** big basic lacking feature, and if so, is it better in 10.6 in which case it'll be worth upgrading.

    Solved my problem the proper way!!
    I read again that combining managed preferences from multiple workgroups is possible on page 6 of this document:
    http://images.apple.com/server/macosx/docs/L355774BWkgrpMgrTB.pdf
    My tests showed differently, but I eventually figured out why:
    Managed preferences will combine only between groups where one is a parent of the other. The child group's managed preferences overrides the parent group's managed preferences, but ONLY IF the parent group is an inherited group from the child group ONLY! (i.e. must be strictly hierarchical)
    i.e.
    If ChildGroup is a child of ParentGroup and the user is added to ChildGroup only, it will get the combined managed preferences of ChildGroup and ParentGroup.
    If the user is explicitly added to both ChildGroup and ParentGroup (instead of ParentGroup being inherited only), the preferences will NOT combine.
    If ThirdGroup is also a child of ParentGroup and the user is added to ThirdGroup and ChildGroup, then the preferences also will NOT combine - i.e. the parent group it wants to be combined with must be inherited through one group only. If ParentGroup is inherited from ThirdGroup, but also inherited from ChildGroup, no combining of managed preferences will take place.
    My solution was to keep my "Access Company" group only as a non-workgroup for file access and create a new workgroup with company-wide managed preferences to which each departmental group belongs to.
    Hope this helps someone who experiences the same problem!

  • How can a family with multiple existing accounts use Home Sharing?

    I'd like to use the new Home Sharing feature, but it appears to be restricted to families in which all of the family members share a single user account.
    We already have separate accounts for each family member. Is there some way for us to use Home Sharing without abandoning most of our existing accounts, along with all of the purchases made by those accounts? I don't think anyone in this situation would be willing to do that.

    Eh. I am not too sure since I have not messed with it much but I do have a great deal of experience with multiple accounts. Each computer can be authorized for multiple accounts. As can iPods. iPods can sync songs/videos/apps from multiple accounts as long as the computer is authorized with them. What I have set up here, is I buy my stuff I want, my parents buy what they want and so do my brothers. When my bro gets something I want I just move it to my computer. That way all our accounts are separate, but if there is something I want I can get it. Also, since the music no longer has DRM, it won't matter. It will play on any computer. What you should see is if you can just do the shared library with multiple accounts. Then if you don't have videos or such, you can get apps or music. Hope this helps!

  • How to sync ical with multiple apple devices and android?

    Does anybody have use an android phone in addition to apple devices, and have you figured out how to sync ical with all? (I know there are other calendars that can be used by all, but it means a lot to my husband to stay with ical.)

    I tried Yahoo in the past but had trouble with duplicate entries. However, this was a while ago before Yahoo updated their site and this was with syncing to a Windows computer with Outlook in addition to a Mac so my results might not be typical. Yahoo's worth a shot, but my experience with Yahoo is why I use Google Calendar.
    Beyond that, I don't know of any other "free" services. There are many other hosted calendar sites that could work, but you'd pay something like $5-$20 per month, which is comparable to MobileMe.

  • How to manage photos from multiple accounts

    Hi,
    i am trying to solve one problem. I have one iMAC where i have two user profiles connected to different AppleIDs. Next to it there are two iPhones and two iPads. I am trying to find out, how to manage photos from all these devices using one account on iMAC. Second question is if there is any finction in iPhoto that can publish images to NAS server? Second alternative for me is to byu iCloud drive space and use Family sharing for publishing photos. Bellow text schema is attached, it is only my idea and i dont know if this could work like this. Did anyone somehow solved this configuration? Thanks

    I can see the screenshot if I double click on it.  However, here is it again.  Being Halloween maybe it'll show.

  • How do I sync with multiple systems with my Iphone 3GS?

       How do I sync with my new IMac with out losing my data that I have already syced with my old PC?

    Launch iTunes on the new Mac.
    From the iTunes menu bar click Store / Authorize This Computer.
    Sync the iPhone.

  • How do i videochat with multiple people when using my aim account in messages?

    i am on messages and looking at my buddy list but it only shows that i can singular video chat, not with multiple people.

    in the general tab of your messages preferences is it set to AIM or Messages?

Maybe you are looking for