[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] setDelegate for NSApplication

I looked into the Display class.

I followed your advice and I created my SWTDelegate calling alloc() and init().

 

I set my own delegate and all works fine.

 

Thanks.

 

I have a swing application that has to run on MacOsx and for some features I need  to have a reference to the NSApplication and to a custom delegate.

I tested my application, after the changes, and I didn’t find wrong behaviors.

In any case, do you think that there may be some inconvenience as a result of this implementation?

 

Regards,

Roberto

 

From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx] On Behalf Of Scott Kovatch
Sent: Wednesday, August 18, 2010 7:26 PM
To: Eclipse Platform SWT component developers list.
Subject: Re: [platform-swt-dev] setDelegate for NSApplication

 

 

On Aug 13, 2010, at 8:32 AM, Roberto Cesare wrote:



Dear All,

 

I’m quite new to SWT Cocoa Port.

I would like to know how to set a delegate for the org.eclipse.swt.internal.cocoa.NSApplication class.

I see that the class has a method setDelegate and I try to invoke it , but the delegate don’t receive any callback, like for example:

applicationDidBecomeActive

or

applicationShouldTerminate

My delegate extends NSObject and implements the two above methods.

MDSwtDelegate controller = new MDSwtDelegate();

org.eclipse.swt.internal.cocoa.NSApplication application = org.eclipse.swt.internal.cocoa.NSApplication.sharedApplication();

application.setDelegate(controller);

There are two problems here. First, it's not enough to just call "new CocoaClass()". You also need to call alloc() and init() so the underlying Cocoa object is created and initialized. Then, your delegate needs to have the objective-C methods defined and added to the class. See Display.initClasses() for ideas on how you would do this.

 

The other problem you may run into is that the SWT already uses the NSApplication's delegate for its own purposes. Have a look at Display to see what you would lose by using your own delegate object.

 

-- Scott K.

 

------------------
Scott Kovatch
IBM

Eclipse Platform Team

Pleasanton, CA