How to unregister GWT eventbus handlers in a Popup/DialogBox? - gwt

I have a dialog box, which contains a button and a TabLayoutPanel. The button is outside the TabLayoutPanel. Tab contents are separate custom widgets.
The problem: I want to respond to clicks on the button by performing an action inside one of the tab content widgets.
I tried using the GWT EventBus this way:
fire an event upon button click
add handler for this event inside the tab
But here's the problem: if I close/open the tab multiple times, the event handler will be registered again. And when the button is clicked, the event handler will start multiple times (for every handler registration/however many times the tab was opened).
Since my dialog box doesn't have an activity/place, I cannot use GWT's Activity.start(... EventBus eventBus) for automatic activity deregistration.
A possible solution is to manually remember registered HandlerRegistration(s) and .removeHandler() them when I navigate away from the tab. But this is a rather ugly solution.
Question: Is there a way to unregister events in a dialog box without remembering them?

It's hard to give a concrete answer without code, but I'd do it like this:
Add ClickHandler to the button when the Popup/Dialog gets opened.
If this button is clicked, check which tab is the active one and call a specific method on the widget in that tab.
getSelectedIndex() and getWidget(index) should be the methods on the TabLayoutPanel to use to determine which widget is the active one.
Unregister the clickhandler after the Popup/Dialog got closed.
This way, you have only one Handler to remove what should be the normal way, e.g. with the onClose() event of the DialogBox.

Related

WicketTester: How to click secondary mouse button?

I want to test a wicket component which shows a context menu on click with the secondary mouse button.
With WicketTester.click(Component) I can click obviously simulate a click on a component. But how do I simulate a click with the secondary mouse button?
WicketTester does not provide means to test JavaScript!
If the context menu is being shown with Wicket Ajax call to the server to make it visible then you can do tester.executeAjaxBehavior(...).
If the menu is shown via JavaScript in the browser then WicketTester cannot check whether it is visible or not. But in that case you should be able to test selecting a menu item, i.e. sending an Ajax call with the appropriate value for the item.

Key Listener called again and again if I click on Browser's back Button with Activity and Places in GWT

I am creating search page and I have use activity and places in GWT. I have used Key Listener so when user press Enter it redirect user on result page.
Problem is that when user use browser back button and again press enter Key Listener call twice same if user again click back button next time it will call trice and so on. Is there any solution for this?
You're probably adding your listener when activity starts but never remove it (e.g. when activity stops).
The full solution depends how you code your activity (do you reuse activity instances? do you have a separate view with activity acting as a presenter/controller? if so, is the view a singleton, or at list lives longer than the activity and can be reused by another activity instance? etc.)

Windows Forms Error Provider does not display in custom tab control

I'm trying to build a Wizard framework in Windows Forms. I've managed to glean a lot of useful tips from this and other sites which have gotten me very close to success. However, I'm having a problem with displaying an ErrorProvider on any tab page other than the first page of the wizard.
My Wizard control is a UserControl. It contains a custom tab control that I've derived from TabControl so that I can hide tabs and ignore attempts to navigate between tabs using keypresses, along with the usual collection of Back/Next/Finish/Cancel buttons at the bottom of the control.
I've used reflection to allow me to raise the validation events on a particular TabPage that belongs to the Wizard Control when I hit the Next button. (I don't want to validate the whole TabControl, only the currently active page.) When I do this, I see in the debugger that my Validating routine for the controls on the current tab page is correctly called and I see that I've called the ErrorProvider that I've attached to the particular control (a TextBox in this case) with a valid error message. I set Cancel to true for the CancelEventArgs in the validating routine and that's picked up by the code that uses the reflection mechanism so that I see that I've failed and don't change tabs. And I set the focus successfully to the control that failed validation.
So all that appears to be working just fine.
Unfortunately, I don't see the ErrorProvider's cheery blinking icon unless I'm on the first tab page. For all of the other tab pages, there's no message visible at all.
I'm baffled. Any thoughts? I can provide code snippets, if helpful.
Thanks!
I assume that in your case the button that moves to the next step of the wizard is placed outside (below) the TabControl
I noticed that the icon is displayed correctly if I pressed the button without releasing the mouse button. It seems that the button outside the container gets focused event though a validation error has occurred (normally you would not be able to leave the active control).
I worked around this issue by registering an event handler for the buttons MouseUp event to "refocus" the TabControl:
private void cmdOK_MouseUp(object sender, MouseEventArgs e)
{
tabControl1.Focus();
}
Note: you also need to set your forms ActiveControl property the one of the controls that failed validation.

How to avoid closing Popup

I have an Popup(not modal window) which shows textbox, when I start typing in the textbox I need to open another popup which show listbox,when I select any item from list box the popup disappears as well the previous popup also disappears how can I avoid closing of the very first popup on close of 2nd popup.
Use a standard "bandpopup" component - in this case you wouldn't even have a second popup to manage. Other thing which comes to my mind is add onClose event listener or event handler - whichever you prefer - and stop event propagation with Event.stop(caughtEvent). It will effectively prevent propagation of OnClose event and your first popup wouldn't be closed.

Listener function for gwt widgets

For my project when a button is clicked, the click event should then wait and listen to the next two clicks on different widgets and then connect them so as to form relationship between them.
Right now i an trying to use FocusListener without success. Any suggestion will be of great help.
Thank you.
I would think you'd just want an ClickListener for each object. Handle "enabling" the other two objects in the first object's click event, then when those two objects are clicked on, invoke the method to form the relationship. You don't want to wait in the first object's event handler.