<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Hook into global closing with "X" on the window</title><link>https://answers.axonivy.com/questions/434/hook-into-global-closing-with-x-on-the-window</link><description>&lt;p&gt;I am looking for a possibility to hook me into the closing of a window when a user clicks on the "X" in the window. For example, to ask the user whether he wants to save his data. And if possible it would be extremely nice to give a veto to prevent the closing.&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/434/hook-into-global-closing-with-x-on-the-window" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 29 Mar 2012 05:54:19 -0400</lastBuildDate><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/434/hook-into-global-closing-with-x-on-the-window/437</link><description>&lt;p&gt;I have another solution. In the start method of the Rich Dialog we add a script step. In there we remove the DefaultCloseOperation of the panel which defines what happens after a click on "X". Instead of the normal DefaultCloseOperation we register our own WindowListener.&lt;/p&gt;
&lt;p&gt;As the listener must be written in Java we use &lt;code&gt;getPanelAPI().callMethod("close", new Object[] {});&lt;/code&gt; to call a Rich Dialoh method which handles the closing then for us.&lt;/p&gt;
&lt;p&gt;You can achieve it like this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;call following code in a script step after the RD Start, which prevents the frame from closing and adds an own windowlistener&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import com.ulcjava.base.application.ULCFrame;

ULCFrame frame = panel.getRootPane() as ULCFrame;
frame.setDefaultCloseOperation(ULCFrame.DO_NOTHING_ON_CLOSE);

frame.addWindowListener(panel);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add following method in the panel code which implements IWindowListener&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@Override
public void windowClosing(WindowEvent event) {
try {
    getPanelAPI().callMethod("close", new Object[] {});
} catch (Exception e) {
    Ivy.log().error("Cannot call close method", e);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;3.
 Add a close method to the RD Logic where you can execute custom code&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Thu, 29 Mar 2012 05:54:19 -0400</pubDate><guid>https://answers.axonivy.com/questions/434/hook-into-global-closing-with-x-on-the-window/437</guid></item><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/434/hook-into-global-closing-with-x-on-the-window/435</link><description>&lt;p&gt;For the first question, when a rich dialog is closed then the event "UNLOAD" will be called. Just catch this event in the Rich dialog logic and you can add your additional behavior. Unfortunately you cannot prevent the closing with this.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Wed, 04 Jan 2012 07:47:44 -0500</pubDate><guid>https://answers.axonivy.com/questions/434/hook-into-global-closing-with-x-on-the-window/435</guid></item></channel></rss>