//Save the resource type descriptions
List editors = new ArrayList();
IPreferenceStore store = WorkbenchPlugin.getDefault()
.getPreferenceStore();
XMLMemento memento = XMLMemento
.createWriteRoot(IWorkbenchConstants.TAG_EDITORS);
memento.putString(IWorkbenchConstants.TAG_VERSION, "3.1"); //$NON-NLS-1$
FileEditorMapping maps[] = typeEditorMappings.userMappings();
for (int mapsIndex = 0; mapsIndex < maps.length; mapsIndex++) {
FileEditorMapping type = maps[mapsIndex];
IMemento editorMemento = memento
.createChild(IWorkbenchConstants.TAG_INFO);
editorMemento.putString(IWorkbenchConstants.TAG_NAME, type
.getName());
editorMemento.putString(IWorkbenchConstants.TAG_EXTENSION, type
.getExtension());
IEditorDescriptor[] editorArray = type.getEditors();
for (int i = 0; i < editorArray.length; i++) {
EditorDescriptor editor = (EditorDescriptor) editorArray[i];
if (!editors.contains(editor)) {
editors.add(editor);
}
IMemento idMemento = editorMemento
.createChild(IWorkbenchConstants.TAG_EDITOR);
idMemento.putString(IWorkbenchConstants.TAG_ID, editorArray[i]
.getId());
}
editorArray = type.getDeletedEditors();
for (int i = 0; i < editorArray.length; i++) {
EditorDescriptor editor = (EditorDescriptor) editorArray[i];
if (!editors.contains(editor)) {
editors.add(editor);
}
IMemento idMemento = editorMemento
.createChild(IWorkbenchConstants.TAG_DELETED_EDITOR);
idMemento.putString(IWorkbenchConstants.TAG_ID, editorArray[i]
.getId());
}
editorArray = type.getDeclaredDefaultEditors();
for (int i = 0; i < editorArray.length; i++) {
EditorDescriptor editor = (EditorDescriptor) editorArray[i];
if (!editors.contains(editor)) {
editors.add(editor);
}
IMemento idMemento = editorMemento
.createChild(IWorkbenchConstants.TAG_DEFAULT_EDITOR);
idMemento.putString(IWorkbenchConstants.TAG_ID, editorArray[i]
.getId());
}
}
Writer writer = null;
try {
writer = new StringWriter();
memento.save(writer);
writer.close();
store.setValue(IPreferenceConstants.RESOURCES, writer.toString());
} catch (IOException e) {
try {
if (writer != null) {
writer.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
MessageDialog.openError((Shell) null, "Saving Problems", //$NON-NLS-1$
"Unable to save resource associations."); //$NON-NLS-1$
return;
}
memento = XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_EDITORS);
Iterator itr = editors.iterator();
while (itr.hasNext()) {
EditorDescriptor editor = (EditorDescriptor) itr.next();
IMemento editorMemento = memento
.createChild(IWorkbenchConstants.TAG_DESCRIPTOR);
editor.saveValues(editorMemento);
}
writer = null;
try {
writer = new StringWriter();
memento.save(writer);
writer.close();
store.setValue(IPreferenceConstants.EDITORS, writer.toString());
} catch (IOException e) {
try {
if (writer != null) {