private static class SetupClassFileAssociationRunnable implements Runnable
{
public void run()
{
EditorRegistry registry = (EditorRegistry) PlatformUI.getWorkbench()
.getEditorRegistry();
// Will not work because this will not persist across sessions
// registry.setDefaultEditor("*.class", id);
IFileEditorMapping[] mappings = registry.getFileEditorMappings();
// Search Class file editor mappings
IFileEditorMapping classNoSource = null;
IFileEditorMapping classPlain = null;
for (IFileEditorMapping mapping : mappings)
{
if (mapping.getExtension().equals("class without source"))
{
classNoSource = mapping;
}
else if (mapping.getExtension().equals("class"))
{
classPlain = mapping;
}
}
IEditorDescriptor jdtClassViewer = registry.findEditor(JDT_EDITOR_ID);
// * If there is a "class without source" type - handle this and revert
// "class" to the default handler.
// * Else register as the default handler for "class"
if (classNoSource != null)
{
// Got a "class without source" type - default to handle this and
// un-default from the "class" type
registry.setDefaultEditor("." + classNoSource.getExtension(),
EDITOR_ID);
if (classPlain != null)
{
if (jdtClassViewer != null)
{
// Restore the default class viewer as the default
// "class with source" viewer
registry.setDefaultEditor("." + classPlain.getExtension(),
JDT_EDITOR_ID);
}
for (IEditorDescriptor editorDesc : classPlain.getEditors())
{
if (editorDesc.getId().startsWith(JD_EDITOR_ID))
{
// Unmap the default JD Eclipse editor
((FileEditorMapping) classPlain)
.removeEditor((EditorDescriptor) editorDesc);
}
}
}
}
else if (classPlain != null)
{
// Only got a class file type - default to decompile this
registry.setDefaultEditor("." + classPlain.getExtension(), EDITOR_ID);
}
// Save updates
registry.setFileEditorMappings((FileEditorMapping[]) mappings);
registry.saveAssociations();
}