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.
As the listener must be written in Java we use `getPanelAPI().callMethod("close", new Object[] {});` to call a Rich Dialoh method which handles the closing then for us.
You can achieve it like this:
 1. 
 call following code in a script step after the RD StartStart, which prevents the frame from closing and adds an own windowlistener
        import com.ulcjava.base.application.ULCFrame;
        ULCFrame frame = panel.getRootPane() as ULCFrame;
        frame.setDefaultCloseOperation(ULCFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(panel);
 2. 
 Add following method in the panel code which implements IWindowListener
        @Override
        public void windowClosing(WindowEvent event) {
		try {
			getPanelAPI().callMethod("close", new Object[] {});
		} catch (Exception e) {
			Ivy.log().error("Cannot call close method", e);
		}
	}
 3.
 Add a close method to the RD LogicLogic where you can execute custom code