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.

asked 03.01.2012 at 10:25

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%


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 Start, 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 Logic where you can execute custom code

link

answered 29.03.2012 at 05:54

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
(suspended)
accept rate: 75%

edited 18.09.2014 at 13:51

Peter%20St%C3%B6ckli's gravatar image

Peter Stöckli ♦
(suspended)

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.

link

answered 04.01.2012 at 07:47

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
(suspended)
accept rate: 75%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×40

Asked: 03.01.2012 at 10:25

Seen: 2,537 times

Last updated: 18.09.2014 at 13:51