In Eclipse, can I get the View ID given a reference to one of its widgets? I don't want to enumerate all views and traverse their hierarchies.
Use Control.getParent() API to go up the widget hierarchy starting with your widget. At some point, you will find the view part. Then you can get the info you need. I'd do this in the debugger first to make it easier to identify the class that the view part will have in the controls tree. It should be pretty obvious when you see it.
Ended up using SWTbot and some manual bookkeeping for the purpose.
Related
I have few gwt mvp design related questions:
Can we use event bus to switch views from one presenter to other via controller using custom event?
If above is true, can the custom event (say changeViewEvent) contain name of next view, on the basis of which controller can take a decision, which presenter to show?
Is it a good design to make views reusable(as a widget) in an application, though i don't agree with this, but will be happy if someone has any thing to mention in favor of this.
PS: all my views make use of custom widgets and there is no gwt specific widgets(buttons, checkbox etc...) in views.
You can do anything you want, but you have to consider the consequences. For example, if you switch views without creating a history event, a user may be thrown out of your app when a user hits a back button expecting to see the previous view.
I very much like the Activities and Places design pattern. It takes care of all of the issues (history handling, bookmarks, tokens, etc.) You can also extend it to add animation effects when switching views on mobile devices - mgwt does that.
I have few gwt mvp design related questions :
Can we use event bus to switch views from one prsenter to other via controller using custom event ?
This is a bad practice, unless you have real good reasons to do that. Since you're changing the view without having an impact on the url, you won't know what is a the state of a view at a choosen moment, you cannot get back to a previous view in an easy way, and finally, people will have difficulties reading the code, since you're out of the "standard".
The only reference for you should be the url, you cannot assume data is loaded neither the applicatio is in a given state: each and any view may be the start of the navigation story for your users, so if you get information from any other source than the Place, you're probably doing wrong, especially if your source is an event. the only special case here is you don't want users to enter your app in a certain view state, so you 'impose' that another url is called before, and restrict the access to the view through an event starting from a given application state
If above is true, can the custom event (say changeViewEvent) contain name of next view, on the basis of which controller can
take a decission, which prsenter to show ?
as said before, you're reinventing the wheel. It's far better to adapt to the existing mechanism that is well thought and covers the majority of cases. You can put a json formatter to tokenize your url while developing so it's not a nightmare to put variables in. And when you're done, create a nicer regular url format
Is it a good design to make views reusable(as a widget) in an application, though i don't agree with this, but will be happy if
someone has any thing to mention in favor of this.
depends on what you call a View. if it's the activitie's view then youm might need that in very few cases, it's better to inherit a basic view and fork its children for each activity (even if the view does nothing, time will show it will evolve differently): this is better since the base view contains what is common without the specifics of each child activity.
Finally if you mean a composition of widgets when you say, a view, then you should definitely reuse them, it will make you obliged to improove your widgets and compositions to be in a constant improvement, this will heop you for the rest of the project, and maybe for other projects
I have a problem that I can't find an elegant solution for. I want to use a NestedTree (or something similar) as a simple menu for my page. Each node links to a Page that shows content that is identified by an ID. To get nice URLs and easy bookmarking I'd like to use BookmarkablePageLinks to link to these pages.
But doing it that way creates a completely new Page each time, thus destroying and recreating the tree, resetting it's state. So with each link click the complete tree collapses and the user has to open it again to choose another link.
I can't find a solution, that satisfies these criteria:
Each tab/window retains a separate state
Opening a new tab copies the state from the tab it's opened from, but is then independent
Easy to use, meaning you don't have to manually set and restore state for each link
It would be okay if the state is not restored when the bookmarked URL is called.
With Wicket 1.4 I was able to use the pageMapName to maintain a map of PageMaps and their menu states in the session. But that functionality got altered substantially with Wicket 1.5 (I'm using 6.8 now).
I would be quite grateful for solutions or tips on how to do this.
But doing it that way creates a completely new Page each time, thus
destroying and recreating the tree, resetting it's state. So with each
link click the complete tree collapses and the user has to open it
again to choose another link.
The tree collapses because its model is being recreated on page load. You are probably keeping the tree's model as a member variable on the page. To get around this issue you should store the tree's model in the session object instead. This way you can retain the state across multiple pages.
You can manage your own pageMaps in Wicket 1.5.x and 6.x. All you need is a little Javascript, see AjaxNewWindowNotifyingBehavior for inspiration.
Then you can keep the expansion state of your tree in your session under pageMap-specific keys.
I'm trying to wrap my head around navigation rules in JSF2.0. If I have a button with an action method, is the purpose of the navigation rule to move me to a 'results' page? This seems too simple I guess, couldn't you just f:ajax and update a result area on the page? What is the real purpose of navigation rules and how can one effectively use them in JSF 2.0?
Bonus points for metaphors that use ponies.
The point of navigation rules is that they allow the server to decide, based on the data in a request, which view to show next - a results page, an error page, the next of several possible following pages in a workflow, whatever.
They're not always useful - most applications only have linear workflows and show errors in-page so that you never really need navigation rules. I've always considered it a bit weird that such an (in my experience) rarely-useful feature became a core concept in Struts and JSF. But it would certainly be useful for a workflow with lots of branching logic.
As for AJAX - that's a different use case. If you're switching to a completely different view, you should do a full update rather than use AJAX.
Why not let your pony jump you on this site and find out the basics from a good tutorial :)
I am embarking on my first GWT app and I am using GWT Platform which is based on the talks Ray Ryan gave at Google IO about MVP. I am trying to structure my app the correct way. My understanding is that I have a presenter for every view in the app and every view is essentially a page in the app.
Where I get confused is how to handle non-dynamic pages. Like say you have just an 'About' page(like the one on Stack Overfliw) which has no interactivity at all. Would you still define a presenter and view for that?
The other part of this question is do you only ever have one html file in the app that all the compiled javascript is loaded into?
yes, for the second question. only one html page. all you do is switch panels inside that html.
when you do a RootPanel.get( ['id'] ).add() you're actually changing only a part of the page.
as for about page, not really needed to implement a presenter.
a presenter defines 'events' that will happen on your view, so your view can call those methods on your controller. if the view does not have any events happening, it doesnt need a controller. no point implementing nothing :)
I am looking to create an app with plugin functionality. What I want is to allow a separate plugin "app" to provide me with the view, and take care of the updating of the view that I will use in my list adapter. Essentially, I want the separate app to take care of the bindView and newView methods of my adapter.
I am looking at RemoteViews, but I am not sure if that is exactly what I need, if it would work, or maybe it's what I have to use, since it would be cross-process.
Thanks for your help.
RemoteViews is the only thing vaguely practical, because you are communicating between processes.
Performance will be awful. Getting a ListView to behave quickly when everything is in one process takes a bit of work. Going across process boundaries for every row will either be very slow and memory intensive. This is why, for example, ContentProvider returns its full result set on a query(), to avoid dozens or hundreds of extra RPC calls.
I strongly suggest you reconsider your proposed architecture.