• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question for Eugene re: push and pull in gui

 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eugene
I have a quick question with regard to a method signature you had in your flightsmodel posted a while back:

I can't make my mind up to do a push of the model's data to the gui or a pull of the data by the gui from the model and I am erring towards using the push method but cannot see how to get the data I want to push to the gui to arrive at the gui in the correct format.
For example my model returns DataInfo[] for the data and a Set for the Origins and Destinations. I can broadcast the data to the gui ok but if as the gui is expecting just Object there is naturally a runtime exception if I try and cast to DataInfo[] or Set to get the data I want.
How did you translate Object to what you wanted in the gui of did you have a Table model etc that accepted an Object argument?
Many, many thanks
Sam
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:

For example my model returns DataInfo[] for the data and a Set for the Origins and Destinations.
How did you translate Object to what you wanted in the gui of did you have a Table model etc that accepted an Object argument?
Many, many thanks
Sam

i', not Eugene. still... when you go for a push the model should only push an Object or and
Object[] , typically it will be a String[] . i.e, the View is is as dumb as dumb as ever.
Model:

Object[] getFlights()
typically, [as i have done] you will send the column names appended in the first row.

View:

update(int updateType, Object data)
switch updateType:
case SEARCH:
setData(Object[] )data;

in setData, refresh your typical TableModel .
note the Object[], typecast, u cant get away with it. you can't push some flight[] objects and expect the View to do something, forget displaying. Any push should be the residual array like String[]. you have got penalities for having a push to populate the origin, destination and carrier combo.
the Model needs to notify ONLY "business actions" like book or a search operation. if it notifies "unique origin" , then the Model loses it purpose. ie., update the views of the data change in model.
what earthly reasons does a Model have to say "push unique origin, carrier" etc.
One way to avoid this can be, use two views one a table format view which relies on the "Push" mechanism from the model and another Outher View which knows the specific Model and pulls the data from combo boxes, text boxes, option buttons etc. the Inner table View is completly reusable and generic.
also i would like to know about double dispatch wherein the View updating the Controller of changes in view(pass "Book button pressed" and itself to the Controller) and the Model updating the Views of changes in data. both uses Observable-Observer pattern.
any ideas are welcome!
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyome likes to untangle this thread of MVC???
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aadhi
I need my origins and destinations at program startup thats is why they will be either pushed or pulled to the gui.
My real question is how do I convert the Object value received by the gui in the modelChanged() method for a push to a useful data type such as DataInfo[] that I can store in my table model? If I try and cast I get a class cast exception at runtime understandably.
Likewise if I were using the pull method and I would end up with an Observable object that would be a superclass of my flightsModel so I cannot cast an Observable down to a flightsModel to call the necessay accessor methods on it.
If anyone can help with this I would really appreciate it.
Many thanks Sam
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:
I need my origins and destinations at program startup thats is why they will be either pushed or pulled to the gui.

1. if you need a scalar value to be shown in your view, then the view should be aware of the underlying model. ex1:- get unique carrier.
ex2: show the manager of the employee in employee details screen.
this scalar data shoud be in the Outer GUI . it will "pull" the data.
The inner view will only display in a record format so any model can pull records(ie., Object[]) to it. flights detail, employee detail, conference room detail or whatever.

My real question is how do I convert the Object value received by the gui in the modelChanged() method for a push to a useful data type such as DataInfo[] that I can store in my table model? If I try and cast I get a class cast exception at runtime understandably.

if View can downcast the Object value into DataInfo[] it's not a push. . the Model pushes Object[][] (in reality it should a String[] because View doesnt recognise objects like a Flighs object or an employee object, instead it can recognize a String[] ) and the views uses it to set its TableModel. that's it.

hope it will be of help!
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean Aadhi with the following:

