javamacosswtfilehandler

JavaApplicationStub with CFBundleDocumentTypes


I'm trying to use CFBundleDocumentTypes to associate a custom file extension with my application. As far as I can tell, this seems to "work" -- JavaApplicationStub launches my application when I double click the file. However, no callback is registered through the ApplicationListener events I setup in java.

I used the code listed in Set Default file association Mac OS X Java Package Maker Installer to do the file association, and the file association itself appears fine, but it seems as if it is the application stub trying to launch the file, and thus fails.

I added the Apple ApplicatinListener code to my java application at (similar to http://developer.apple.com/mac/library/documentation/Java/Reference/1.5.0/appledoc/api/index.html?com/apple/eawt/Application.html) but it doesn't seem like my application ever gets a call back.

the code is similar to

Application.getApplication().addApplicationListener(
  new ApplicationAdapter() { 
    public void handleOpenFile(ApplicationEvent evt) {
      //some logging message here that I never get
    }
  }
);

I should perhaps mention that I'm also using SWT...

Any help would be appreciated


Solution

  • Unfortunately you can't use the SWT and the eAWT's ApplicationListener at the same time. See this SWT bug. The SWT needs a change from Apple in the JVM, and then I have to change the SWT to use it.

    Since you are interested in an open file event, though, you can now do that entirely in SWT across all platforms. In the 3.6 SWT there is a new event SWT.OpenDocument that will fire when a file for your app is double-clicked. See this blog post and search for "SWT.OpenDocument".