simonpena.com Una mezcla heterogénea de tecnología y desvaríos

11Apr/090

Undo, redo support using patterns

This Easter Week has been very productive. Although I didn't upload the screenshots as I said, I've made several interesting improvements.

  • The delete menu item changes according to the current user interface selection. If an account is selected, it displays delete account. If an user is selected, it displays delete user, and if an account operation is selected, it displays delete account operation.
  • It is possible to undo/redo the actions made. The major improvement I pointed out on the previous post is almost done, so you can reverse the addition, edition and deletion of users, accounts and account operations.

I've made a new hierarchy in the controller layer. I created the interface UIAction, with methods execute, undo, redo and getName. I created an abstract implementation, GenericAction, where I made final those methods -to avoid the concrete classes reimplementing them-, calling doExecute, doUndo, doRedo and doGetName (which currently doesn't make much sense), followed by a call to update (a private method which updates the information displayed on the main window).

The doWathever methods are protected and abstract, so the actions extending GenericAction must override them. This way, each action implements its own behavior for that methods, but at the same time complying with the generic behavior without the an explicit call to super. It follows the Template method pattern.

Besides, I made a CompositeAction class, following the Composite pattern, so several actions can be grouped into another.

This way, all the defined actions are commands, and the application itself has the responsibility of executing them. Whenever an action is executed, it is stored in an undoable actions stack, and its name is set in the edit menu, so you can read "Undo actionName". If you undo the action, the application takes it out from the stack, invokes its undo method, and adds it to the redoable actions stack. After that, its name will appear in the edit menu, displaying "Redo actionName". Again, if you redo the action, the application takes it out from that stack and invokes its redo method, adding it again to the undoable actions stack. And over and over again (as far as it is well implemented).

5Apr/090

Keep working hard

It's been a while since the last post, and some improvements have been made. I've added a context menu both to the navigation panel and the account operation table, and it is now possible to rename, edit and delete accounts, and edit and delete account operations. I've fixed the account operations table filters, so you can search within the comments and categories (or both) of the account operations. The field to be searched is selected in a search text box just like iTunes'.

The menu bar isn't completed yet: there are several operations which can't be accessed from there. But as the listeners and actions are made for the context menu, the work left is reduced to bind those actions to the main menu items.

The next major change involves re-factoring some of the actions, so the Command Pattern can be introduced: support for undo and redo should is the next target.

There's still another thing I have to put hours in: improving the application installation and configuration. Right now it involves downloading Maven, MySQL and JTA, and installing and configuring them. Several weeks ago I found H2 Database, and how easy it was to install and use it. I think it would be a lot easier for the final user to have his data in an embedded database, so the task left for me is to figure how to select the database placement, choose if that placement is a permanent one or can be changed even on runtime, and if it would even be possible to change between an embedded database or a server one.

I'm not sure which option should I prioritize... We'll see. And I'll upload some screenshots someday within this week.