简体   繁体   中英

Eclipse RCP: File association (--launcher.openFile)

I'm developing an eclipse product and i need to associate a file extension to my editor. I followed several examples (as like as this and this ) but it seems that the editor ever receives the SWT OpenDocument event.

As described in the fileAssociation example i created an eventListener class to process SWT.OpenDocument events and i added this in my Application class to the display before that the PlatformUI.createAndRunWorkbench() method gets called

public Object start(IApplicationContext context) throws Exception {
Object args = context.getArguments().get(IApplicationContext.APPLICATION_ARGS); 
OpenDocumentEventProcessor eProc = new OpenDocumentEventProcessor();
Display display = PlatformUI.createDisplay();
display.addListener(SWT.OpenDocument, eProc);
try{
    if(!handleWorkspace(display)){
        System.exit(0);
        return IApplication.EXIT_OK;
    }
int returnCode = PlatformUI.createAndRunWorkbench(display, new XVRWorkbenchAdvisor(args, eProc));

In the product file i added the following program arguments:

--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-name
XVR Studio Developer

If I use the same code in a new empty RCP project it works like a charm..

I can't figured out which could be the problem..

can you help me?

Thanks a lot!!

As I have just made this work for an RCP app, I thought it would be helpful to document how I did it here, and provide refs.

  1. I had no use for the 'context.getArguments()..', the 'OpenDocumentEventProcessor' handled everything.
  2. I would suggest that the reason this did not work was that the -name value did not match the value of the 'appName' property in the 'org.eclipse.core.runtime.products' extension point. Just to be sure, I removed the spaces from the appName property and in the -name. Then it worked.

Very useful references are:

For the basic coding: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fproduct_open_file.htm

For an explanation of how this works: http://aniefer.blogspot.co.uk/2010/05/opening-files-in-eclipse-from-command.html

One small point that eluded me for some time, was getting the path for the file in several chunks at the place where there was a space in the name. Eventually I realised (in a 'duh!' moment) that I needed to put quotes round the %1 parameter in the installer's (InstallAware) definition for the file association - ie it became "%1"

This approach is unknown for me, but since there is no explicit editor call in your pasted code I guess you still rely on eclipse to decide which editor has to be opened. So I guess you still have to define contentypes and file associations declaratively. To do that contribute to "org.eclipse.core.contenttype.contentTypes" extension, add a 'file-association' (file extension...). Get your editor declaration in your plugin xml and add the previously created 'contentTypeBinding' id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM