How can i implement "Undo" action in this example?

I have tried to look at description of undo framework here, but not understand how can i
use this for my purpose in this example...