FAQ How do I dynamically register an editor to handle a given extension?
You cant. Editors, like most other extensions to the platform, must be specified declaratively in the plug-in manifest file. You cannot dynamically install a new editor except by dynamically installing a new plug-in containing the new editor.
The only thing you can currently do programmatically is specify the default editor to use for a given file name or extension. The editor must already be registered with the platform through a plug-in and must already declare that it supports files with that name or extension.
Here is an example snippet that sets the default editor for text files to be the built-in platform text editor:
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); registry.setDefaultEditor("*.txt", "org.eclipse.ui.DefaultTextEditor");
This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.