[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
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:




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();


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
Eclipse Platform Team
Pleasanton, CA