Eventlistener in Java Addin Tool

623
1
02-05-2012 09:48 AM
Marianne_BilstedWiese
New Contributor
Hi Forum

I am porting a Tool for ArcMap to a Java Addin, and I want to listen to Document events.

In the Tools init() function, I do the following, which I found here:

((MxDocument)mxDoc).addIDocumentEventsListener(new IDocumentEventsAdapter(){
       @Override public void openDocument(IDocumentEventsOpenDocumentEvent e){
         JOptionPane.showMessageDialog(null, "Hey: Document opened!");
       }
});


However, with this code in its init() function, ArcMap hangs and never opens any Document.
ArcMap did not hang when I tried  the newDocument event instead, however a Document that is closed and re-opened will not fire the the newDocument Event.

So, if someone could answer any of my questions here, that would be nice:
1) Are we supposed to fire a super.openDocument(e);  after having done our own logic?
I tried that, but it did not seem to change anything.
2) Could it be, that I should rather listen to Events in an Extension than in this Tool?
It might be, that Extensions are loaded first..
3) Any other suggestions?

In the hope of an answer
Marianne Wiese
0 Kudos
1 Reply
Marianne_BilstedWiese
New Contributor
Hello there

I think I can answer my own question now.

It works for me, if I put this code in the init() method of an Apllication Extension that loads automatically at startup.

Now I get messages both on newDocument and on openDocument Events.

It does not seem necessary to forward the super.specificEvent().

/Marianne
0 Kudos