OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved] How to prevent file closing

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
satabau
General User
General User


Joined: 12 Mar 2012
Posts: 34

PostPosted: Thu May 24, 2012 8:59 am    Post subject: [Solved] How to prevent file closing Reply with quote

Hi, while my program is running I need , if the user wants to close the file and clicks on the "X", to show something and tell him that he can't close the file.
I've made this:
Code:

public class MyDocumentEventListener implements XDocumentEventListener {

    public void documentEventOccured(DocumentEvent ev){}
    public void disposing(com.sun.star.lang.EventObject ev){}
}

and
Code:
xSpreadsheetComponent.addEventListener(new MyDocumentEventListener());

but I have no idea how to PREVENT the closing. With method "disposing" I only have the information that the user is closing.
I tried another way but I have the same problem:
Code:
public class EventListener implements com.sun.star.document.XEventListener{

    public void notifyEvent(com.sun.star.document.EventObject arg0){System.out.println("NOTIFYEVENT");}
    public void disposing(com.sun.star.lang.EventObject arg0){System.out.println("disposing");}
}

and
Code:
 
       XMultiServiceFactory xFactory=null;
     try{    xFactory  = getMultiServiceFactory(xRemoteContext);
               XEventBroadcaster xEventBroadcaster =(XEventBroadcaster)      UnoRuntime.queryInterface(XEventBroadcaster.class, xSpreadsheetComponent);
             XEventListener xEventListener = new EventListener();
              xEventBroadcaster.addEventListener(xEventListener);
         }catch(Exception e){e.printStackTrace();}

Can you help me?
Thank you
Back to top
View user's profile Send private message
satabau
General User
General User


Joined: 12 Mar 2012
Posts: 34

PostPosted: Fri May 25, 2012 4:42 am    Post subject: Reply with quote

I write my solution. Hope this can help someone
Code:

XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop);
        XTerminateListener terminateListener = new MyTerminateListener ();
        xDesktop.addTerminateListener (terminateListener);

and
Code:

public class MyTerminateListener implements XTerminateListener{

    public void notifyTermination(EventObject arg){}

    public void queryTermination(EventObject arg) throws TerminationVetoException
    {
        throw new TerminationVetoException();
    }

    public void disposing(EventObject arg){}
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group