How to make a XUI dialog go away with its corresponding document.

Keith Berard shows how Last Updated: 2006-10-24

=Question by N.N.=

I have created an XUI dialog box that shows when a particular document type is selected using an instance.acl file to source the dialog. How do I cause this dialog to close when the document instance is closed? Currently if I close the document and open a new document, I have two of the same dialogs open.

=Keith Berard answers=

We encountered this for our XUI implementation. The code base is in Java, but the general idea should be pretty easy to write in any language.

Basically, on instantiation of Epic, through the use of the custom\init folder, we create an object that listens for DocumentLoad events. In this way, anytime a new window is opened, the event gets fired. Next, we get a handle on the current window by doing the following:

Document doc = (Document)e.getTarget; View view = (View)((DocumentView)doc).getDefaultView; Window win = view.getWindow;

Finally, we make a call to a method that checks a static arraylist containing a list of windows. If the window passed does not contain the XUI dialog, we create it, and add the window to the list. If there is already a XUI dialog present, we do not.

In addition, we trap the WindowClosing event to remove the window from the static list when the window is closed. This works for us because we want to keep an instance of our dialog open even when just the default blank edit window is up (our XUI interfaces our CMS, so we need to have one instance up at all times). I assume you could trap DocumentClosing or the like if you wanted the XUI to go away when the last document is gone.

That's pretty much it. The last thing I should mention is that getting the initial instance to load on first application run is a bit tricky, so below is a snippet of what we actually call, contained in "loadXUITools.js " in our init dir. /** * This function loads the initial XUI. * ApplicationLoad event is used because first run will * not have a valid document (editinit) and scripts in * init are called before the window is fully available. */ function handleEvent(e) { if (e.getType.equals("ApplicationLoad")) { Packages.com.mcg.epic.xui.XUIToolManager.loadXUI; } } var o = { handleEvent: handleEvent }; var listener = Packages.org.w3c.dom.events.EventListener(o); Application.addEventListener("ApplicationLoad", listener, true);