0

I know, several questions have been asked about this topic. However, I didn't find an adequate answer.

Here is my current design (excuse this ugly pic):

[Movie repository]----|

                      | [Cinema] --- [Controller] --- [View]

[Room repository]-----|

Now I want to display and modify some of the data in a JTable with additional buttons for e.g. creating new movies,....

Is it okay, to create in the view a tableModle for the table or are there more elegant solutions for this?

I feels somehow wrong: For example, in the view I load all movies from the Cinema object. Then I modify the object in the view (in the table) and push it to the controller who calls a method in the cinema which calls the update method of the repositoy and then I load the whole data again. Is such a way "correct"? This way, the view modifies the data (within the table) and so the modification needs not to be delegated to the model..

Please, excuse me - I am a noob....

Compass
  • 5,867
  • 4
  • 30
  • 42
user3579222
  • 1,103
  • 11
  • 28
  • I would load the data in the controller and then push it in the (table)model. The tableModel should notify the view via the fireTableDataChanged() methods. – keuleJ Oct 31 '14 at 19:54
  • Thank you soo much for your reply! So you mean if I press a button on the view, I should notify the controller, the controller loads data from the model, creates a tablemodel out of it and pushes the tablemodel back to the view which is used in the table? – user3579222 Oct 31 '14 at 19:59
  • No, keep the updates to a minimum. The TableModel would wrap your movie model, to honour the contract of the table API. When you make a modification to the values in the table, the table model will push those down to the controller (via the movie model), but only the current value is updated, it should not be required to update anything else – MadProgrammer Oct 31 '14 at 20:14
  • take a look at http://stackoverflow.com/questions/5217611/the-mvc-pattern-and-swing – keuleJ Oct 31 '14 at 22:03

0 Answers0