Question

My Eclipse plugin produces .pdf files for my users in the Project Explorer in the projects that my plugin creates. Today, a tester noticed that on his install, when he double clicks this .pdf file in his project explorer, he gets the OLE exception dialog...

OLE Exception dialog from Eclipse

What I want to do is make so that when my plugin is installed in Eclipse, it modifies the preferences to assign the .pdf file association to the system's pdf viewer.

I realize that this might be a bad idea, since I can't assume that a user has a PDF viewer installed on his/her PC.

I noticed that when I right click the .pdf file in the project explorer, that I get a choice to "Open With" various options like "Default Editor" and "System Editor". I'd like my plugin to make the default action be Open With -> System Editor.

Is this possible? If so, how?

Was it helpful?

Solution 2

It does not look like it is possible to change or add a file association without using internal classes.

You can get the existing file associations with:

IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();

IFileEditorMapping [] mappings = editorRegistry.getFileEditorMappings();

but updating the list requires using the EditorRegistry implementation of IEditorRegistry and this is an internal class. The implementation of IFileEditorMapping is also internal.

Update:

The org.eclipse.ui.editors extension point does have a command attribute for running an external program and a launcher attribute for running a program via a IEditorLauncher class. You might be able to use one of those.

OTHER TIPS

Try Window > Preferences > General > Editors > File Associations.

Add *.pdf if it is not there. Highlight it and then add an associated editor. Select the External programs radio and then Adobe Acrobat Document or another reader program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top