In my GWT project, I’m trying to get it so two DialogBoxes can pass information between each other. One of them holds a MapWidget, and when a button is pressed in the other DialogBox, the position information is received from that other DialogBox’s MapWidget. Does anyone have any tips for how I should coordinate between having two different DialogBoxes show up? Should I wrap the code for the two in a Composite? Furthermore, is there an example anywhere of dealing with two DialogBoxes at once in GWT? For example, if I click outside of the two boxes, both should be dismissed. I’m wondering if there’s a way to keep both of them in focus at once, so I can switch between the two without causing either to disappear.
Share
Sharing Data Between Dialog Boxes
In my opinion, the “correct” way to do this would be to implement some sort of MVP structure in the application so that a presenter manages the view (
DialogBoxes, among other things) and knows how to pass simple data to the view for it to display (the presenter would handle theMapWidgetdata, the view would take care of displaying it on the DOM).However, if you’re looking for a quicker/more simpler approach, you have a couple of options (which you choose really depends on the application structure):
Composite, as you mentioned, that knows how to pass the necessary data back and forth. By having theCompositemanage the data object and tell the twoDialogBoxes how to display it, you are actually approaching an MVP architecture within yourComposite.DialogBoxinto a class that contains aHandlerManager(sometimes used as an “Event Bus”) that fires events when the button is pressed. You can create events that are designed to pass data back and forth between the twoDialogBoxes (even make them type-safe with type parameters). See this StackOverflow question for details on using aHandlerManager. The MVP article, linked above, also has some good information on using an event bus.Model-View-Presenter is a tried-and-true method of structuring an application that results in more testable code, better project structure, and can help guide you when making decisions like this. I strongly recommend checking it out if you haven’t already.
Sharing Auto-Hide Functionality
GWT’s
PopupPanel(on whichDialogBoxis based) offers a methodaddAutoHidePartner(Element)which is describe thusly:So, you can create two auto-hiding
DialogBoxes that only close when you click outside both of them (e.g., they do not close when you click within either of the boxes) with the following code:You can interact with either of the dialog boxes without the other closing. Omit the appropriate call to
setAutoHidePartnerif you only want a one-way partnership.