MVC design issue

I think I need some advice regarding to this issue: My UI contains a JTable used to display available and unavailable records. The user can select one row (record) and book it. But not all the records are "bookable" (because of 48H/time rule) so the UI must react different on available or unavailable records.

I place this logic on controller. So if the view tries to book a record first it informs the controller about and the controller decides if the record can be booked or not. If the the controller decides that the record is bookable it starts the book UI (for the customer ids) and after this it informs the Model.

I did things more or less the way you mentioned except that I did not worry about implementing Design Patterns!!..

In the Client I validate whether a record chosen by user is bookable( everything, including 48 rule) and then call the worker thread to do DB updates. After it completes it calls back another method in EDT which will update the table.

I feel that design patterns are good, but a good solution is more important than the patterns themselves..

Thanks for your answer. I am not shore that I understand wat you mean. Can you detaliate a little

ThanX M.

Thirumurugan Mylrajan
Ranch Hand

Joined: Jan 26, 2006
Posts: 64

posted Jul 16, 2006 19:11:00

0

Originally posted by Mihai Radulescu: Hi, Thirumurugan

Thanks for your answer. I am not shore that I understand wat you mean. Can you detaliate a little

ThanX M.

ok so here is how I do my booking..

1. Assuming the results of the search are already displayed on the JTable 2. Get the details of the selected row and validate them (Like customer field blank, date validation, 48 hr rule ) 3. If its ok throw a dialog to the user asking him to enter the details, like start date, cust id. 4. It user is ok and presses a button do a validation and if its ok, create a thread for back end updates. 5. The backend check locks record, reads again to see if has not been modified and if not modified do the update. 6. On success or failure it calls another method which runs in Event dispatcher thread to do GUI updates with success, failure message, Table updation..etc

I understand - I have a similar workflow, but how create the customer id dialog? The view or the controller ?

Regads M. [ July 17, 2006: Message edited by: Mihai Radulescu ]

Thirumurugan Mylrajan
Ranch Hand

Joined: Jan 26, 2006
Posts: 64

posted Jul 17, 2006 10:39:00

0

Originally posted by Mihai Radulescu:

I understand - I have a similar workflow, but how create the customer id dialog? The view or the controller ?

[ July 17, 2006: Message edited by: Mihai Radulescu ][/QB]

I did not think in terms of the Model-view-controller pattern. Let me try it..

The model in this case is the TableModel. View is the JTable and the controller is the background thread which updates the model.

I cannot create a GUI from a background thread since its not in EDT.

So I throw the dialog from the code which does the inital validation of the data shown in the JTable. So I think in my case the dialog is thrown from the view. But strictly speaking its not from the view, but from an instance holding the view.

Derivations & extensions to MVC are everywhere, and it's really hard to say what acts as a view/controller/model in certain solution. For example, JavaSwing is described as using the Model-Delegate pattern, which is a is a variation of the MVC. TableUI is a view-controller part, and JTable acts as a model (because holds all data selection index, column names, values, etc.)

So, don't worry about MVC, it's already in your implementation, both in micro- and macro- scale!

To simplify interactions between gui components I prefer to use mediator pattern. It really helps in situations, where it's necessary to do many things (like changing state of many components - enabling, selecting, resizing, blocking input) at the same time. For example: