• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Where TableModel goes? -- Client GUI

 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
In my design, two JComboBox (Views) are hooked with DataModel (Model) (client side) through listeners. Controller (Control) deals with all inputs from JComboBox and JTable, then directly save all changes in the DataModel (Model).
But the question is where I should put TableModel? I consider it as the part of Views in MVC. But according to this, I cannot hook it with DataModel (model), right?. And I have no idea how to update it by View ( bypass Controller or not???) ?
Any suggestion for this? Thanks.
Rick
Regards.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11893
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rick,
Originally posted by Rick Lu:
But the question is where I should put TableModel? I consider it as the part of Views in MVC. But according to this, I cannot hook it with DataModel (model), right?. And I have no idea how to update it by View ( bypass Controller or not???) ?

I agree with your idea of having the TableModel within the view.
You could have the View getting the updates from the Model and passing them on to the TableModel. Alternatively, if your Model is Observable, you could make your TableModel an Observer, and have it receive the updates directly.
Does this give you some ideas?
Regards, Andrew
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Andrew.

You could have the View getting the updates from the Model and passing them on to the TableModel.

I think JTable is the View. But of course, I need a class (TableModel) that extends AbstractTableModel. My question is that how I can update TableModel by View? Did you mean directly getting updates from Model to JTable and passing them to TableModel? Or something else? I cannot understand this. Currently, the view - JTable gets everything from TableModel. Could you explain this from me? Confused.
Regards. Rick
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11893
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rick,
You have some class that sets up the TableModel and the JTable. That class could either pass updates from the Model to the TableModel, or it could register the TableModel as an Observer of the Model (in which case the TableModel will get the updates automagically).
Regards, Andrew
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

You have some class that sets up the TableModel and the JTable. That class could either pass updates from the Model to the TableModel,

You mean "That class" is a part of Views? To me, the role of it is not clear. I think that's my problem. Is it a part of View?
or it could register the TableModel as an Observer of the Model (in which case the TableModel will get the updates automagically).

Yes, I currently use it and it works.
Thanks. Rick
 
Rick Lu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I undertand your points now, Andrew. Thanks.
Rick
Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic