To try the new approach, add the following definitions in the containing widget:
Code:
HandlerRegistration reg;
Dialog getReusableDialog() {
Dialog dialog = (Dialog) Canvas.getById("isc_globalWarn");
// dialog may not exist if no dialogs have been shown yet
if (dialog == null) {
SC.say("Creating Reusable Dialog");
dialog = getReusableDialog();
dialog.clear();
}
return dialog;
}
void watchForNoteHide() {
if (reg != null) return;
final Dialog dialog = getReusableDialog();
reg = dialog.addVisibilityChangedHandler(new VisibilityChangedHandler() {
public void onVisibilityChanged(VisibilityChangedEvent event) {
String title = dialog.getTitle();
if (!"Note".equals(title) || dialog.isVisible()) return;
SC.logWarn("*** Dialog hidden!"); // run your code here
reg.removeHandler();
reg = null;
}
});
}
Since this approach relies on heuristics, if your UI is closed through some other means (other than the hook you add to the handler above), you may want to check for reg != null and remove the handler in that case, to ensure it's no longer active.
Leave a comment: