Thursday, January 31, 2013

Re: Cancel CellList selection

Thanks Thomas. Unfortunately we are not using any DI framework. So we are going by traditional GWT Activities and Places framework with ClientFactory being passed to my Activity from AppActivityMapper. 

Interesting. I never thought declaration of SingleSelectionModel model should be in Activity although I understand we can mock SingleSelectionModel for testing. So I guess the selectionModel.addSelectionChangeHandler code will also go in Activity/Presenter class right? 

The reason I put the flag it in ClientFactory is I wanted to make it a global variable so that it could be reusable from different Views that has List-Details screens. When user arrives on the form, reset the flag in ClientFactory to false. When user saves the form successfully, reset that flag to false as there are not unsaved changes. When user update the form set the value to true onValueChange event of its GWT widgets(textbox, SelectBox, etc). That way not only I can show that pop-up alert message if the user clicks on different cell in the Cell List within the same view but also if the user tries to navigate away to a different tab in my app, I can check that variable globally thru some PlaceChangeEvent. I thought putting a global variable would be easier than having every view to handle logic of updating the local flag within its presenter. 



On Thursday, January 31, 2013 5:22:13 AM UTC-6, Thomas Broyer wrote:


On Tuesday, January 29, 2013 6:43:11 PM UTC+1, BM wrote:
I was looking something similar and your example is perfect. I am going with approach of having my custom SingleSelectionHandler i.e PromptingSelectionModel . My view is more like GWT Showcase CellList-DetailForm example. If I click on my cell, my code populates the form elements. My Form is a separate GWT custom widget FormAWidget with its own presenter FormAPresenter. 

So with that being said, I probably will be storing a variable "hasUnsavedChanged" in ClientFactory which gets updated whenever my form data is changed. How do I get that variable inside my PromptingSelectionModel class so that I can check that variable in my overridden setSelected method? Since I use GWT MVP structure my ViewA holds declaration of CellList and PromptingSelectionModel. The ActivityA has reference to ClientFactory, the only way I can think of is passing the ClientFactory to my ViewA class with setClientFactory(ClientFactory cf) and pass that ClientFactory object to PromptingSelectionModel constructor. I don't like the idea of my views now having reference of ClientFactory.

"ClientFactory" (if you copied it form the Dev Guide) is supposed to be about "manual dependency injection". You shouldn't pass it around (if you were using a JSR330 DI framework or similar, such as GIN, you wouldn't even pass it to the activities, you'd instead inject a Provider<HelloView>). If you happen to need it in the view, then give it to the view when it's constructed (the view is constructed by the ClientFactory, right?)

That said, I believe the selection model should live in the presenter: it's part of the "presentation logic".

Please advise if you can see any better way of doing this.


Avoid global shared state. Don't put "hasUnsavedChanges" in your ClientFactory. That information belongs to your form (and in this case, its presenter). Then inject objects into each other as needed so they have access to the information.

 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment