Search code examples
eclipse-rcpfile-association

Change Eclipse RCP unknown file type association programmatically


I am building a 3.x RCP application and I add some Eclipse based default features such as Project Explorer, toolbars, preferences pages etc.

My problem is when I drag and drop a file that is not associated with any editor. In that case Eclipse RCP uses the default editor that my OS uses. I know I can change it from Preferences > Editors, but I would like to change the default value of that preferences by coding.

I want to assign unknown file types to the Eclipse text editor. How can I do that?


Solution

  • 'Preferences > General > Editors > File Associations > Open unassociated files with' ends up setting the IDE.UNASSOCIATED_EDITOR_STRATEGY_PREFERENCE_KEY preference key in the preference store for the org.eclipse.ui.ide plug-in. The value of the key for using the text exitor is org.eclipse.ui.ide.textEditor

    So you should be able to use something like:

    IPreferenceStoere store = new ScopedPreferenceStore(InstanceScope.INSTANCE, ""org.eclipse.ui.ide"");
    
    store.setValue(IDE.UNASSOCIATED_EDITOR_STRATEGY_PREFERENCE_KEY,
                   "org.eclipse.ui.ide.textEditor");