undo/redo with the Command Pattern

177 views
Skip to first unread message

aliwa

unread,
Jun 15, 2011, 10:34:22 AM6/15/11
to GWT Dispatch
Hello,

I am looking for examples of "undo/redo using the Command pattern, I
did not find any example that helps explain the use of this pattern
for this case .

Suppose I have a text box, when the user changes the value of this
area and tap "Enter" an RPC is launched to the server to save the
change. I wanted to add a button "undo"so that when the user clicks
over the text area takes the previous value and an RPC is lunched to
update the value in the server and take into account the undo.

I also wanted to add a button "redo" for the opposite behavior.

Could you give me an idea about how to implement this behavior with
the Command Pattern?

Thank you in advance for your help

I use GWT 2.3 on Eclipse 3.6.

David Peterson

unread,
Jun 15, 2011, 10:39:25 PM6/15/11
to gwt-di...@googlegroups.com
Hi there,

I think the simplest way would be to create an 'Undo' object that contains both the Action and the Result, and put them into a stack when the result is returned from the server. If you want to undo something, send the top Result back to the server, and push the Undo object onto the onto the 'Redo' stack. If you want to redo it, just send the Action back to the server. Fairly straightforward.

As far as intercepting them goes, the simplest is probably to create a custom DispatchAsync implementation that caches the Actions/Results for you automatically. Perhaps providing some kind of marker to distinguish 'Undoable' actions. Probably an 'UndoableAction' and 'UndoableResult' superclass would be simplest, given GWT's restrictions with interfaces...

Regards,

David

ali thabet

unread,
Jun 16, 2011, 7:07:59 AM6/16/11
to gwt-di...@googlegroups.com
Thank you for your answer David, I'll try that.

2011/6/16 David Peterson <da...@randombits.org>
Reply all
Reply to author
Forward
0 new messages