Revert (Undo) implementation in GWT
Asked Answered
S

1

3

We are trying to build a GUI framework using GWT. We are finding it hard to implement the cancel functionality in the framework.

Required feature is this:

We have CRUD screens which have pop-ups, grids and so on. When the user changes anything in the GUI and then clicks on cancel() he should be given a notification message saying that something has changed.

Approach that we have tried:

Currently we are trying to keep a hashmap of key vs value of the entire pojo object and trying to compare it against the model which gets updated as and when user changes something. But this is adding lot of unwanted code in every pojo and not working as expected when user adds data directly from the backend.

Is there any elegant way in achieving this functionality? Kindly note that *we are not using Editor framework of GWT *(https://developers.google.com/web-toolkit/doc/latest/DevGuideUiEditors) in our application.

Example: Suppose I have a pojo like this:

public class Person {

    List<Address> address;
    PhoneNumber phoneData;


    // and so on along with getters and setters

}

How will I write a generic clone method for this? And even if I manage to do that somehow that will lead to lot of code in every pojo (our application has hundreds of them) which doesn't seem right.

Please note that, our pojo gets updated as soon as something is changed in GUI to achieve live binding.

Sheila answered 9/1, 2013 at 10:49 Comment(3)
Maybe take a snapshot of the POJO before editing (clone()) and then later compare the edited POJO with the snapshot (equals()) ?Uncrowned
??? where is the problem? You should not change the data until the user confirms the changes with "ok". When the user decides to click "cancel", just close the dialog and refer to the previous.Tenstrike
You're going to have to take a snapshot somehow, and I think Thomas is on the right track. Otherwise you'll have to record every edit the user makes and know how to revert it, which sounds like way more work with way more edge cases.Alvar
W
0

So you have "Save" and "Cancel" buttons in your form?

I would recommend you to change the concept. Update your object properties immediately as user edit them (as in GMail, JIRA and many other modern applications) in an OnChange event handler.

Save all updates to the session stack as UpdateAction objects and let the user undo every single property modification calling UpdateAction.undo() method.

The benefits are:

  1. this design is much more user friendly than "Click "Edit" - update - click "Save"" scenario.

  2. You don't need separate view/edit forms/popup dialogs - just a single form for both viewing and editing.

Wurtz answered 9/1, 2013 at 15:3 Comment(4)
Thanks for your answer. Our application is already updating the model immediately on any change in the gui. I did not completely understand the update action object you spoke about. We are trying to write a framework which should support any kind of model revert action. We have only one form for both view and edit. But popups are present in them for complex configurationsSheila
If you update your database immediately then you don't need the "Cancel" button. What is it for?Wurtz
I suggest you to update database immediately. Then you won't need the "Cancel" button at all.Wurtz
Am sorry but I need cancel button.its a big form with lot of fields and we cannot update database everytimeSheila

© 2022 - 2024 — McMap. All rights reserved.