the Model pushes Object[][] (in reality it should a String[] because View doesnt recognise objects like a Flighs object or an employee object, instead it can recognize a String[]

How can an Object[][] be a String[] - one is a two-dimensional array and the other a single.
If I understand correctly you are saying that you are casting the origins and destinations data to Object[] and the table data to Object[][] and that the gui should know nothing about the way the database stores the data in DataInfo Objects?
So you are converting DataInfo[] to String[] or String[][] and then passing that back to the gui?
Thanks Sam
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
Here is what you can do in View:

Eugene.
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:
I'm not sure what you mean Aadhi with the following:
How can an Object[][] be a String[] - one is a two-dimensional array and the other a single.

i apologize, it is a String[][]

So you are converting DataInfo[] to String[] or String[][] and then passing that back to the gui?

exactly! i repeat, for a "Push" option the View should be the dumbest. it should know the residual data like a String[][]. nothing more nothing less.
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugene Kononov:

Here is what you can do in View:

Eugene.

Euegene,
thanks for the sample code! still i am not convinced with the Model pushing the ORIGIN_AIRPORTS. basically a Model will broadcast when its state changes. A Model pushing ORIGIN_AIRPORTS to the view, is as good as the view calling getOriginAirports to the Model. our main concern is to keep the View as dumb as possible. The Model loses its high cohesion and it is doing "out of the way functionalities" by way of ORIGIN_AIRPORTS. IMHO, the notification of a Model is to keep different views like say a pie chart, a table , a graph and such like uniform provided the Model data changes.
consider the situation wherein i want to use the same View for a Conference room booking or a train booking. i need to create one more view because the modelChanged is not generic . i mean ,it starts recognizing mode than a SEARCH_EVENT and a BOOK_EVENT. imagine we need to make a search based on all the fields say price .
The Model needs to fire the PRICE_DOLLARS. what i am trying to know is that the View can't get away with a Push unless it a generic record type. the outer view will pull the values which "wont change
after startup" like the destination airport, origin , carrier etc and the push approach for more generic /reusbale events like search and book.
hope i am clear with my views!!
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eugene Kononov:

public void modelChanged(String notificationType, Object data) {
if (notificationType == NotificationType.ORIGIN_AIRPORTS) {
String[] origins = (String[])data;
for (int i = 0; i < origins.length; i++)
originAirportCombo.addItem(origins[i]);
}
}
[/CODE]
Eugene.

Eugene , i have got a query. does the NotificationType equivalent to the notification contract between the View and the Model or is it altogether a separate class. say , in my case the NotificationType is called as the ModelChangedListener(Interface) which has the contract modelChanged(int updateType, Object data) as well as all the static final fields for update types like SEARCH_EVENT, BOOK_EVENT etc.
if the NotificationType is the contract between view and model for notification, then putting a field like ORIGIN_AIRPORTS kills the contract of a very generic booking and searching system. i may need to add ROOMS for a conference rooms searching/booking.
please guide me !
[ February 26, 2003: Message edited by: aadhi agathi ]
 
Burk Hufnagel
Ranch Hand
Posts: 814
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aadhi agathi:
the outer view will pull the values which "wont change after startup" like the destination airport, origin , carrier etc and the push approach for more generic /reusbale events like search and book.

aadhi,
What makes you think they won't change? Just because the client you are writing doesn't modify anything but the number of available seats in a record doesn't mean that some other client won't.
Data has methods to add, modify, and delete records _and_ you have to make those methods available to anyone using your remote version. So, how can you be sure that there isn't another client app out there that won't add a new Origin city, or modify/delete the last record refering to SFO?
What happens then? If you assume that the values never change after start up then you're either showing values in your combo boxes that no longer exist in the database, or you're missing newly entered values.
BTW, neither of these scenarios is in the assignment that I received, but neither of them is outside the scope of what I would be testing either.
 
Sam O'Neill
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone.
Burk I am initialising the origins and destination at startup but that's it. I agree that another application could be modifying the database such that an item in the list is no longer available after startup but all that means is that the user will get a message such as
"Sorry no flights available for the chosen criteria at this time"
Are you proposing live updates to the origins and destinations fields?
Sam
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Burk Hufnagel:

What makes you think they won't change? Just because the client you are writing doesn't modify anything but the number of available seats in a record doesn't mean that some other client won't.

ha, its' a good response. what i mean by "wont change" is, NOT that the actual values wont change. the user wont be getting a refresh of these combo boxes even if something is done behind the back unless the application is reloaded. if i do a refresh of all the combo boxes , text boxes etc. it will cost a hell lot of issue. so i will pull the values only at startup for this minute data.
saying this, refreshing the View records (JTable) on a book or search is a good way of synching all the Views. The Model pushes the data to the View in record form and so the inner View will be dumb and reusable 100%. the inner View knows only " how to show a String[][]". Pass anything from the Model which is a String[][] , the View renders it.
But the Outer view is a different case . you can make the model notify the flight, origin, destiantion etc. but if the view knows how to display this , then it is as good as coding the view with a pull. meaning that the View is not reusable for a different model say a conference room booking which may need to show the room, time etc.
Thanks for you thoughts!
hoping someone will help with the Model pushing , bending "out of way" on its functionality of notifyig the "state change" .
[ February 27, 2003: Message edited by: aadhi agathi ]
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:
Thanks everyone.
Burk I am initialising the origins and destination at startup but that's it. I agree that another application could be modifying the database such that an item in the list is no longer available after startup but all that means is that the user will get a message such as
"Sorry no flights available for the chosen criteria at this time"

this is the most feasible solution. consider some 5+ combo boxes in a real application . it will cost hell to update these combo boxes once after startup. BTW,1. are you still using the "push" for search and book events???
2. do u have a single View or an Outer and Inner View , Outer pulling and the inner pushing ???
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam O'Neill:
Thanks everyone.
Burk I am initialising the origins and destination at startup but that's it. I agree that another application could be modifying the database such that an item in the list is no longer available after startup but all that means is that the user will get a message such as
"Sorry no flights available for the chosen criteria at this time"

IMHO, this is the most feasible solution. consider some 5+ combo boxes in a real application . it will cost hell to update these combo boxes once after startup. BTW,1. are you still using the "push" for search and book events???
2. do u have a single View or an Outer and Inner View , Outer pulling and the inner pushing ???
FlightsView containing FlightsTableView.
 
aadhi agathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does anyone want to pass a Judgement
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eugene , i have got a query. does the NotificationType equivalent to the notification contract between the View and the Model or is it altogether a separate class.

NotificationType is a separate very simple class, here it is in its entirety:

Eugene.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic